【发布时间】:2015-10-13 06:14:06
【问题描述】:
如果数量少于 5,我如何才能发送电子邮件?下面的代码将在我加载页面时发送电子邮件。我怎样才能达到这个限制?
$queryNotification = "SELECT * from stock where stockQty <= :qua1 ";
$stmtNotification = $conn->prepare($queryNotification);
$stmtNotification->bindParam(':qua1',$qua1);
$stmtNotification->execute();
$listofnotification = '';
while ($queryNotRow = $stmtNotification->fetch()){
$stockname = $queryNotRow['stockName'];
$stockquantity = $queryNotRow['stockQty'];
$Category = $queryNotRow['category'];
}
$mail = new PHPMailer;
// Set mailer to use SMTP
$mail->isSMTP();
// Specify main SMTP servers
$mail->Host = 'smtp.gmail.com';
// Enable SMTP authentication
$mail->SMTPAuth = true;
// SMTP username
$mail->Username = '';
// SMTP password
$mail->Password = '';
// Enable TLS encryption (gmail setting)
$mail->SMTPSecure = 'tls';
// TCP port to connect to (gmail setting)
$mail->Port = 587;
$mail->From = 'a';
$mail->FromName = 'a';
// Add recipients
$mail->addAddress($adminemail, $adminfullname);
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = 'Notification Of Stock Low';
$mail->Body = 'Dear '.$adminfullname.', <br><br> Your Shop Stock Are Low ,<br>Please Reorder Again,<br><br> Below are the Stock Low Details<br><br>'.$listofnotification.'<br><br>Thank you.';
if(!$mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
}
【问题讨论】:
-
你写的代码是这样的。发送邮件时添加if()查看数量。
标签: php html email pdo sendmail