php - mail() php 不以 html 格式发送

标签 php html email

我尝试了这里已经回答的问题(thisthisthis 和其他...),但没有任何效果...我有发送电子邮件的功能:

function send_email($para, $assunto, $msg){
    $to      = $para;
    $subject = $assunto;

    $message = '<html><body>';
    $message .= str_replace("\\r\\n","<br/>",$msg);
    $message .= '</body></html>';

    $headers = 'From: email@realemail.com' . "\r\n";
    $headers .= 'Reply-To: email@realemail.com' . "\r\n";
    $headers .= 'X-Mailer: PHP/' . phpversion() . "\r\n";
    $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
    $headers .= 'MIME-Version: 1.0' . "\r\n";

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

我用类似的方式调用它:

$var = "<p><strong>...blablabla...</strong></p>";

send_email("email@email", "lalala", $var);

我可以发送电子邮件,但它不是 html 格式的(它包含 html 标签,HTMLBODY 除外)。我做错了什么?

编辑 1: 邮件显示如下(除了HTMLBODY TAG外,发送的内容完全一样):

BEGIN
<p><strong>...blablabla</strong></p>
END

当我收到完整的电子邮件(如 this 教程)时,显示电子邮件发送时带有标签 html、正文等... 一封电子邮件:

Delivered-To: myemail@gmail.com
...
To: myemail@gmail.com
Subject: aaaaaaaaaaaaaaaaaaaaa
From: sender@email.com
Reply-To: sender@email.com
X-Mailer: PHP/5.6.19
Content-type: text/html; charset=iso-8859-1
MIME-Version: 1.0
...
Date: Tue, 29 Nov 2016 15:51:48 -0200
...
X-AntiAbuse: This header was added to track abuse, please include it with any abuse report
X-AntiAbuse: Primary Hostname - svr1.ravehost.com.br
X-AntiAbuse: Original Domain - gmail.com
X-AntiAbuse: Originator/Caller UID/GID - [99 497] / [47 12]
X-AntiAbuse: Sender Address Domain - svr1.ravehost.com.br

<html><body>...blablabla...</body></html>

最佳答案

不确定这是否是一个确切的解决方案,但这解决了我在使用 Microsoft Outlook 时遇到的 html 电子邮件问题。

将 header 中的所有 \r\n 替换为 PHP_EOL。当我在用 PHP 发送 html 电子邮件时遇到问题时,我这样做了,它似乎解决了我的特殊问题。

关于php - mail() php 不以 html 格式发送,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40872925/

相关文章:

php - 使用 PHP 向特定设备发送通知?

.NET 电子邮件拦截

java - LDAP 按电子邮件值搜索找不到记录

php - 如何从表 B 中获取记录数以放置在表 A 中每一行的名称旁边

php - 从同一个脚本运行多个网站

php - Wordpress:如果(网址为 example.com/sitemap)执行此操作...

html - SVG 中的 CSS3 旋转 : Firefox ignores origin

html - 具有三个元素的标题,一左一中一右

javascript - 在 Ajax 中找不到页面 (404)

email - 在没有白标签的情况下使用来自多个域的 sendgrid