【发布时间】:2014-08-07 13:03:11
【问题描述】:
当用户提交表单时,我会发送一封包含表单数据的电子邮件。
这是我的代码:
$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('a5@gmail.com', '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($body); //不发送html
我从以下网址寻求帮助:PHPMailer Mailer Error: Message body empty。和PHP Mailer Class issue :Message body empty,但他们都没有帮助。
我也尝试了 var_dump($body) 得到:string(0) ""
谁能告诉我为什么$body 是空的并帮我解决这个问题?
【问题讨论】:
-
看到 $body 是用
preg_replace初始化的,我会检查这不会导致问题 -
您为什么要尝试将
[]替换为空?$message之后还有一个右大括号,它在 if 语句中吗?如果是这样,那是什么?如果不删除它。 -
我们怎么知道,您没有显示任何对名为
$body的变量有任何影响的代码。抓紧。