【问题标题】:HTML content not showing in mail [duplicate]邮件中未显示 HTML 内容 [重复]
【发布时间】:2016-04-29 09:01:56
【问题描述】:

我已经在 localhost 中设置了电子邮件发送,并使用它可以访问我的 gmail 帐户以使用 php 脚本发送邮件。

<?php

$to = "example@gmail.com";
$subject = "HTML Mail";
$message  = "<html><body>";
$message .= "<b>Hey! How are you today?</b>";
$message .= "<br>Regards";
$message .= "</body></html>";

$headers = "From: myemail@gmail.com\r\n";


mail($to,$subject,$message,$headers);
echo "<h1>MAIL SENT</h1>";
?>

当我使用这个脚本发送这封电子邮件时,它给出了

<html><body><b>Hey! How are you today?</b><br>Regards</body></html>

为什么没有显示html类型的输出?

嘿!你今天好吗?
问候

在 gmail 中喜欢这样吗?

【问题讨论】:

    标签: php html email


    【解决方案1】:

    可能是您缺少标明这是 HTML 内容的标头吗?

    $headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
    $headers .= "MIME-Version: 1.0\r\n";
    

    编辑:正如另一个答案所指出的,两个标题都是必需的。

    【讨论】:

      【解决方案2】:

      来自 mail() 的 PHP 文档:

      // To send HTML mail, the Content-type header must be set
      $headers .= 'MIME-Version: 1.0' . "\r\n";
      $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
      

      如果缺少这些标头,则消息内容将被解释为纯文本。

      【讨论】:

        【解决方案3】:

        您好,要发送带有 HTML 正文的电子邮件,您需要指定标题。像这样的

        //your code <br>
        $headers = "From: myemail@gmail.com\r\n"; <br>
        //HTML headers <br>
        $headers .= 'MIME-Version: 1.0' . "\r\n"; <br>
        $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
        

        所以之后您可以发送带有 html 正文的电子邮件

        mail($to,$subject,$message,$headers);
        

        祝你好运

        【讨论】:

          猜你喜欢
          • 2016-05-14
          • 1970-01-01
          • 1970-01-01
          • 2018-12-09
          • 2014-08-04
          • 2020-02-20
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多