僅當數量低於5時,我如何才能發送電子郵件?下面的代碼將隨時發送電子郵件,我加載頁面。我怎樣才能達到這個限制?PHP - 僅當數量低於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()。 –