I have set up a php script to send a notification email to customers one week after initially placing their order. Here's the code:
<?
# First, open a database connection
#
mysql_connect(' 127.0.0.1:3306' , 'user', 'pass') or
die('Could not connect: ' . mysql_error());
mysql_select_db ('database');
#
# Query the database for orders placed seven days prior to the current date
#
$result = mysql_query("SE LECT title, lastname, email FROM table WHERE DATE_SUB(CURDAT E(),INTERVAL 7 DAY) = DATE(FROM_UNIXT IME(date))");
#
# Now use PHP's built-in 'mail()' function to send the message
#
while($row = mysql_fetch_arr ay($result)) {
$subject = "Order in Progress";
$title = $row['title'];
$lastname = $row['lastname'];
$message = "Dear $title $lastname,\r\n\ r\n We are currently processing your order.\r\n\r\n Our despatch team will contact you (if not already) using the telephone number supplied with your initial order when your products are ready for despatch.\r\n\r \n Thank you again for your order, should you have any queries please call our sales team\r\n\r\n Thank you.\r\n";
mail($row['email'],$subject,$mess age,"From:email @example.com\r\ n");
}
#
# Finally, close the database connection as it is no longer required
#
mysql_close($li nk);
?>
I don't think it's the SQL query as running it inside MySQL returns the correct data.
<?
# First, open a database connection
#
mysql_connect(' 127.0.0.1:3306' , 'user', 'pass') or
die('Could not connect: ' . mysql_error());
mysql_select_db ('database');
#
# Query the database for orders placed seven days prior to the current date
#
$result = mysql_query("SE LECT title, lastname, email FROM table WHERE DATE_SUB(CURDAT E(),INTERVAL 7 DAY) = DATE(FROM_UNIXT IME(date))");
#
# Now use PHP's built-in 'mail()' function to send the message
#
while($row = mysql_fetch_arr ay($result)) {
$subject = "Order in Progress";
$title = $row['title'];
$lastname = $row['lastname'];
$message = "Dear $title $lastname,\r\n\ r\n We are currently processing your order.\r\n\r\n Our despatch team will contact you (if not already) using the telephone number supplied with your initial order when your products are ready for despatch.\r\n\r \n Thank you again for your order, should you have any queries please call our sales team\r\n\r\n Thank you.\r\n";
mail($row['email'],$subject,$mess age,"From:email @example.com\r\ n");
}
#
# Finally, close the database connection as it is no longer required
#
mysql_close($li nk);
?>
I don't think it's the SQL query as running it inside MySQL returns the correct data.
Comment