<?php
ini_set( "max_execution_time", 3600 );
require("class.phpmailer.php");

$mail = new phpmailer();

$mail->From       = "eBlast@kidspages.org";
$mail->AddReplyTo = "eBlast@kidspages.org";
$mail->FromName   = "Kids' Pages Family";
$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) ) and ( email_address not in (select email from kp_ebook_unsubscribe) ) and ( email_address not in (select email from kp_ebook_sent ) )";

// $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) )"

echo '### Start: ' . date('l jS \of F Y h:i:s A') . "<br />";

$result = @MYSQL_QUERY($query);

$numrows = mysql_num_rows( $result );
echo "$numrows addresses to process... <br />";
$count = 0;

while ( $row = mysql_fetch_array ( $result ) )
{
  $email_address = $row["email_address"];
  $count++;

// HTML body
$body =
<<<EOT

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Walking With Dinosaurs</title>
<style type="text/css">
<!--
body,td,th {
color: #CC9933;
}
body {
background-color: #000000;
margin-left: 0px;
margin-top: 0px;
margin-right: 0px;
margin-bottom: 0px;
}
.style1 {
font-family: Arial, Helvetica, sans-serif;
font-size: 12px;
}
.style3 {font-size: 12px}
.style6 {
font-family: Arial, Helvetica, sans-serif;
font-size: 12px;
color: #FFFFFF;
}
.style8 {
font-family: Arial, Helvetica, sans-serif;
font-size: 24px;
color: #FFFFFF;
}
a         { color:#fff; text-decoration: underline; }
a:link    { color:#fff; text-decoration: underline; }
a:hover   { color:#fff; text-decoration: none; }
a:active  { color:#fff; text-decoration: none; }
-->
</style>
</head><body>
<div style="background-color:#000;">
<table align="center" border="0" cellpadding="0" cellspacing="0" width="619">
<tbody><tr>
<td colspan="3"><img src="http://kidspages.org/newsletter/images/2009-05-15/top.jpg" height="570" width="619"></td>
</tr>
<tr>
<td align="left" background="http://kidspages.org/newsletter/images/2009-05-15/left.jpg" height="197" valign="bottom" width="37"><img src="http://kidspages.org/newsletter/images/2009-05-15/left.jpg" height="172" width="37"></td>
<td align="left" background="http://kidspages.org/newsletter/images/2009-05-15/content_separator.jpg" valign="top" width="545"><table border="0" cellpadding="0" cellspacing="0" width="545">
<tbody><tr>
<td align="center" height="297" valign="top" width="278"><table border="0" cellpadding="0" cellspacing="0" height="187" width="250">
<tbody><tr>
<td align="left" height="187" valign="top" width="277"><p class="style1" align="center"><br>
<font color="#cc9933">
<strong><span class="style1">The Pepsi Center wants to offer
you the opportunity to purchase tickets to this extraordinary
event before the general public!<br>
<font color="#cc9966"> <br>
</font></span></strong><span class="style1"><strong>Presale runs from <br>
Friday, May 15th at noon until <br>
Sunday, May 17th at 10:00pm</strong></span><strong><span class="style1"><br>
<br>
Password:</font> <font color="#cc9966">DINO</font><font color="#cc9966"><br>
<br>
</font></span><span class="style1"><font color="#cc9966"><font color="#cc9933">Tickets
go on sale to the general public<br>
Monday, May 18th at 10:00am</font></font></span></strong><font color="#cc9933"><br>
</font><strong><span class="style1"><font color="#cc9966"><br>
</font></span><br>
<a href="http://www.ticketmaster.com/promo/v70kek" target="_blank"><img src="http://kidspages.org/newsletter/images/2009-05-15/buy_tickets.jpg" border="0" height="57" width="262"></a>
</strong></p>
</td>
</tr>
</tbody></table></td>
<td width="10">&nbsp;</td>
<td align="center" valign="top" width="258"><table border="0" cellpadding="0" cellspacing="0" height="302" width="250">
<tbody><tr>
<td align="left" height="302" valign="top" width="250"><div align="center">
<p><strong><strong><strong><span class="style1"><font color="#cc9933"><br>
15 Life Size Dinosaurs Roam The Arena Floor in this Astonishing
New Show!</font>
</span></strong></strong></strong></p>
<p><strong><strong><strong><span class="style6"><br>
</span><strong><strong><span class="style8"><img src="http://kidspages.org/newsletter/images/2009-05-15/logo.jpg" usemap="#Map2" border="0" height="120" width="235"></span></strong></strong></strong>
<map name="Map2" id="Map2">
<area shape="rect" coords="6,21,109,94" href="http://www.newspaceentertainment.com/" target="_blank">
<area shape="rect" coords="125,19,228,94" href="http://www.pepsicenter.com/" target="_blank">
</map>
<strong><a href="http://timesunioncenter-denver.com/" target="_blank">
</a><br>
<br>
<font color="#cc9933">
<span class="style1"><font size="3">Wednesday, July 29th
-<br>
Sunday, August 2nd</font></span></strong></strong><br>
<br>
<span class="style1"><a href="http://www.pepsicenter.com/" target="_blank"><font color="#cc9966">Click
here</font></a> for more information </span></strong> </p>
</font>
</div></td>
</tr>
</tbody></table></td>
</tr>
</tbody></table>    </td>
<td align="left" background="http://kidspages.org/newsletter/images/2009-05-15/right.jpg" valign="bottom" width="37"><img src="http://kidspages.org/newsletter/images/2009-05-15/right.jpg" height="172" width="36"></td>
</tr>
<tr>
<td colspan="3"><img src="http://kidspages.org/newsletter/images/2009-05-15/bottom.jpg" usemap="#Map" border="0" height="43" width="619"></td>
</tr>
</tbody></table>
<div align="center"><br>
<span class="style3"><a href="http://ecards.concerts.com/2009_WalkingwithDinosaurs/Denver_Presale/presale.htm" target="_blank"><font color="#ddb000" size="1">CLICK HERE IF YOU CAN'T SEE THE IMAGES ABOVE OR HAVE TECHNICAL DIFFICULTIES</font></a></span>
</div>
<p>
<map name="Map" id="Map">
<area shape="rect" coords="200,16,405,32" href="http://www.dinosaurlive.com/" target="_blank">
</map>
</p>
<div style="background-color:#000;padding:10px 5px 5px 5px;">
<table align="center" border="0" cellpadding="0" cellspacing="0" width="575">
<tr>
<td align="left" valign="top" width="100%">
<p style="font-size:9px;">
<font color="#ffffff" face="Verdana, Arial, Helvetica, sans-serif" size="1" style="font-size: 9px; font-family: Verdana, Arial, Helvetica, sans-serif;">
Don't see the images in this e-mail? Please add eblast@KidsPages.org to<br /> your address book or safe senders list.<br />
<br />
You are receiving these bimonthly eBlasts because of your relationship with KidsPages.org.<br />
We will never share our mailing list with anyone. If you do not wish to continue<br />
receiving these announcements, please click <a href="http://kidspages.org/unsubscribe/$email_address">here</a> to unsubscribe.<br />
<br />
&copy; Copyright 2009 Kids Pages Family Media, Inc.
</font>
</p>
</td>
</tr>
</table>
</div>
<br />
</div>
</body></html>



EOT;

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

See Walking with Dinosaurs -- The Arena Spectacular

Buy tickets at http://www.ticketmaster.com/promo/v70kek

EOT;

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

  $mail->Body    = $body;
  $mail->AltBody = $text_body;
  $mail->Subject = "Walking with Dinosaurs -- Exclusive Presale Offer";
  $mail->AddAddress( $email_address );


//    echo "NOT sending $count / $numrows to " . $email_address . "<br>";
//    $insertsql = "INSERT INTO `kp_ebook_sent` (`email`) VALUES ( '$email_address' )";
//    $insert_success = MYSQL_QUERY( $insertsql );
//    echo "insert was" . ( $insert_success ? " very" : " NOT" ) . " successful<br /><br />";
    

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

    $insertsql = "INSERT INTO `kp_ebook_sent` (`email`) VALUES ( '$email_address' )";
    @MYSQL_QUERY( $insertsql );
  }

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

  echo "<br />";
  echo "### COMPLETE ###<br />";
  echo '### End: ' . date('l jS \of F Y h:i:s A') . "<br />";
?>
