OK, I ran the script for real and it added the send date to 159 records in the table (I added a test record), but it wrote only 83 lines to the text file. And there were 2 records with my email address, so I should have received 2 emails but received only one. Now I am worried that not all the people received the notice. I need to be able to trust the script or it isn't much use. Could you please tell me what is wrong, or could be improved in my code? I really need this script to work reliably as I'll need to use it over and over with different SELECT clauses. Thanks very much. 
Code:
include('cr-connectdb.php');
require('class.phpmailer.php');
$Today_ymd = date("Y-m-d"); // 2010-08-31
// Retrieve Records from booking table
$sql = "SELECT `Book_Count` FROM `booking` WHERE `Book_Date` < '2010-6-30' AND `Book_Begin_Date` > '2010-8-31' AND (`Book_Comp` = 'Alamo' AND `country` NOT IN('CA', 'CW')) AND `Book_Pick` NOT LIKE 'Oahu%' AND `Book_Pick` NOT LIKE 'Maui - Kaan%' AND `Book_Confirm` <> 'Not Confirmed' ORDER BY `Book_Last_Name` ";
$result1 = mysql_query($sql,$connection) or die("Couldn't execute $sql query. <br> mysql error: ".mysql_error());
if(mysql_num_rows($result1) == 0){ echo "No rows returned\n"; exit; }
while($clientList = mysql_fetch_assoc($result1)){
$sql = "SELECT * FROM `booking` WHERE Book_Count = '".$clientList['Book_Count']."'";
$result = mysql_query($sql,$connection) or die("Couldn't execute $sql query. <br> mySQL Error: ".mysql_error());
while($row = @mysql_fetch_array($result)){
include('load-booking-variables.php');
include('convert-dates-to-mdy.php');
include('add-agency-logos.php');
$body = file_get_contents($Email_Alamo_Refund);
include('replace-email-variables.php');
// Send email to Client
$Subject = "Notice Regarding Your Hawaii Car Rental";
$emailaddress = $Email;
echo $emailaddress; echo "<br>";
include('send-client-email.php');
// Report Entry
$report = "Alamo Refund Info sent to: ".$name." at ".$Email." on ".$Today_mdy." \r\n";
$file = "/absolutepath/alamo-refund.txt";
if (!$file_handle = fopen($file,"a")) { echo "Cannot open $file file"; }
if (!fwrite($file_handle, $report)) { echo "Cannot write to $file file"; }
fclose($file_handle);
// Set Last Email Date to current date
$sql = "UPDATE booking SET `laste` = '".$Today_ymd."' WHERE `Book_Count` = '".$Book_Count."'" ;
$result2 = mysql_query($sql,$connection) or die("Couldn't execute $sql query. <br> mysql error: ".mysql_error());
}
}
Bookmarks