繁体   English   中英

使用PHP mail()函数在Outlook中使用HTML电子邮件

[英]HTML e-mail in outlook using PHP mail() function

我一直在Outlook 2013中获取源代码。我已经阅读了很多stackoverflow问题,尝试了所有推荐的解决方案,但都无济于事。

这是我的PHP

    $test1 = "test string";

// Retrieve the email template required
$message = file_get_contents('email-templates/template1.html');
// Replace the % with the actual information
$message = str_replace('%test1%', $test1, $message);

//echo $message;

$to = 'test@gmail.com';
$email_subject = "test";
$email_body = $message;

$headers = "From: $to\n";
$headers  .= "MIME-Version: 1.0\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\n";
$headers .= "Content-Transfer-Encoding: 8bit\n";


mail($to,$email_subject,$email_body,$headers);

仅使用\\n而不是\\r\\n ,并已完成顺序(此命令已提出),但仍可在gmail,phone和bot上使用,而在Outlook中却没有。

还有其他建议吗?

我建议宁愿尝试重新发明(或修复)使用PHPMailer的轮子。 多年来,我一直在使用它来发送可在Outlook中正确呈现的HTML电子邮件。

您的代码很像手册页中的示例http://php.net/manual/en/function.mail.php

尝试用\\ r \\ n(CR-LF)结束行而不仅仅是换行符,谁知道

您可以备份一个步骤,从php.net复制并粘贴示例,然后查看问题是否确实在Outlook方面。 您还可以从收件箱中提取HTML电子邮件,并查看它们在做什么(尝试从php中复制并粘贴发送好的HTML电子邮件的副本)

至于重新发明轮子,如果mail()早于PHPMailer,则可以说是后者进行了重新发明...

解决方案是

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM