我尝试了这里已经回答的问题(this、this、this 和其他...),但没有任何效果...我有发送电子邮件的功能:
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 标签,HTML
和 BODY
除外)。我做错了什么?
编辑 1:
邮件显示如下(除了HTML
和BODY
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/