我尝试过已经在这里回答的问题(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
和BODY
除外)。我做错了什么?
编辑1 :
电子邮件显示如下(发送的内容完全相同,但HTML
和BODY
TAG除外):
BEGIN
<p><strong>...blablabla</strong></p>
END
当我收到完整的电子邮件(如this教程)时,显示该电子邮件是使用TAGS 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>
答案 0 :(得分:-2)
不确定这是否是一个确切的解决方案,但这解决了我在Microsoft Outlook中遇到的html电子邮件问题。
使用\r\n
替换标头中的所有PHP_EOL
。当我遇到用PHP发送HTML电子邮件的问题时,我这样做了,它似乎解决了我的特殊问题。