首页 > 解决方案 > 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

解决方案


根据PHPmailer在您的问题中发送 HTML 代码链接,您可能需要更改:

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

因为它似乎是一个函数而不是一个变量。


推荐阅读