<?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-06-01/KidsPagesLogo-0906.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%">
<!-- Disney's A Christmas Carol -->
<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;">
All Aboard for "Disney's A Christmas Carol" Train Tour!
</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.christmascaroltraintour.com" target="_blank"><img src="http://kidspages.org/newsletter/images/2009-06-01/DisneyTrain1.jpg" width="250" height="137" border="0" alt="" /></a></div>
<p>Enjoy a FREE once-in-<br />a-lifetime attraction where guests of all ages will get a behind the scenes look at the magic, the spectacle and cutting edge technology of the all-new motion picture "Disney's A Christmas Carol" starring Jim Carrey and directed by Robert Zemeckis!</p>
<ul>
<li>Check out a sneak peek of select scenes from  the film in the Digital 3-D Theater</li>
<li>Get a Behind the Scenes look at the making of the Movie</li>
<li>See Charles Dickens Museum museum artifacts</li>
<li>Morph your face into characters from the movie</li>
<li>Catch a glimpse of concept art, models, costumes & maquettes</li>
<li>Plus carolers, snow and much more</li>
</ul>
<div style="float:right;padding: 5px 0px 5px 5px;"><a href="http://www.christmascaroltraintour.com" target="_blank"><img src="http://kidspages.org/newsletter/images/2009-06-01/DisneyTrain2.jpg" width="205" height="137" border="0" alt="" /></a></div>
<strong>
Fun For the Whole Family!<br />
<br />
The train will be in Denver at Union Station<br />
(1701 Wynkoop St.), open to the pubic for free:<br />
Friday, 6/12 - 9am-9pm<br />
Saturday, 6/13 - 9am-9pm<br />
Sunday, 6/14 - 10am-6pm<br />
For more information visit <a href="http://www.christmascaroltraintour.com" target="_blank">www.christmascaroltraintour.com</a><br />
</strong>
<div style="font-size:9px;">
Photo credit: Mike Kern &copy;Imagemovers Digital, LLC. All Rights Reserved.
</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>
<!-- /Disney's A Christmas Carol -->
<!-- Heritage Square Amusement Park -->
<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;">
June is FREE Event Month at Heritage Square
</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/kidspages.html" target="_blank"><img src="http://kidspages.org/newsletter/images/2009-05-01/HeritageSquare-Total.jpg" width="250" height="146" border="0" alt="" /></a></div>
<p>Come enjoy many different opportunities for family fun at Heritage Square!</p>
<p><strong>June 13-14:</strong> Come cheer on four locals who have been selected by the Guinness Book of World Records to break the world record of Miniature Golf  for the most holes played by a foursome in a 24 hour period.</p>
<p><strong>June 21:</strong> Annual Father's Day Corvette Show.  Come check out some of the coolest cars in town.</p>
<p><strong>June 28:</strong> Radio Disney Family Field Day:  Disney Radio and Heritage Square invite you and your family to compete in races, obstacle courses, and challenges.</p>
<strong>
Heritage Square<br />
18301 West Colfax Ave, Golden<br />
<a href="http://www.heritagesquareamusementpark.com/kidspages.html" target="_blank">HeritageSquareAmusmentPark.com</a><br />
or call 303 PARTIES (727-8437)<br />
</strong>
<div style="float:left;padding: 5px 5px 0px 0px;">
<a href="http://www.heritagesquareamusementpark.com/kidspages.html" 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>
<!-- /Heritage Square Amusement Park -->
<!-- Denver Center Theatre Academy -->
<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;">
Back by popular demand!
</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" target="_blank"><img src="http://kidspages.org/newsletter/images/2009-06-01/DCPA.jpg" width="250" height="143" border="0" alt="" /></a></div>
<p>Denver Center Theatre Academy presents <em>New Kid</em> by Dennis Foon on<br />July 7-18.</p>
<p>This heartwarming comedy follows the adventures of a young boy's move to the US. Share his journey as he struggles to fit in. Explore with Nick as he discovers the excitement of new beginnings and the challenge of making new friends. Appropriate for ages 4-12.<br />Tickets are $6</p>
<strong>
Denver Center Theatre Academy<br />
Conservatory Theatre, 1101 13th St.<br />
303-893-4100<br />
<a href="http://denvercenter.org" target="_blank">denvercenter.org</a><br />
</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>
<!-- /Denver Center Theatre Academy -->
</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-06-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 Galore! -->
<div style="padding-right:0px;padding-top:0px;padding-bottom:10px;">
<a href="http://kidspages.org/2009/06/monthly-feature/fairs-festivals-in-june-and-july-2009-part-one" target="_blank"><img src="http://kidspages.org/newsletter/images/2009-06-01/sidebar1-FairsAndFestivals.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;">
Fairs and<br />Festivals Galore!
</div>
<div style="text-align:center;line-height:150%;">
<p style="margin-top:5px;">
Summer in Colorado is full of sun, fun, fairs and festivals! Enjoy music, culinary delights, dancing, artwork, rodeos, picnics, midways, three-legged races and much, much more <em>every</em> weekend this June and July. Best of all, most of the festivals offer FREE admission, although there is usually a charge for food and some activities. Click here for a schedule of all the awesome family fun!
</p>
<p style="margin-top:0px;"><a href="http://kidspages.org/2009/06/monthly-feature/fairs-festivals-in-june-and-july-2009-part-one" target="_blank">Read it now.</a></p>
</div>
<br />
<!-- /Sidebar: Fairs and Festivals Galore! -->
<!-- Sidebar: Are we there yet? -->
<div style="padding-right:0px;padding-top:0px;padding-bottom:10px;">
<a href="http://kidspages.org/2009/06/monthly-feature/are-we-there-yet" target="_blank"><img src="http://kidspages.org/newsletter/images/2009-06-01/sidebar2-AreWeThereYet.jpg" width="150" height="118" border="0" alt="" /></a>
</div>
<div align="center" style="font-size:17px; line-height: 19px; font-weight:bold; color:#4e5670;">
Are we there yet?
</div>
<div style="text-align:center;line-height:150%;">
<p style="margin-top:5px;">
Family vacations are a time to make memories, not a time for stress. Learn Six Steps for Trip Success in this month's Kids' Pages and make your family road trip one you'll cherish.
</p>
<p style="margin-top:0px;"><a href="http://kidspages.org/2009/06/monthly-feature/are-we-there-yet" target="_blank">Read it now.</a></p>
</div>
<br />
<!-- /Sidebar: Are we there yet? -->
<!-- Sidebar: Wild About Wildlife! -->
<div style="padding-right:0px;padding-top:0px;padding-bottom:10px;">
<a href="http://kidspages.org/2009/06/monthly-feature/please-dont-feed-the-animals" target="_blank"><img src="http://kidspages.org/newsletter/images/2009-06-01/sidebar3-Wildlife.jpg" width="150" height="113" border="0" alt="" /></a>
</div>
<div align="center" style="font-size:17px; line-height: 19px; font-weight:bold; color:#4e5670;">
Wild About Wildlife!
</div>
<div style="text-align:center;line-height:150%;">
<p style="margin-top:5px;">
One of the perks of living in Colorado is enjoying all of the breathtaking scenery that surrounds us. The open space areas, parks and forests are rich assets to our state and also home to many species of wildlife. But did you know that some wildlife can exist and thrive in close proximity to neighborhoods and suburban communities? Why shouldn't you feed the animals? Learn this and much more about<br />our Colorado Wildlife<br />this month!
</p>
<p style="margin-top:0px;"><a href="http://kidspages.org/2009/06/monthly-feature/please-dont-feed-the-animals" target="_blank">Read it now.</a></p>
</div>
<!-- /Sidebar: Wild About Wildlife! -->
</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 this June 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 />";
?>
