Forum Moderators: coopster
<?php
include_once('config.php');
$send_db = 'db';
$send_table= 'table';
//query to pull names and email addresses from the db
$result = mysql_query("SELECT distinct(order_num),email,name,tracking,id,date FROM $send_db.$send_table where email_sent is NULL") or die ('Error: '.mysql_error());
if (mysql_num_rows($result) == 0) {
echo "No rows found, nothing to send, so I am exiting";
exit;
}
while ($row = mysql_fetch_array($result)) {
$email_id = $row['id'];
$order_num = $row['order_num'];
$name = $row['name'];
$email = $row['email'];
$date = $row['date'];
$tracking = $row['tracking'];
}
$to = "$email";
$headers = "From: donotreply@website.com\r\n";
$headers .= "Reply-To: donotreply@website.com\r\n";
$subject = "Your Order Number $order_num Has Shipped";
$body = "\n\n
---------------------------------------------\n
DO NOT REPLY TO THIS MESSAGE \n
---------------------------------------------\n
\n
$name\n
\n
Thank you for Ordering our product!\n
\n
Your Order Number $order_num has shipped on $date and should arrive to you shortly.\n
Your Order Shipped via the USPS First Class Mail. The tracking number for your package is $tracking \n
\n
For Customer Service please call phone number. For Returns, please contact Customer Service at the above phone number for Return Authorization. \n
\n
Thank you! \n
Company \n
\n
\n
\n
\n
";
mail($to, $subject, $body, $headers);
//update email_sent to Y
$result1 = mysql_query("UPDATE $send_db.$send_table set email_sent = 'Y' where order_num = '$order_num' and email = '$email';");
if (!$result1) {
echo "Could not successfully run query against the DB: " . mysql_error();
exit;
}
?>
while ($row = mysql_fetch_array($result)) {
$email_id = $row['id'];
$order_num = $row['order_num'];
$name = $row['name'];
$email = $row['email'];
$date = $row['date'];
$tracking = $row['tracking'];
$to = "$email";
....
...
if (!$result1) {
echo "Could not successfully run query against the DB: " . mysql_error();
exit;
}
}
?>