【问题标题】:HTML showing as plain text body in PHPMailerHTML 在 PHPMailer 中显示为纯文本正文
【发布时间】:2019-01-09 16:39:02
【问题描述】:

我不好意思问这个问题,因为我已经看到这个问题被问过好几次了。但是,似乎没有一个解决方案对我有用。我的 HTML 在通过 PHPMailer 发送的电子邮件正文中以纯文本形式输出

我已阅读 Github 上的 PHPMailer 文档,并在 stackoverflow 上找到了类似 PHPmailer sending HTML CODEAdd 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


【解决方案1】:

根据您问题中的PHPmailer sending HTML CODE 链接,您可能需要更改:

// From
$mail->IsHTML = (true);
// To -- i.e. remove the equals sign (=)
$mail->IsHTML(true);

因为它看起来是一个函数而不是一个变量。

【讨论】:

    猜你喜欢
    • 2013-05-19
    • 2015-07-06
    • 2014-04-01
    • 1970-01-01
    • 2020-03-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多