【问题标题】:HTML email sent using php mail() does not work in Gmail [duplicate]使用 php mail() 发送的 HTML 电子邮件在 Gmail 中不起作用 [重复]
【发布时间】:2018-07-28 16:56:20
【问题描述】:

我有一个 php 脚本,用于在我的 linux 主机以表格形式注册后发送确认邮件。 确认邮件是使用 CSS 格式化的 HTML。 但它只在 Gmail 中显示 HTML 代码但它在其他邮件客户端上完美运行

 <?php
$yourname='ijaz';
$youremail = 'ijazblahblah@gmail.com';
$id = 150456;
    $subject = "Confirmation";
        $message = '<html><body>';
$message .= '<h1 style="color:#f40;">Hi Jane!</h1>';
$message .= '<p style="color:#080;font-size:18px;">Will you marry me?</p>';
$message .= '</body></html>';
        $headers = 'From: blah<info@blah.in>' . "\n";
        mail($youremail,$subject,$message,$headers);


        ?>

我在 Gmail 中收到的邮件是这样的:

<html><body><h1 style="color:#f40;">Hi Jane!</h1><p style="color:#080;font-size:18px;">Will you marry me?</p></body></html>

【问题讨论】:

    标签: php html email gmail


    【解决方案1】:

    添加内容类型。用于邮件中的 html。

     $headers .= "Content-Type: text/html; charset=UTF-8\r\n";
    

    【讨论】:

      【解决方案2】:

      您必须包含告诉 GMail 将其呈现为 HTML 的标题:

      $headers .= "Content-Type: text/html; charset=UTF-8\r\n";
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2012-06-12
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-10-22
        • 2017-01-22
        相关资源
        最近更新 更多