<?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-08-01/KidsPagesLogo-0908.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%">
<!-- 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;">
ZOOmily -- Tails From Near & Far, Far Away
</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://clk.atdmt.com/6UM/go/163615505/direct/01/" target="_blank"><img src="http://kidspages.org/newsletter/images/2009-08-01/dz-zoomily_character.gif" width="176" height="288" border="0" alt="" /></a>
</div>
<p>Once upon a time, there was a magical evening where your children's favorite animal stories and fairy tales from around the world come to life, with costumed characters, magical performances, once in a lifetime animal experiences and food fit for a king. Come dressed as a character from your favorite fairy tale or children's story and you could win a prize!</p>
<p>Proceeds from ZOOmily will benefit Denver Zoo's <a href="http://denverzoo.org/education/red_apple.asp" target="_blank">Red Apple Fund</a> for Life-Long Learning, which makes it possible for all individuals -- no matter their economic circumstances -- to discover the wonders of animals through participation in Denver Zoo education programs. Ticket Price includes: Dinner and desserts throughout the zoo!</p>
<strong>
ZOOmily -- Tails From Near & Far, Far Away<br />
Presented By: Mountain States Toyota<br />
Saturday, August 8<br />
6pm - 9pm<br />
<a href="http://clk.atdmt.com/6UM/go/163615505/direct/01/" target="_blank">Click here</a> for more information.<br />
</strong>
<div style="border-top:5px;">
<a href="http://clk.atdmt.com/6UM/go/163615505/direct/01/" target="_blank"><img src="http://kidspages.org/newsletter/images/2009-08-01/dz-logo.gif" width="74" height="92" 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;">
Family Nights at<br />Carino's Italian!
</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.carinos.com" target="_blank"><img src="http://kidspages.org/newsletter/images/2009-08-01/Carinos-Family-Portion-Bowtie.jpg" width="250" height="174" border="0" alt="" /></a>
</div>
<p>Moms, it's time for a break! Monday and Tuesday are Family Nights at <a href="http://www.carinos.com" target="_blank">Carino's Italian</a>. Our Family Platters are<br />&#189; price and start at $9.99. Serving 2 to 3 people each, we feature a wide variety like our Homemade 16 layer Lasagna, Pasta with Handmade Meatballs, Lemon Rosemary Chicken, or our own Skilletini, a sizzling skillet of spaghetti, spicy marinara, onions, bell peppers and choice of Chicken or Italian Sausage. Choose from 14 platters. Buy two mini desserts and get one free. Select from our Homemade Tiramisu, Italian Chocolate Cake or NY Cheesecake. Come experience the Food Fire and Fun of Carino's today!</p>
<p><a href="http://www.carinos.com" target="_blank">Click here</a> for more information.</p>
<div>
<a href="http://www.carinos.com" target="_blank"><img src="http://kidspages.org/newsletter/images/2009-08-01/Carinos-logo.gif" width="270" height="140" 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;">
Real National Heroes Day
</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.HeritageSquareAmusementPark.com" target="_blank"><img src="http://kidspages.org/newsletter/images/2009-08-01/HeritageSquare-flag.jpg" width="250" height="169" border="0" alt="" /></a>
</div>
<p>Come and pay tribute to our men and women in uniform at Heritage Square. This free family event will feature exhibits for all five branches of our armed services including the Army of One Humvee, the Navy Seal Trailer, an Antarctic snow-cat, an Army Reserves Rocket Launcher, and the Air Force Color guard. All current and retired members of the military and their families will receive 50% off unlimited rides passes all day.</p>
<strong>
Real National Heroes Day<br />
August 9 at Heritage Square<br />
<p><a href="http://www.heritagesquareamusementpark.com/kidspages.html" target="_blank">Click here</a> for their Kids' Pages Birthday Specials!</p>
Visit their website at <a href="http://www.HeritageSquareAmusementPark.com" target="_blank">www.HeritageSquareAmusementPark.com</a> for more information or call 303-PARTIES (727-8437).
</strong>
<div>
<a href="http://www.HeritageSquareAmusementPark.com" target="_blank"><img src="http://kidspages.org/newsletter/images/2009-05-01/HeritageSquare-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>
<!-- /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/2009-08-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: Fairs and Festivals for August & September! -->
<div style="padding-right:0px;padding-top:0px;padding-bottom:10px;">
<a href="http://kidspages.org/2009/08/monthly-feature/fairs-and-festivals-august-and-september" target="_blank"><img src="http://kidspages.org/newsletter/images/2009-08-01/FairsAndFestivals.jpg" width="150" height="123" border="0" alt="" /></a>
</div>
<div align="center" style="font-size:17px; line-height: 19px; font-weight:bold; color:#4e5670;">
Fairs and Festivals for August & September!
</div>
<div style="text-align:center;line-height:150%;">
<p style="margin-top:5px;">
Family-friendly fairs and festivals are still going strong in the metro area, and continue to do so even as autumn begins to appear! Yup, it's getting to be that time of year again! But in the meantime, you can still enjoy music, culinary delights, dancing, artwork, rodeos, picnics, midways, and much, much more at area festivals<br />every weekend!
</p>
<p style="margin-top:0px;"><a href="http://kidspages.org/2009/08/monthly-feature/fairs-and-festivals-august-and-september" target="_blank">Click here for<br />a complete list!</a></p>
</div>
<br />
<!-- /Sidebar: Fairs and Festivals for August & September! -->
<!-- 10 Tips for Raising Self-Sufficient Kids -->
<div style="padding-right:0px;padding-top:0px;padding-bottom:10px;">
<a href="http://kidspages.org/2009/08/monthly-feature/10-tips-for-raising-self-sufficient-kids" target="_blank"><img src="http://kidspages.org/newsletter/images/2009-08-01/SelfSufficientKids.jpg" width="150" height="114" border="0" alt="" /></a>
</div>
<div align="center" style="font-size:17px; line-height: 19px; font-weight:bold; color:#4e5670;">
10 Tips for Raising Self-Sufficient Kids
</div>
<div style="text-align:center;line-height:150%;">
<p style="margin-top:5px;">
All parents want their kids to grow up with the life skills to become self-sufficient and productive adults. But even parents with the best of intentions can sometimes find themselves hovering too much, controlling their kids' schedules and catering to their every need. If kids aren't given opportunities to tackle challenges on their own, they will grow up without the skills to be responsible, self-sufficient adults and will continue to rely on their parents. This month learn ten tips to get you on your way to raising self-sufficient kids on <a href="http://kidspages.org" target="_blank">KidsPages.org</a>.
</p>
<p style="margin-top:0px;"><a href="http://kidspages.org/2009/08/monthly-feature/10-tips-for-raising-self-sufficient-kids" target="_blank">Read it now.</a></p>
</div>
<br />
<!-- /10 Tips for Raising Self-Sufficient Kids -->
<!-- Homework Help -->
<div style="padding-right:0px;padding-top:0px;padding-bottom:10px;">
<a href="http://kidspages.org/2009/08/monthly-feature/homework-help" target="_blank"><img src="http://kidspages.org/newsletter/images/2009-08-01/HomeworkHelp.jpg" width="150" height="142" border="0" alt="" /></a>
</div>
<div align="center" style="font-size:17px; line-height: 19px; font-weight:bold; color:#4e5670;">
Homework Help
</div>
<div style="text-align:center;line-height:150%;">
<p style="margin-top:5px;">
School is almost in session and kids aren't the only ones who need help with homework. Sometimes parents need help too. Fortunately, much of the help you and your child need is only a keystroke away. The Internet is an invaluable resource when it comes to education. This month Kids' Pages shares some great homework sites for you to use during the school year.
</p>
<p style="margin-top:0px;"><a href="http://kidspages.org/2009/08/monthly-feature/homework-help" target="_blank">Read it now.</a></p>
</div>
<!-- /Homework Help -->
</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 = "August 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 />";
?>
