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