今天想经过php发送邮件, php
根据手册描述,发送html邮件须要指定header头 html
<?php $header="MIME-Version: 1.0\r\n"; $header.="From:admin@xxx.com\r\n"; $header.="Content-Type:text/html;charset=utf-8\r\n"; $message="<html><body><a href='http://xxx.com'></a></body></html>"; mail('cxz@163.com','测试邮件标题',$message,'-fadmin@xxx.com');
结果发出的邮件仍是显示源代码,html并未生效,连header头信息都看成文本显示出来了。 post
觉得是postfix的缘由,百度了一通,无解。 测试
goole了一下,发现有老外的文章提到这个问题,解决办法是: spa
header头信息末尾不要用 \r\n,用PHP_EOL替代,以下: code
$header="MIME-Version: 1.0".PHP_EOL; $header.="From:admin@xxx.com".PHP_EOL; $header.="Content-Type:text/html;charset=utf-8".PHP_EOL;缘由,php下换行符是\n,win下换行符是\r\n,这里PHP_EOL是换行符,根据不一样的环境值不同。
手册里有提到: htm
If messages are not received, try using a LF (\n) only. Some poor quality Unix mail transfer agents replace LF by CRLF automatically (which leads to doubling CR if CRLF is used). This should be a last resort, as it does not comply with » RFC 2822. utf-8