<?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/2009-02-01/KidsPagesLogo-0902.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">FREE Family Fun Galore!</p>
<p style="margin: 0 0 4px 0"><a href="http://KidsPages.org" target="_blank">Click here</a> to visit your Complete Family Resource for<br />Festivities and 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%">
<!-- 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;">
17th Annual All About Kids Expo at the Colorado Convention 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://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>All About Kids Expo Powered By Radio Disney offers numerous free activities with paid admission! Thousands of families from all over the Denver Metro Area enjoy hours of fun AND interact with some of Colorado's best family-oriented companies offering great services and products.</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 -->
<!-- Justin Roberts -->
<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;">
Justin Roberts & the Not Ready for Naptime Players
</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.bouldertheater.com/event_detail.php?id=977" target="_blank"><img src="http://kidspages.org/newsletter/images/2009-02-01/BoulderTheater-JustinRoberts.jpg" width="158" height="200" border="0" alt="" /></a></div>
<p>Justin Roberts is truly one of the "all-stars" of the indie family music scene. He logs thousands of miles on the road each year, leading some to call him the hardest working man in children's show business. With national awards and recognition and a devoted fan base, Justin and his wonderfully named bandmates "The Not Ready for Naptime Players" dish out unexpectedly intelligent and whimsically rocking music for kids and their parents.</p>
<strong>
Don't miss Justin Roberts! Tickets on sale now!<br />
Saturday, March 14, 11am at the Boulder Theater<br />
<a href="http://www.bouldertheater.com/event_detail.php?id=977" target="_blank">www.bouldertheater.com</a><br />
</strong>
<div style="float:left;padding: 5px 5px 0px 0px;">
<a href="http://www.bouldertheater.com/event_detail.php?id=977" target="_blank"><img src="http://kidspages.org/newsletter/images/2009-02-01/BoulderTheater-logo.gif" width="330" height="72" 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>
<!-- /Justin Roberts -->
<!-- Spring Spin at Elitch Gardens -->
<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;">
Spring Spin at Elitch Gardens
</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.SpringSpin.com" target="_blank"><img src="http://kidspages.org/newsletter/images/2009-02-01/SpringSpin-logo.gif" width="230" height="166" border="0" alt="" /></a></div>
<p>Spring Spin is an easy and fun way to raise money for your favorite charity while offering a great day at Elitch Gardens. There is no cost to you or your organization. Your group sells tickets to a special private preview day at Elitch Gardens for only $19.99 -- that's half the regular general admission price. Your organization keeps $5 for every ticket you sell. The ticket is the best value of the season and includes many extras, such as a free ticket to return any date between September 1 and November 1. Sign up today and give your fundraising efforts a real spin!</p>
<strong>
<a href="http://www.SpringSpin.com" target="_blank">www.SpringSpin.com</a>
</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>
<!-- /Spring Spin at Elitch Gardens -->
</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-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: A Kid’s Guide to the Denver Theatre Scene -->
<div style="padding-right:0px;padding-top:0px;padding-bottom:10px;">
<a href="http://kidspages.org/2009/02/monthly-feature/all-the-worlds-a-stage" target="_blank"><img src="http://kidspages.org/newsletter/images/2009-02-01/DenverTheatreScene.gif" width="150" height="111" border="0" alt="" /></a>
</div>
<div align="center" style="font-size:17px; line-height: 19px; font-weight:bold; color:#4e5670;">
A Kid’s Guide<br />to the Denver<br />Theatre Scene
</div>
<div style="text-align:center;line-height:150%;">
<p style="margin-top:5px;">When kids get involved in the performing arts they learn many life skills like teamwork, public speaking, self discipline and creative collaboration. Being involved in an arts program is also a great way to inspire curiosity in kids and boost literacy skills. We are fortunate that the Metro Area is bustling with many high-quality theatre programs for kids. Click here to find one that's just right for your budding thespian!</p>
<p style="margin-top:0px;"><a href="http://kidspages.org/2009/02/monthly-feature/all-the-worlds-a-stage" target="_blank">Read it now.</a></p>
</div>
<br />
<!-- /Sidebar: A Kid’s Guide to the Denver Theatre Scene -->
<!-- Sidebar: Insurance How Much and WHAT? -->
<div style="padding-right:0px;padding-top:0px;padding-bottom:10px;">
<a href="http://kidspages.org/2009/02/monthly-feature/insurance-you-name-it-theyve-got-it" target="_blank"><img src="http://kidspages.org/newsletter/images/2009-02-01/Insurance.gif" width="150" height="85" border="0" alt="" /></a>
</div>
<div align="center" style="font-size:17px; line-height: 19px; font-weight:bold; color:#4e5670;">
Insurance --<br />How Much and WHAT?
</div>
<div style="text-align:center;line-height:150%;">
<p style="margin-top:5px;">With the economic crunch families are trying to trim their household budgets as much as possible. Which policies and how much insurance do you really need before your premiums become a financial burden themselves? Kids' Pages tackles the question of insurance coverage this month, read on and you may save some $$!</p>
<p style="margin-top:0px;"><a href="http://kidspages.org/2009/02/monthly-feature/insurance-you-name-it-theyve-got-it" target="_blank">Read it now.</a></p>
</div>
<br />
<!-- /Sidebar: Insurance How Much and WHAT? -->
<!-- Sidebar: Help Your Child Ace the Weekly Spelling Test -->
<div style="padding-right:0px;padding-top:0px;padding-bottom:10px;">
<a href="http://kidspages.org/2009/02/monthly-feature/help-your-child-ace-the-weekly-spelling-test" target="_blank"><img src="http://kidspages.org/newsletter/images/2009-02-01/SpellingTest.gif" width="150" height="89" border="0" alt="" /></a>
</div>
<div align="center" style="font-size:17px; line-height: 19px; font-weight:bold; color:#4e5670;">
Help Your Child Ace the Weekly Spelling Test
</div>
<div style="text-align:center;line-height:150%;">
<p style="margin-top:5px;">What every parent and kid needs: a quick, painless, and effective parenting technique for helping kids pass that universal Friday spelling test. Read on for spelling test success...</p>
<p style="margin-top:0px;"><a href="http://kidspages.org/2009/02/monthly-feature/help-your-child-ace-the-weekly-spelling-test" target="_blank">Read it now.</a></p>
</div>
<br />
<!-- /Sidebar: Help Your Child Ace the Weekly Spelling Test -->
</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

FREE Family Fun Galore!

Go to KidsPages.org to visit your Complete Family Resource for Festivities and 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 = "Free Family 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 />";
?>
