1
當用戶提交表單時,我發送一封包含表單數據的電子郵件。錯誤:郵件正文空使用PHP郵件程序
這裏是我的代碼:
$message = '
<html>
<head>
<title>ES Html Report</title>
</head>
<body>
<table>
<tr>
<th>Project Name</th>
<th>TODo</th>
<th>Priority</th>
<th>Due on</th>
<th>Assignee</th>
<th>Created</th>
<th>Updated</th>
<th>Completed</th>
<th>Assignee Status</th>
<th>Status</th>
</tr>
<tr>
<td>'.$todolists_store_row['Projects_name'].'</td>
<td>'.$todolists_store_row['Name'].' </td>
<td>'.$todolists_store_row['priority'].'</td>
<td>'.$todolists_store_row['Due_on'].'</td>
<td>'.$todolists_store_row['assignee_name'].'</td>
<td>'.$todolists_store_row['Created_at'].'</td>
<td>'.$todolists_store_row['Modified_at'].'</td>
<td>'.$todolists_store_row['Completed_at'].'</td>
<td>'.$todolists_store_row['Assignee_status'].'</td>
<td>'.$status.'</td>
</tr>
</table>
</body>
</html>
';
}
$mail = new PHPMailer();
$mail->isSendmail();
$mail->setFrom('[email protected]', 'First Last');
$mail->addAddress($others, 'John Doe');
$body= preg_replace('/\[\]/','',$message);
$mail->IsHTML(true);
$mail->Body =$body;
var_dump($body);
$mail->AltBody = 'This is a plain-text message body';
//send the message, check for errors
if (!$mail->send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}
我曾嘗試調試代碼$ MAIL-> msgHTML($機構); //沒有html被髮送
我從url尋找幫助:PHPMailer Mailer Error: Message body empty。和PHP Mailer Class issue :Message body empty但他們都沒有幫助。
我也試過的var_dump($機構)和我:字符串(0)「」
誰能告訴我,爲什麼$body
是空的,幫我解決這個問題?
看到,因爲$體與'preg_replace'初始化,我會檢查未造成問題 – ElendilTheTall
爲什麼你試圖取代'[]'什麼也沒有? '$ message'後面還有一個大括號,是否在if語句中?如果是這樣,它是什麼?如果不刪除它。 – Styphon
我們如何知道,你沒有顯示任何代碼對'$ body'變量有任何影響。控制。 – RiggsFolly