<?php
ini_set( "max_execution_time", 3600 );

require("class.phpmailer.php");


$mail = new phpmailer();

$mail->From       = "ebook@kidspages.org";
$mail->AddReplyTo = "ebook@kidspages.org";
$mail->FromName   = "Kids' Pages Family Magazine eBook";
$mail->Mailer     = "mail";

@MYSQL_CONNECT( "localhost", "kp_pnmonkey", "buster" );
@mysql_select_db( "kp_phoenix" );

// $query = "select distinct email_address from kp_emails where   email_address not in (select email_address from kp_emails_block)";
$query = "select distinct email_address from kp_emails where ( email_address not in (select email_address from kp_emails_block) ) and ( email_address not in (select email from kp_ebook_unsubscribe) )";


$result = @MYSQL_QUERY($query);

while ( $row = mysql_fetch_array ( $result ) )
{

  $email_address = $row["email_address"];

// HTML body
$body =
<<<EOT


<html>
<head>
  <meta http-equiv="content-type" content="text/html; charset=utf-8" />
  <title>Kids' Pages eBook - March 2008</title>
  <style>
    a         { color:#4e5670 }
    a:link    { font-weight: bold; text-decoration: none; }
    a:hover   { font-weight: bold; text-decoration: underline; }
    a:active  { font-weight: bold; text-decoration: none; }
    sup { font-size: smaller; vertical-align: baseline; position: relative; bottom: 0.33em; }
  </style>
</head>

<body bgcolor="#FFFFFF" text="#4b3905" link="#0000ff" vlink="#0000ff" alink="#0000ff">
  <div align="center">
    <div align="left" style="border: medium solid rgb(0,0,0);background-color:#fdc652;font-family:verdana,geneva,serif; font-size:14px; font-weight:bold; padding:10px; width:700;">
      <div align="center" style="font-size:20px; font-weight:bold; color:#4e5670;">
        <div style="float:left;padding-right:10px;padding-top:10px;padding-bottom:10px;">
          <a href="http://kidspages.org/ebooks/2008-03/denver/flash.html#/1/" target="_blank">
            <img src="http://kidspages.org/images/cover/2008-03/KP-Cover-2008-03-den-sm.jpg" width="150" height="195" border="0"><br />
            <div align="left" style="font-family:verdana,geneva,serif; font-size:12px; font-weight: normal; text-align:center;">
              Click here to launch the<br /><b>Denver Metro eBook!</b>
            </div>
          </a>
        </div>

        <div style="float:right;padding-left:10px;padding-top:10px;padding-bottom:10px;">
          <a href="http://kidspages.org/ebooks/2008-03/noco/flash.html#/1/" target="_blank">
            <img src="http://kidspages.org/images/cover/2008-03/KP-Cover-2008-03-noco-sm.jpg" width="150" height="195" border="0"><br />
            <div align="left" style="font-family:verdana,geneva,serif; font-size:12px; font-weight: normal; text-align:center;">
              Click here to launch the<br /><b>Northern Colorado eBook!</b>
            </div>
          </a>
        </div>

        March 2008 Issue<br /><br />
        Kids' Pages Family Magazine<br />
        is now an eBook too!<br />
      </div>
      <br />

      <div style="text-align:center;">
        Enjoy reading each issue<br />
        cover to cover online.<br />
        User-friendly with live links,<br />
        contests, coupons and more.<br />
        <br />
      </div>

      <br />
      <br style="clear:both" />
      <p style="font-size:60%;">
        Don't see the images? Please add ebook@KidsPages.org to your address book or safe senders list.<br />
        <br />
        You have received this e-mail because you are registered with KidsPages.org. If you do not wish to receive the Kids' Pages eBook by e-mail please click <a href="http://kidspages.org/index.php?module=SubmitStuff&func=unsubscribe&emailaddress=$email_address">here</a> to unsubscribe.
      </p>
    </div>
  </div>
</body>
</html>


EOT
;

// Plain text body (for mail clients that cannot read HTML)
$text_body  =
<<<EOT

March 2008 Issue

Kids' Pages Family Magazine
is now an eBook too!

Enjoy reading each issue cover to cover online.
User-friendly with live links, contests, coupons and more.

See it at: http://kidspages.org/ebooks/2008-03/denver/flash.html#/1/

You have received this e-mail because you are registered with KidsPages.org. If you do not wish to receive the Kids' Pages eBook by e-mail please click on the link below.

http://kidspages.org/index.php?module=SubmitStuff&func=unsubscribe

EOT
;

  $mail->From     = "ebook@kidspages.org";
  $mail->FromName = "Kids' Pages Family Magazine eBook";
  $mail->Mailer   = "mail";

  $mail->Body    = $body;
  $mail->AltBody = $text_body;
  $mail->Subject = "Kids' Pages Family Magazine eBook - March 2008";
  $mail->AddAddress( $email_address );

//  $mail->AddAddress($row["email_address"], $row["full_name"]);
//  $mail->AddStringAttachment($row["photo"], "YourPhoto.jpg");

  if ( !$mail->Send() )
  {
    echo "There has been a mail error sending to " . $email_address . "<br>";
  }
  else
  {
    echo "Success sending to " . $email_address . "<br>";
  }

  // Clear all addresses and attachments for next loop
  $mail->ClearAddresses();
  $mail->ClearAttachments();
}

  echo "<br />";
  echo "### COMPLETE ###<br />";
?>
