dtt78245 2014-06-25 03:58
浏览 270
已采纳

PHPMailer IsHTML(true)不起作用

I am trying to send emails from PHPMailer. Everything is working but the problem is it is sending emails along with HTML tags even after writing $mail->IsHTML(true); . Below is my code for sending emails.

    $mail = new PHPMailer(); 
    $mail->IsSMTP();
    $mail->SMTPDebug = 1;
    $mail->SMTPAuth = true; 
    $mail->SMTPSecure = EMAIL_COMPOSE_SECURE; 
    $mail->Host = EMAIL_COMPOSE_SMTP_HOST;  
    $mail->Port = EMAIL_COMPOSE_PORT;
    $mail->Username = EMAIL_COMPOSE_OUTGOING_USERNAME;
    $mail->Password = EMAIL_COMPOSE_OUTGOING_PASSWORD;
    $mail->SetFrom(EMAIL_COMPOSE_INCOMING_USERNAME);
    $mail->Subject =$subject;

    $mail->Body = $message;
    $mail->IsHTML(true);
    $mail->AddAddress($email_to);
    if(!$mail->Send()){
        echo "Mailer Error: " . $mail->ErrorInfo;
    }
    else{
      echo "Message has been sent";
    }

And one more thing I will mention, in my application text editor for writing the emails is ckeditor. Will that cause any problem? Please help.

  • 写回答

2条回答 默认 最新

  • douzhan1868 2014-06-25 06:05
    关注

    Why would you not expect it to use HTML if you call IsHTML(true)? That's how you tell PHPMailer to treat your message body as HTML! If you don't want HTML as the content type, call IsHTML(false), or just don't call it at all since plain text is the default.

    If you want both HTML and plain text, call msgHTML($html) instead and it will also handle the HTML->text conversion for you.

    As Chris said, call IsHTML before setting Body.

    And as Dagon said, if you put HTML in $message, it will send HTML...

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 ats2837 spi2从机的代码
  • ¥200 wsl2 vllm qwen1.5部署问题
  • ¥100 有偿求数字经济对经贸的影响机制的一个数学模型,弄不出来已经快要碎掉了
  • ¥15 这个公式写进SIMULINK中的function模块的代码中应该是什么样的
  • ¥15 数学建模数学建模需要
  • ¥15 已知许多点位,想通过高斯分布来随机选择固定数量的点位怎么改
  • ¥20 nao机器人语音识别问题
  • ¥15 怎么生成确定数目的泊松点过程
  • ¥15 layui数据表格多次重载的数据覆盖问题
  • ¥15 python点云生成mesh精度不够怎么办