我正在为我的 PHP 项目使用 Sendmail。邮件发送成功,但会一一发送。我的编码流程是检查数据库,然后如果项目的值小于我设置的值,它将发送电子邮件通知用户。
我想将所有项目合并到一封电子邮件中,这样用户就不会因为同一通知收到太多电子邮件。我希望你明白我的意思。问题是,我不知道如何使用 Sendmail 将数据合并到一封电子邮件中。有人可以告诉我应该在哪里改变吗?
这是我的代码:
<?php
include 'MasConnectDB.php';
$sql = "SELECT Item, Available FROM accessories_other";
$result = mysql_query( $sql ) or die( 'Query failed.'.mysql_error() );
while($row = mysql_fetch_array($result))
{
$Item = $row['Item'];
$Available = $row['Available'];
if( $row['Available'] <= 5 ){
$message2 = $message3." <div style='margin:30px 0px;'>
$Item<br /></div>";
}
$to = 'some@email.com';
$subject = 'Testing sendmail.exe';
$message = 'The Following Your Product Expired. Product Code:'.$message2;
$headers = 'From: some@email.com' . "\r\n" .
'Reply-To: some@email.com' . "\r\n" .
'MIME-Version: 1.0' . "\r\n" .
'Content-type: text/html; charset=iso-8859-1' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
if(mail($to, $subject, $message, $headers))
echo "Email sent";
else
echo "Email sending failed";
}
?>
编辑:
<?php
include 'MasConnectDB.php';
$sql ="SELECT TC_Status FROM thin_client WHERE TC_Status ='Available'";
$result = mysql_query($sql) or die('Query failed. ' . mysql_error());
while($row = mysql_fetch_array($result)) {
$TC_STatus = $row['TC_Status'];
if( $result > 5 ){
echo "Thin client is more than 5";
}
else
$to = 'some@email.com';
$subject = 'Notification of less on stock';
$message = 'less than 5';
$headers = 'From: some@email.com' . "\r\n" .
'MIME-Version: 1.0' . "\r\n" .
'Content-type: text/html; charset=iso-8859-1' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
if(mail($to, $subject, $message, $headers))
echo "Email sent";
else
echo "Email sending failed";
}
?>