duankousong9637 2017-11-09 13:47
浏览 188

PHPMailer html电子邮件不显示为html

We have an email system where an email is formatted via PHPMailer. When PHPMailer sends the email, I open it in the email client and it displays as text not HTML.

I have tried using Gmail and Yahoo - both clients display the email as the HTML source code.

Does anybody have any suggestions as to how I can fix this?

Note: If I use Outlook to attach a version of the HTML email (insert as text), the email is sent and displayed correctly in the email clients listed above.

Thanks in advance

  • 写回答

2条回答 默认 最新

  • drrog9853 2017-11-09 13:53
    关注

    I believe that PHPMailer is not recognizing you code as HTML. Try to add this line of code when creating the email:

    $mail->IsHTML(true);  
    

    EDIT Here is a sample of the code I am using and works correctly. You can cross check for any differences.

    $mail = new PHPMailer;
    //Set email parameters  
    $mail->isSMTP();                            // Set mailer to use SMTP
    $mail->Host = 'smtp.office365.com';      // Specify main and backup server
    $mail->SMTPAuth = true;                          // Enable SMTP authentication
    $mail->Username = 'example@mydomain.co.uk';     // SMTP username
    $mail->Password = 'MyPassword';                  // SMTP password                      
    $mail->SMTPSecure = 'tls';           // Enable encryption, 'ssl' also accepted
    $mail->Port = 587;
    $mail->From = $fromEmail;
    $mail->FromName = self::getEmailName($email);
    $mail->addAddress($email);
    $mail->WordWrap = 50;                            // Set word wrap to 50 characters  
    $mail->isHTML(true);                             // Set email format to HTML
    $mail->CharSet = "UTF-8";
    
    评论

报告相同问题?

悬赏问题

  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥200 uniapp长期运行卡死问题解决
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
  • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?
  • ¥15 乘性高斯噪声在深度学习网络中的应用
  • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 C++ 头文件/宏冲突问题解决