phpmailer - HTML 在 PHPMailer 中显示为纯文本正文
问题描述
我不好意思问这个问题,因为我已经看到这个问题被问了好几次了。但是,似乎没有一个解决方案对我有用。我的 HTML 在通过 PHPMailer 发送的电子邮件正文中作为纯文本输出
我已经阅读了 Github 上的 PHPMailer 文档,并在 stackoverflow 上找到了类似这个PHPmailer 发送 HTML 代码和这个在 phpmailer 中添加 HTML 格式的答案。
//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。
解决方案
根据PHPmailer在您的问题中发送 HTML 代码链接,您可能需要更改:
// From
$mail->IsHTML = (true);
// To -- i.e. remove the equals sign (=)
$mail->IsHTML(true);
因为它似乎是一个函数而不是一个变量。
推荐阅读
- python - How can run 10 minute minus the current time on python?
- arrays - 带有 if 条件的 .map() 是否会遍历数组中的所有索引?| JS 反应
- java - 如何使用 Java 创建 JSON 对象
- python - 函数内部的函数在 kivy 和 python 中的任何命令之前开始
- javascript - change a div class with JS and an event listener
- glsl - How to pass depth buffer to fragment shader using SCNTechnique
- pandas - How can I return value of a column based on the min value of one column and max value of another column?
- r - 根据条件仅在数据框列的子集中更改 NA
- java - 如何在第三方 android 视图的构造函数上处理“AttributeSet”
- java - 如何访问 JToolBar 中的 JRadioButton