PHP的mail()函数发送邮件,其中的html标签未被正常解析的问题
来源:互联网 发布:杀毒清理软件 编辑:程序博客网 时间:2024/05/17 02:16
问题描述
最近有一台线上服务器迁移到了欧洲节点,服务器配置,操作系统和应用环境与之前都是一样,Centos6.5,PHP5.5,但是使用PHP自带的mail函数发送邮件,其中的html标签未被解析,被当成字符串直接显示出来,奇怪的是之前的服务器并没有这个问题。
问题分析
查看官方文档,mail
函数的定义如下:
bool mail ( string $to , string $subject , string $message [, string $additional_headers [, string $additional_parameters ]] )
通过官方文档的例子,不难看出要想发送html的邮件,关键在于第四个参数$additional_headers
:
<?php// multiple recipients$to = 'aidan@example.com' . ', '; // note the comma$to .= 'wez@example.com';// subject$subject = 'Birthday Reminders for August';// message$message = '<html><head> <title>Birthday Reminders for August</title></head><body> <p>Here are the birthdays upcoming in August!</p> <table> <tr> <th>Person</th><th>Day</th><th>Month</th><th>Year</th> </tr> <tr> <td>Joe</td><td>3rd</td><td>August</td><td>1970</td> </tr> <tr> <td>Sally</td><td>17th</td><td>August</td><td>1973</td> </tr> </table></body></html>';// To send HTML mail, the Content-type header must be set$headers = 'MIME-Version: 1.0' . "\r\n";$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";// Additional headers$headers .= 'To: Mary <mary@example.com>, Kelly <kelly@example.com>' . "\r\n";$headers .= 'From: Birthday Reminder <birthday@example.com>' . "\r\n";$headers .= 'Cc: birthdayarchive@example.com' . "\r\n";$headers .= 'Bcc: birthdaycheck@example.com' . "\r\n";// Mail itmail($to, $subject, $message, $headers);?>
使用这个例子在线上服务器上测试,仍然不行。但是在文档中发现了这样一个提示:
Note: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.
提示说,如果没有收到消息,尝试只用(\n)
,因为一些质量差的Unix邮件传输代理商自动将LF(\n)
替换为CRLF(\r\n)
(如果使用CRLF,则会导致出现两个CR)。
于是我将$headers
中的所有的(\r\n)
全部替换成(\n)
,再次发送邮件,HMTL标签全部显示正常。
0 0
- PHP的mail()函数发送邮件,其中的html标签未被正常解析的问题
- 关于PHP mail函数无法正常解析HTML邮件问题
- wamp下使用php的mail()函数发送邮件问题
- PHP的mail函数实现邮件发送
- php mail函数发送html邮件不解析,linux+postfix
- PHP通过mail函数发送带附件的邮件
- PHP通过mail函数发送带附件的邮件
- php中使用mail函数发送邮件时的注意事项
- php使用内置函数mail()发送邮件的解决方案
- php中mail函数发送邮件失败的解决方法
- 解决php mail发送邮件收不到的问题
- 用PHP MAIL()函数发送HTML邮件
- PHP mail函数发送HTML邮件
- javax.mail发送邮件遇到的问题
- 使用linux的mail命令发送html格式的邮件
- 使用linux的mail命令发送html格式的邮件
- Spring的Mail邮件发送
- 发送支持html标签的邮件
- mybatis中#和$的区别
- 麦克纳姆轮及其速度分解计算
- STM32中断一些概念(主要是外部中断)
- Box
- Android中Xposed框架篇-微信实现本地视频发布到朋友圈功能
- PHP的mail()函数发送邮件,其中的html标签未被正常解析的问题
- oracle spool 命令
- ASP.NET导出数据功能
- RecyclerView 通用适配 BaseQuickAdapter
- 面试题整理17 输入一个字符串判断一个字符串是否是有效ip地址
- 数据加密算法详解
- 【SpringBoot】AutoConfiguration 解密
- bootstrap Datatable搜索
- linux中fork()函数详解(原创!!实例讲解)