【发布时间】:2019-01-09 16:39:02
【问题描述】:
我不好意思问这个问题,因为我已经看到这个问题被问过好几次了。但是,似乎没有一个解决方案对我有用。我的 HTML 在通过 PHPMailer 发送的电子邮件正文中以纯文本形式输出
我已阅读 Github 上的 PHPMailer 文档,并在 stackoverflow 上找到了类似 PHPmailer sending HTML CODE 和 Add HTML formatting in phpmailer 的答案。
//Create a new PHPMailer instance
$mail = new PHPMailer(true);
// Set PHPMailer to use the sendmail transport
$mail->isSendmail();
//Set who the message is to be sent from
$mail->setFrom('xxx@yyy.com');
//Set an alternative reply-to address
// $mail->addReplyTo('replyto@example.com', 'First Last');
//Set who the message is to be sent to
$mail->addAddress('xxx@yyy.com');
//Set the subject line
$mail->Subject = 'Rework Report';
$body = file_get_contents('current/rework.txt');
$mail->Body= $body;
$mail->IsHTML = (true);
//Attach a file
//$mail->addAttachment('current/rework.txt');
//send the message, check for errors
if (!$mail->send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}
输出应该是电子邮件正文中的 HTML。
【问题讨论】:
-
您正在获取包含 HTML 的
.txt文件的内容?你为什么使用isSendmail()?您不太可能需要这样做。 -
您还可以在没有 try/catch 块的情况下启用异常。您使用的是旧版本的 PHPMailer?
标签: phpmailer