<?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 - Happy New Year from Kids' Pages</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/2009-01-01/KidsPagesLogo-0901.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%;">
<p style="margin: 0 0 4px 0">Happy New Year!</p>
<p style="margin: 0 0 4px 0"><a href="http://KidsPages.org" target="_blank">Click here</a> to visit your ULTIMATE Family Resource for<br />2009 Family Fun throughout the Front Range!</p>
</div>
</div>
</td>
</tr>
<tr>
<td height="100%" valign="top">
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<!-- The Arvada Center Children's Theater -->
<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;">
The Arvada Center Children's Theater presents <strong><em>Just So</em></strong>
</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://arvadacenter.org/on-stage/just-so" target="_blank"><img src="http://kidspages.org/newsletter/images/2009-01-01/ArvadaCenter-JustSo.gif" width="210" height="209" border="0" alt="" /></a></div>
<p>Ever wonder how life's little mysteries came about? It's time to find out! Set in a once-upon-a-time land of trunkless elephants, thin-skinned rhinos, and spotless leopards, everything is "just so" until a great adventure transforms them all. Three of Rudyard Kipling's famous tales including How the Elephant Got His Trunk and How the the Leopard Got His Spots, come to life to take you on a fun filled ride of fantasy, humor and song as you discover the answers. This witty and clever musical about courage, individuality and friendship is sure to delight the mind and expand the imagination in kids and adults alike!</p>
<strong>
Feb 17 to May 9<br />
Weekday general admission tickets: $8<br />
Weekend reserved tickets: $10<br />
<p>For more information and to purchase tickets, please visit <a href="http://arvadacenter.org/on-stage/just-so" target="_blank">arvadacenter.org/on-stage/just-so</a> or call 720-898-7200.</p>
</strong>
<div style="float:left;padding: 5px 5px 0px 0px;">
<a href="http://arvadacenter.org/on-stage/just-so" target="_blank"><img src="http://kidspages.org/newsletter/images/2009-01-01/ArvadaCenter-logo.gif" width="270" height="97" 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>
<!-- /The Arvada Center Children's Theater -->
<!-- All About Kids Expo -->
<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;">
Mark your Calendars<br />for the 17th Annual<br />All About Kids Expo!
</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.all-about-kids.org" target="_blank"><img src="http://kidspages.org/newsletter/images/2009-01-01/AllAboutKids-logo.gif" width="240" height="227" border="0" alt="" /></a></div>
<p>Denver's longest running children's expo, is a two day event filled with non-stop interactive, fun, entertainment for children of all ages. FREE activities, with paid admission, include pony rides, petting zoo, climbing wall, giant slides, jumpcastles, clowns, balloon animals,magician, face painting, and much, much more!</p>
<p><strong>Choo Choo Soul -- Performing LIVE<br />on Sunday at 2 pm!</strong></p>
<strong>
Colorado Convention Center<br />
Saturday, February 28th 10am-6pm<br />
Sunday, March 1st 10am-5pm<br />
<a href="http://www.all-about-kids.org" target="_blank">www.all-about-kids.org</a> for more information<br />
</strong>
<div style="float:left;padding: 5px 5px 0px 0px;">
<a href="http://www.all-about-kids.org" target="_blank"><img src="http://kidspages.org/newsletter/images/2009-01-01/RadioDisney-logo.gif" width="164" 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>
<!-- /All About Kids Expo -->
<!-- Win a Wii -->
<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;">
Enter to win Awesome Prizes at <a href="http://www.kidspages.org/contests" target="_blank">KidsPages.org</a>!
</div>
<font style="font-family:Arial, Helvetica, sans-serif;font-size:14px;line-height:21px;">
<div style="text-align:center;padding: 5px 0px 5px 5px;"><a href="http://www.kidspages.org/contests" target="_blank"><img src="http://kidspages.org/newsletter/images/2009-01-01/KidsPagesContests.gif" width="325" height="453" border="0" alt="" /></a></div>
<strong>
<div style="text-align:center;padding: 5px 0px 5px 5px;"><a href="http://www.kidspages.org/contests" target="_blank">Click here to enter</a></div>
</strong>
</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>
<!-- /Win a Wii -->
<!-- Birthday Party Mall -->
<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"></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"></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:22px;font-weight:bold;padding-bottom:2px;color:#005bab;">
Birthday Party Mall
</div>
<font style="font-family:Arial, Helvetica, sans-serif;font-size:14px;">
<div style="float:right;padding: 5px 0px 5px 5px;"><a href="http://BirthdayPartyMall.com" target="_blank"><img src="http://kidspages.org/newsletter/images/2009-01-01/birthdaypartymall.gif" width="160" height="240" border="0" /></a></div>
<strong>Get Entered to Win a $ 150 Gift Card* Monthly Contest Drawing!</strong><br />
<p>Tired of the same old Birthday Party Place? Need some new and unique ideas? Short on time...and cash? Check out <a href="http://www.BirthdayPartyMall.com" target="_blank">www.BirthdayPartyMall.com</a> today!</p>
<p>Over 200 Listings of Birthday Party Places, Party Packages, Entertainers, Parties in your Home, Party Supplies, Rentals and more! You can also save some cash while you browse close to 70 Money Saving Coupons for your kids' next Birthday Party Bash. While you're there, sign up for the newsletter and a Birthday Reminder Notice, too!</p>
<p>Remember to enter the MONTHLY contest drawings for a $150 Gift Card to any Birthday Party Business on the site*.</p>
<p>Click here to start saving time and money today...<a href="http://www.BirthdayPartyMall.com" target="_blank">www.BirthdayPartyMall.com</a></p>
<strong>Colorado's 1st Birthday-Party-Specific Website & Directory -- Saving you time and money; while helping to create wonderful memories!</strong>
</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"></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"></td></tr>
</table>
</td>
</tr>
<!-- /Birthday Party Mall -->
</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/2009-01-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: Conquering Debt before it Conquers You! -->
<div style="padding-right:0px;padding-top:0px;padding-bottom:10px;">
<a href="http://www.kidspages.org/2009/01/monthly-feature/debt-management-101" target="_blank"><img src="http://kidspages.org/newsletter/images/2009-01-01/ConqueringDebt.gif" width="150" height="99" border="0" alt="" /></a>
</div>
<div align="center" style="font-size:17px; line-height: 19px; font-weight:bold; color:#4e5670;">
Conquering Debt<br />before it<br />Conquers You!
</div>
<div style="text-align:center;line-height:150%;">
<p style="margin-top:5px;">We are living in challenging financial times that call for savvy money management skills. It's time to get your outstanding debts in order. But what if your credit card balance is growing faster than your checkbook balance? Check out this month's Kids' Pages for some friendly tips to help you tame unruly debt.</p>
<p style="margin-top:0px;"><a href="http://www.kidspages.org/2009/01/monthly-feature/debt-management-101" target="_blank">Read it now.</a></p>
</div>
<br />
<!-- /Sidebar: Conquering Debt before it Conquers You! -->
<!-- Sidebar: Star Struck Teen -->
<div style="padding-right:0px;padding-top:0px;padding-bottom:10px;">
<a href="http://www.kidspages.org/2009/01/monthly-feature/tween-idols" target="_blank"><img src="http://kidspages.org/newsletter/images/2009-01-01/TeenIdols.jpg" width="150" height="100" border="0" alt="" /></a>
</div>
<div align="center" style="font-size:17px; line-height: 19px; font-weight:bold; color:#4e5670;">
Star Struck Teen?
</div>
<div style="text-align:center;line-height:150%;">
<p style="margin-top:5px;">If your child's bedroom looks like a shrine to High School Musical heart throb Zac Efron, simply take a deep breath and silently close the door. Infatuations with celebrities are perfectly natural for the preteen and teen set and typically aren't anything to lose sleep over. Kids' Pages tackles the issue of Tween Idols this month, don't miss it!</p>
<p style="margin-top:0px;"><a href="http://www.kidspages.org/2009/01/monthly-feature/tween-idols" target="_blank">Read it now.</a></p>
</div>
<br />
<!-- /Sidebar: Star Struck Teen -->
<!-- Sidebar: Decode Your Child's Cough -->
<div style="padding-right:0px;padding-top:0px;padding-bottom:10px;">
<a href="http://www.kidspages.org/2009/01/monthly-feature/decode-your-childs-cough" target="_blank"><img src="http://kidspages.org/newsletter/images/2009-01-01/Cough.jpg" width="150" height="90" border="0" alt="" /></a>
</div>
<div align="center" style="font-size:17px; line-height: 19px; font-weight:bold; color:#4e5670;">
Decode your Child's Cough
</div>
<div style="text-align:center;line-height:150%;">
<p style="margin-top:5px;">Learn how you can tell by the sound of your child's cough what their illness might be and what to do for it instead of using over-the-counter cough and cold medications, which the FDA strongly recommends against for children under age 4 because of the risk of serious and potentially life-threatening side effects. Kids' Pages covers seven common childhood illnesses that have coughing as a primary symptoms.</p>
<p style="margin-top:0px;"><a href="http://www.kidspages.org/2009/01/monthly-feature/decode-your-childs-cough" target="_blank">Read it now.</a></p>
</div>
<br />
<!-- /Sidebar: Decode Your Child's Cough -->
</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 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>
</body>
</html>



EOT;

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

Happy New Year from Kids' Pages

Go to KidsPages.org to visit your ULTIMATE Family Resource for 2009 Family Fun throughout the Front Range!

EOT;

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

  $mail->Body    = $body;
  $mail->AltBody = $text_body;
  $mail->Subject = "Happy New Year 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 />";
?>
