解决163/sohu/sina不能够收到PHP MAIL函数发出邮件的问题


Posted in PHP onMarch 13, 2009
// 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 it 
mail($to, $subject, $message, $headers);

查看sendmail的maillog,发现奇怪的内容。
Mar 1 11:28:03 <a title="shaohui" href="http://www.shaohui.org" target="_blank">shaohui</a>.org sendmail[27526]: n213S1Xc027524: to=<shaohui_1983@163.com>, ctladdr=<shaohui@shaohui.org> (500/500), delay=00:00:02, xdelay=00:00:01, mailer=esmtp, pri=150812, relay=163mx03.mxmail.netease.com. [220.181.12.72], dsn=5.0.0, stat=Service unavailable

但是,如果我使用Linux Shell 的mail命令是可以发送成功的,不过多加了一条-f 参数伪造发件人。这是唯一的不同,于是maillog 的其中一个字段ctladdr显示也不一样。不再是apache用户,我怀疑163等国内的邮件服务提供商,把所有的apache的用户的邮件当成垃圾邮件处理掉了。
Feb 25 23:44:59 <a title="shaohui" href="http://www.shaohui.org" target="_blank">shaohui</a> sendmail[13067]: n1PFixH4013067: to=shaohui_1983@163.com, ctladdr=contact@shaohui.org (0/0), delay=00:00:00, xdelay=00:00:00, mailer=relay, pri=30869, relay=[127.0.0.1] [127.0.0.1], dsn=2.0.0, stat=Sent (n1PFixdx013068 Message accepted for delivery)

根源找到,于是问题就很好解决了,查一下php的手册,发现mail函数原来也是可以伪造发件人的。
bool mail ( string $to , string $subject , string $message [, string $additional_headers [, string $additional_parameters ]] )

在第六个参数additional_parameters使用额外的参数"-f sender_addr@mydomain.com", 问题就解决了。
PHP 相关文章推荐
PHP读MYSQL中文乱码的解决方法
Dec 17 PHP
php模板原理讲解
Nov 13 PHP
php给每个段落添加空格的方法
Mar 20 PHP
php找出指定范围内回文数且平方根也是回文数的方法
Mar 23 PHP
php实现encode64编码类实例
Mar 24 PHP
php中二分法查找算法实例分析
Sep 22 PHP
Yii2框架redis基本应用示例
Jul 13 PHP
使用Laravel中的查询构造器实现增删改查功能
Sep 03 PHP
php设计模式之适配器模式原理、用法及注意事项详解
Sep 24 PHP
如何在Laravel5.8中正确地应用Repository设计模式
Nov 26 PHP
PHP 自动加载类原理与用法实例分析
Apr 14 PHP
php封装实现钉钉机器人报警接口的示例代码
Aug 08 PHP
PHP 文件类型判断代码
Mar 13 #PHP
php discuz 主题表和回帖表的设计
Mar 13 #PHP
php 获取mysql数据库信息代码
Mar 12 #PHP
php 删除记录实现代码
Mar 12 #PHP
php 异常处理实现代码
Mar 10 #PHP
php 表单数据的获取代码
Mar 10 #PHP
php URL编码解码函数代码
Mar 10 #PHP
You might like
php is_file()和is_dir()用于遍历目录时用法注意事项
2010/03/02 PHP
PHP运行时强制显示出错信息的代码
2011/04/20 PHP
PHP输入流php://input介绍
2012/09/18 PHP
PHP中session跨子域的三种实现方法
2016/07/25 PHP
php实现数组重复数字统计实例
2018/09/30 PHP
JQuery循环滚动图片代码
2011/12/08 Javascript
JavaScript中使用stopPropagation函数停止事件传播例子
2014/08/27 Javascript
jQuery点击改变class并toggle及toggleClass()方法定义用法
2015/12/11 Javascript
Node层模拟实现multipart表单的文件上传示例
2018/01/02 Javascript
vue自定义指令的创建和使用方法实例分析
2018/12/04 Javascript
JS监听滚动和id自动定位滚动
2018/12/18 Javascript
webpack 代码分离优化快速指北
2019/05/18 Javascript
微信小程序sessionid不一致问题解决
2019/08/30 Javascript
jQuery实现html可联动的百分比进度条
2020/03/26 jQuery
Python编写检测数据库SA用户的方法
2014/07/11 Python
Python内建数据结构详解
2016/02/03 Python
Python Django切换MySQL数据库实例详解
2019/07/16 Python
python能做什么 python的含义
2019/10/12 Python
python 用 xlwings 库 生成图表的操作方法
2019/12/22 Python
pyecharts绘制中国2020肺炎疫情地图的实例代码
2020/02/12 Python
Python统计文本词汇出现次数的实例代码
2020/02/27 Python
CSS3实现多样的边框效果
2018/05/04 HTML / CSS
工程造价管理专业大专生求职信
2013/10/06 职场文书
体育老师的教学自我评价分享
2013/11/19 职场文书
信息管理员岗位职责
2013/12/01 职场文书
高中生学习的自我评价
2013/12/14 职场文书
中年人生感言
2014/02/04 职场文书
商务英语广告词大全
2014/03/18 职场文书
村党支部书记承诺书
2014/05/29 职场文书
校园环保标语
2014/06/13 职场文书
硕士生找工作求职信
2014/07/05 职场文书
2014年电厂个人工作总结
2014/11/27 职场文书
2015年组织部工作总结
2015/04/03 职场文书
2015年高校教师个人工作总结
2015/05/25 职场文书
离职证明范本
2015/06/12 职场文书
Win11 PC上的Outlook搜索错误怎么办?
2022/07/15 数码科技