<?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>
<head>
<title>KidsPages.org - FREE Family Fun!</title>
</head>
<body>
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td align="center" bgcolor="#FFFFFF">
<table border="0" cellpadding="0" cellspacing="0" width="575">
<tr>
<td align="left" bgcolor="#FFFFFF" height="50" valign="top"><a href="http://kidspages.org" target="_blank"><img alt="kidspages.org" src="http://kidspages.org/newsletter/images/2010-02-01/KidsPagesLogo-1002.gif" width="384" height="80" border="0" /></a></td>
<td align="right" bgcolor="#FFFFFF" height="50" style="line-height:0px; font-size:0px;" valign="top">&nbsp;</td>
</tr>
<tr>
<td colspan="2">
<hr color="#B7CD60" noshade="noshade" size="1px">
</td>
</tr>
<tr>
<td colspan="2">
<div style="font-family:Arial, Helvetica, sans-serif;font-size:25px;font-weight:bold;padding-bottom:6px;color:#594022;">
<div style="font-size:15px;color:black;line-height:150%;">
</div>
</div>
</td>
</tr>
<tr>
<td height="100%" valign="top">
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<!-- 1 -->
<tr>
<td align="left" bgcolor="#FFFFFF" height="100%">
<table border="0" cellpadding="0" cellspacing="0" height="100%" width="381">
<tr>
<td colspan="2" height="12" rowspan="2" style="line-height:0px; font-size:0px;" width="12"><img height="12" src="http://kidspages.org/newsletter/images/2008-04-01/color001_ul_corner.jpg" width="12" alt="" /></td>
<td bgcolor="#9A9B96" height="1px" style="line-height:0px; font-size:0px;" width="357"></td>
<td colspan="2" height="12" rowspan="2" style="line-height:0px; font-size:0px;" width="12"><img height="12" src="http://kidspages.org/newsletter/images/2008-04-01/color001_ur_corner.jpg" width="12" alt="" /></td>
</tr>
<tr><td bgcolor="#E2E5D2" height="11" style="line-height:0px; font-size:0px;"></td></tr>
<tr>
<td bgcolor="#9A9B96" height="100%" style="line-height:0px; font-size:0px;" width="1"></td><td bgcolor="#E2E5D2" height="100%" style="line-height:0px; font-size:0px;" width="11"></td>
<td align="left" bgcolor="#E2E5D2" height="100%" style="font-size: 12px; color:#343436; line-height:16px;" valign="top">
<div style="font-family:Arial, Helvetica, sans-serif;font-size:25px;line-height:27px;font-weight:bold;padding-bottom:2px;color:#005bab;">
Monster Jam at the<br />Pepsi Center!
</div>
<font style="font-family:Arial, Helvetica, sans-serif;font-size:14px;line-height:21px;">
<div style="float:right;padding: 5px 0px 5px 5px;">
<a href="http://tickethorse.com/eventsearch.aspx?q=Monster+Jam" target="_blank"><img src="http://kidspages.org/newsletter/images/2010-02-01/MonsterJam.gif" width="250" height="386" border="0" alt="" /></a>
</div>
<p>Monster Jam, an incredible family-friendly experience starring the biggest performers on four wheels: Monster Jam monster trucks. These twelve-feet-tall, ten- thousand- pound machines will bring you to your feet, racing and ripping up a custom-designed track full of obstacles to soar over - OR smash through. Monster Jam provides a massive night's entertainment tailored perfectly for your family's budget, and these colorful, larger-than-life beasts are sure to capture the hearts of both young and old.</p>
<p>FEATURING: GRAVE DIGGER, TEENAGE MUTANT NINJA TURTLE, MONSTER MUTT, EL TORO LOCO, BOUNTY HUNTER and IRON OUTLAW.</p>
<strong>
Saturday, February 13 at 7:30pm and Sunday February 14 at 2pm at the Pepsi Center!<br />
<br />
KIDS' SEATS HALF OFF! (Ages 2-12, all seats $2 more day of show. Valid only on $20 & $25 seats. Service charges, facility and handling fees may apply).<br />
<br />
Built Ford Tough Party in the Pits<br />
Sunday, February 14, 11:30am-1pm<br />
Get a free Pit Pass at Your Local Ford Stores or pay $5 at the Box Office day-of (must be accompanied with a Sunday 2pm event ticket to be admitted)<br />
<br />
Buy tickets at <a href="http://tickethorse.com/eventsearch.aspx?q=Monster+Jam" target="_blank">www.tickethorse.com</a>, the Pepsi Center Box Office or call 1-866-461-6556.<br />
</strong>
<div>
<a href="http://tickethorse.com/eventsearch.aspx?q=Monster+Jam" target="_blank"><img src="http://kidspages.org/newsletter/images/2010-02-01/PepsiCenter-logo.gif" width="158" height="77" border="0" alt="" /></a>
</div>
</font>
</td>
<td bgcolor="#E2E5D2" height="100%" width="11"></td><td bgcolor="#9A9B96" height="100%" width="1"></td>
</tr>
<tr><td colspan="5" style="line-height:0px; font-size:0px;"><img height="12" src="http://kidspages.org/newsletter/images/2008-04-01/color001_bottom.jpg" width="381" alt="" /></td></tr>
<tr><td colspan="5" style="line-height:0px; font-size:0px;"><img height="14" src="http://kidspages.org/newsletter/images/2008-04-01/pix.gif" width="1" alt="" /></td></tr>
</table>
</td>
</tr>
<!-- /1 -->
<!-- 2 -->
<tr>
<td align="left" bgcolor="#FFFFFF" height="100%">
<table border="0" cellpadding="0" cellspacing="0" height="100%" width="381">
<tr>
<td colspan="2" height="12" rowspan="2" style="line-height:0px; font-size:0px;" width="12"><img height="12" src="http://kidspages.org/newsletter/images/2008-04-01/color001_ul_corner.jpg" width="12" alt="" /></td>
<td bgcolor="#9A9B96" height="1px" style="line-height:0px; font-size:0px;" width="357"></td>
<td colspan="2" height="12" rowspan="2" style="line-height:0px; font-size:0px;" width="12"><img height="12" src="http://kidspages.org/newsletter/images/2008-04-01/color001_ur_corner.jpg" width="12" alt="" /></td>
</tr>
<tr><td bgcolor="#E2E5D2" height="11" style="line-height:0px; font-size:0px;"></td></tr>
<tr>
<td bgcolor="#9A9B96" height="100%" style="line-height:0px; font-size:0px;" width="1"></td><td bgcolor="#E2E5D2" height="100%" style="line-height:0px; font-size:0px;" width="11"></td>
<td align="left" bgcolor="#E2E5D2" height="100%" style="font-size: 12px; color:#343436; line-height:16px;" valign="top">
<div style="font-family:Arial, Helvetica, sans-serif;font-size:25px;line-height:27px;font-weight:bold;padding-bottom:2px;color:#005bab;">
Step into the spotlight!
</div>
<font style="font-family:Arial, Helvetica, sans-serif;font-size:14px;line-height:21px;">
<div style="float:right;padding: 5px 0px 5px 5px;">
<a href="http://denvercenter.org/education" target="_blank"><img src="http://kidspages.org/newsletter/images/2010-02-01/DCPA-AcademyChildren.jpg" width="250" height="342" border="0" alt="" /></a>
</div>
<p>The Denver Center for the Performing Arts puts every child center stage in its popular acting program. Anyone ages 3 and up can learn from the region's finest professional teaching artists.</p>
<p>Spring classes and summer camps now enrolling. So interACT with us; you'll receive a standing ovation.</p>
<strong>
Denver Center Theatre Academy<br />
303-446-4892<br />
Visit <a href="http://denvercenter.org/education" target="_blank">denvercenter.org/education</a> for more information.<br />
</strong>
<div style="border-top:5px;">
<a href="http://denvercenter.org/education" target="_blank"><img src="http://kidspages.org/newsletter/images/2010-02-01/dcpa-dctalogo.gif" width="252" height="100" border="0" alt="" /></a>
</div>
</font>
</td>
<td bgcolor="#E2E5D2" height="100%" width="11"></td><td bgcolor="#9A9B96" height="100%" width="1"></td>
</tr>
<tr><td colspan="5" style="line-height:0px; font-size:0px;"><img height="12" src="http://kidspages.org/newsletter/images/2008-04-01/color001_bottom.jpg" width="381" alt="" /></td></tr>
<tr><td colspan="5" style="line-height:0px; font-size:0px;"><img height="14" src="http://kidspages.org/newsletter/images/2008-04-01/pix.gif" width="1" alt="" /></td></tr>
</table>
</td>
</tr>
<!-- /2 -->
<!-- 3 -->
<tr>
<td align="left" bgcolor="#FFFFFF" height="100%">
<table border="0" cellpadding="0" cellspacing="0" height="100%" width="381">
<tr>
<td colspan="2" height="12" rowspan="2" style="line-height:0px; font-size:0px;" width="12"><img height="12" src="http://kidspages.org/newsletter/images/2008-04-01/color001_ul_corner.jpg" width="12" alt="" /></td>
<td bgcolor="#9A9B96" height="1px" style="line-height:0px; font-size:0px;" width="357"></td>
<td colspan="2" height="12" rowspan="2" style="line-height:0px; font-size:0px;" width="12"><img height="12" src="http://kidspages.org/newsletter/images/2008-04-01/color001_ur_corner.jpg" width="12" alt="" /></td>
</tr>
<tr><td bgcolor="#E2E5D2" height="11" style="line-height:0px; font-size:0px;"></td></tr>
<tr>
<td bgcolor="#9A9B96" height="100%" style="line-height:0px; font-size:0px;" width="1"></td><td bgcolor="#E2E5D2" height="100%" style="line-height:0px; font-size:0px;" width="11"></td>
<td align="left" bgcolor="#E2E5D2" height="100%" style="font-size: 12px; color:#343436; line-height:16px;" valign="top">
<div style="font-family:Arial, Helvetica, sans-serif;font-size:25px;line-height:27px;font-weight:bold;padding-bottom:2px;color:#005bab;">
Garden Camps for Kids!
</div>
<font style="font-family:Arial, Helvetica, sans-serif;font-size:14px;line-height:21px;">
<div style="float:right;padding: 5px 0px 5px 5px;">
<a href="http://www.botanicgardens.org/content/children-and-family-programs" target="_blank"><img src="http://kidspages.org/newsletter/images/2010-02-01/BG-wildflower-week.jpg" width="250" height="376" border="0" alt="" /></a>
</div>
<p><b>Get into the Gardens this summer!</b> A variety of different day camps offer a unique opportunity to investigate the amazing world of plants. Discover the wonders of the plant world as you paint, paint, eat, dig and discover your way through the Gardens. Each day brings a new theme with lots of fun activities, investigations and projects to take home.</p>
<b>Registration begins March 8</b> for the following camps:
<ul style="padding-top:0px;margin-top:0px;">
<li>Gardens around the Globe (ages 6-12)</li>
<li>KidCamp at the Gardens (ages 6-12)</li>
<li>Art Romp at the Gardens (ages 6-15)</li>
</ul>
<strong>
Visit <a href="http://www.botanicgardens.org/content/children-and-family-programs" target="_blank">www.botanicgardens.org</a> for more information.<br />
</strong>
<div>
<a href="http://www.botanicgardens.org/content/children-and-family-programs" target="_blank"><img src="http://kidspages.org/newsletter/images/2009-12-01/BotanicGardens-logo.gif" width="250" height="77" border="0" alt="" /></a>
</div>
</font>
</td>
<td bgcolor="#E2E5D2" height="100%" width="11"></td><td bgcolor="#9A9B96" height="100%" width="1"></td>
</tr>
<tr><td colspan="5" style="line-height:0px; font-size:0px;"><img height="12" src="http://kidspages.org/newsletter/images/2008-04-01/color001_bottom.jpg" width="381" alt="" /></td></tr>
<tr><td colspan="5" style="line-height:0px; font-size:0px;"><img height="14" src="http://kidspages.org/newsletter/images/2008-04-01/pix.gif" width="1" alt="" /></td></tr>
</table>
</td>
</tr>
<!-- /3 -->
</table>
</td>
<td align="right" height="100%" valign="top">
<table border="0" cellpadding="0" cellspacing="0" width="177">
<tr>
<td colspan="5" style="line-height:0px; font-size:0px;"><img alt="Kids' Pages eBlast" src="http://kidspages.org/newsletter/images/2010-02-01/kphead.gif" width="177" height="59"></td>
</tr>
<tr>
<td bgcolor="#999999" height="100%" width="1"></td>
<td bgcolor="#E3EDB9" height="100%" width="11"></td>
<td align="center" bgcolor="#E3EDB9" height="100%" style="font-family:Arial, Helvetica, sans-serif;font-size:12px; color:#343436;padding-bottom:3px; line-height:16px;" valign="top" width="153">
<br />
<!-- Sidebar: 01 -->
<div style="padding-right:0px;padding-top:0px;padding-bottom:10px;">
<a href="http://kidspages.org" target="_blank"><img src="http://kidspages.org/newsletter/images/2010-02-01/CalendarFamily.gif" width="150" height="209" border="0" alt="" /></a>
</div>
<div align="center" style="font-size:17px; line-height: 19px; font-weight:bold; color:#4e5670;">
<em>The</em> Events Calendar for Front Range Families
</div>
<div style="text-align:center;line-height:150%;">
<p style="margin-top:5px;">
<a href="http://kidspages.org" target="_blank">KidsPages.org</a> brings you the Most Comprehensive Family Calendar with hundreds of free and low-cost events. Enjoy!
</p>
<p style="margin-top:0px;"><a href="http://kidspages.org" target="_blank">Click here to visit your Family Calendar!</a></p>
</div>
<br />
<!-- /Sidebar: 01 -->
</td>
<td bgcolor="#E3EDB9" height="100%" style="line-height:0px; font-size:0px;" width="11"></td>
<td bgcolor="#999999" height="100%" style="line-height:0px; font-size:0px;" width="1"></td>
</tr>
<tr>
<td colspan="5" style="padding: 0 0 14px 0; line-height:0px; font-size:0px;"><img border="0" height="12" src="http://kidspages.org/newsletter/images/2008-04-01/kpbook_bottom.jpg" width="177" alt="" /></td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
<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="#000000" 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 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 2010 Kids Pages Family Media, Inc.
</font>
</p>
</td>
</tr>
</table>
</body>
</html>


EOT;

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

FREE Family Fun Galore!

Go to KidsPages.org to visit the Most Comprehensive Family Calendar with hundreds of free and low-cost events. Enjoy!

EOT;

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

  $mail->Body    = $body;
  $mail->AltBody = $text_body;
  $mail->Subject = "February Fun from Kids' Pages";
  $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 />";
?>
