This script should solve your immediate problem.
The first block, which builds $msg, is based upon the code you provided since I don’t have enough insight into your database setup to write something more modern. mysql_fetch_array and the whole group of mysql_ functions were deprecated in PHP 5.5.0 (see http://php.net/manual/en/function.mysql-fetch-array.php, http://php.net/manual/en/function.mysql-query.php, etc.) and should no longer be used. But since you’ve opened the database this way, I use it in the second code block too. Please consider getting comfortable with the PDO class, which is a vast improvement and will make your PHP/SQL a lot more stable (http://php.net/manual/en/class.pdostatement.php).
$msg = "<table border="1" cellpadding='3' cellspacing='0'> ";
$msg .= "<tr> <th>Date</th><th>Line</th> <th>Style No</th> <th>PO No</th><th bgcolor="#CCCCFF">Order Qty</th><th>Line Out</th><th>Final QC Out</th><th>Iron Out</th><th>Refinal Out</th><th>Packing In</th><th>Warehouse In</th>";
while ( $row10 = mysql_fetch_array( $result10 ) ) {
$msg .= "<tr>";
$msg .= "<td>" . $row10['wdate'] . "</td>";
$msg .= "<td> Line" . $row10['line'] . "</td>";
$msg .= "<td>" . $row10['style_no'] . "</td>";
$msg .= "<td>" . $row10['po_no'] . "</td>";
$msg .= "<td bgcolor="#CCCCFF">" . $row10['order_qty'] . "</td>";
$msg .= "<td>" . $row10['Line_Out'] . "</td>";
$msg .= "<td>" . $row10['Final_QC_Out'] . "</td>";
$msg .= "<td>" . $row10['Iron_Out']. "</td>";
$msg .= "<td>" . $row10['Refinal_Out'] . "</td>";
$msg .= "<td>" . $row10['Packing_In'] . "</td>";
$msg .= "<td>" . $row10['Warehouse_In'] . "</td>";
$msg .= "</tr>";
}
$msg .= "</table>";
$query = "SELECT email FROM email_tbl";
if ( !$result = mysql_query( $query ) ) {
$message="Invalid query: " . mysql_error() . "\n";
$message .= 'Whole query: ' . $query;
die($message);
}
$to = '';
while ( $row = mysql_fetch_assoc( $result ) ) {
$to .= $row['email'] . ',';
}
rtrim( $to, "," );
mysql_free_result( $result );
$subject = "Morning email from Gayan";
$headers="From: [email protected]" . "\r\n" .
'Reply-To: [email protected]';
if ( mail( $to, $subject, $msg, $headers ) ) {
echo "Email sent successfully<br>";
} else {
echo "ERROR sending email<br>";
}
8
solved PHP for send a email for more than one recipients automatically at a given time