我的网站上有发送电子邮件功能。如果是EmailSentDate,我希望根据查询自动发送从数据库中获取的电子邮件
function EmailNotif() {
$stats = 'Open';
$messages = array();
$conn = dbConnect();
$stmt = $conn->prepare("SELECT * FROM invalid_invoice
WHERE EmailSentDate<NOW() AND Status=:stats");
$stmt->bindParam(':stats', $stats);
$stmt->execute();
$data = $stmt->fetchAll(PDO::FETCH_ASSOC);
//var_dump($data);
foreach ($data as $row6) {
$invnumb=$row6['Invoice_Number'];
$partnumb=$row6['Part_Number'];
$issue=$row6['Issues'];
$pic=$row6['PIC_Comments'];
$issuetype=$row6['Issue_Type'];
$createdate=$row6['Creation_Date'];
$site=$row6['Site'];
$vendor=$row6['Vendor_Name'];
$invdate=$row6['Invoice_Date'];
$po=$row6['PO'];
$rr=$row6['RR'];
$currency=$row6['Currency'];
$invamount=$row6['Invoice_Amount'];
$stat=$row6['Status'];
$emailadd=$row6['PersoninCharge'];
$emailid=$row6['ID'];
$messages[$emailadd] .= "<b>Issue Type: {$issuetype} </b><br><br>";
$messages[$emailadd] .= "<b>Creation Date: {$createdate} </b><br><br>";
$messages[$emailadd] .= "<b>Site: {$site} </b><br><br>";
$messages[$emailadd] .= "<b>Vendor Name: {$vendor} </b><br><br>";
$messages[$emailadd] .= "<b>Invoice Date: {$invdate} </b><br><br>";
$messages[$emailadd] .= "<b>Invoice Number: {$invnumb} </b><br><br>";
$messages[$emailadd] .= "<b>Part Number:</b><br>{$partnumb}<br><br>";
$messages[$emailadd] .= "<b>PO: {$po} </b><br><br>";
$messages[$emailadd] .= "<b>RR: {$rr} </b><br><br>";
$messages[$emailadd] .= "<b>Currency: {$currency} </b><br><br>";
$messages[$emailadd] .= "<b>Invoice Amount: {$invamount} </b><br><br>";
$messages[$emailadd] .= "<b>Issues:{$issue}</b><br><br>";
$messages[$emailadd] .= "<b>Status: {$stat} </b><br><br>";
$messages[$emailadd] .= "<b>PIC Comments: {$pic}</b><br>";
$messages[$emailadd] .= "<br><br>";
}
foreach($messages as $email=>$message) {
dbInsertEmailMessage($email, "Invalid Invoice Tracking Message", "<html>{$message}</html>");
}
$conn = null;
}
function dbInsertEmailMessage($send_to, $subject, $message) {
$sql7 = "INSERT INTO email_queue (send_to, subject, message)
VALUES (:send_to, :subject, :message)";
$conn = dbConnect();
$stmt7 = $conn->prepare($sql7);
$stmt7->bindParam(':send_to', $send_to);
$stmt7->bindParam(':subject', $subject);
$stmt7->bindParam(':message', $message);
$stmt7->execute();
$conn=null;
}
我查询了将EmailSentDate更新为今天的日期,但它没有更新。我应该在哪里插入此查询?或者我有什么方法可以使它工作?请帮忙。感谢。
更新
我在函数dbInsertEmailMessage之后添加了以下代码。但它没有将EmailSentDate更新为当前日期。
foreach($emailid as $e_id) {
$sql2="UPDATE invalid_invoice SET EmailSentDate=:now WHERE ID =:emailid";
$conn=dbConnect();
$stmt2=$conn->prepare($sql2);
$stmt2->bindParam(':emailid', $e_id, PDO::PARAM_STR);
$stmt2->bindParam(':now', $now);
$stmt2->execute();
$conn = null;
var_dump($e_id);
}