解决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获取通过http协议post提交过来xml数据及解析xml
Dec 16 PHP
探讨如何在PHP开启gzip页面压缩实例
Jun 09 PHP
PHP反射机制用法实例
Aug 28 PHP
PHP中怎样防止SQL注入分析
Oct 23 PHP
php基础教程
Aug 26 PHP
php给图片添加文字水印方法汇总
Aug 27 PHP
PHP正则表达式之捕获组与非捕获组
Nov 06 PHP
PHP抓取淘宝商品的用户晒单评论+图片+搜索商品列表实例
Apr 14 PHP
PHP mysqli事务操作常用方法分析
Jul 22 PHP
如何修改Laravel中url()函数生成URL的根地址
Aug 11 PHP
Mac系统下安装PHP Xdebug
Mar 30 PHP
thinkPHP框架中layer.js的封装与使用方法示例
Jan 18 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
世界上第一台立体声收音机
2021/03/01 无线电
PHP5中MVC结构学习
2006/10/09 PHP
解析PHP SPL标准库的用法(遍历目录,查找固定条件的文件)
2013/06/18 PHP
php常用数学函数汇总
2014/11/21 PHP
IE8 兼容性问题(属性名区分大小写)
2009/06/04 Javascript
分享10篇优秀的jQuery幻灯片制作教程及应用案例
2011/04/16 Javascript
jQuery中事件对象e的事件冒泡用法示例介绍
2014/04/25 Javascript
基于jquery的文字向上跑动类似跑马灯的效果
2014/09/22 Javascript
完美实现仿QQ空间评论回复特效
2015/05/06 Javascript
js+html5实现可在手机上玩的拼图游戏
2015/07/17 Javascript
Active控件问题小结(附解决办法)
2016/06/09 Javascript
JQuery form表单提交前验证单选框是否选中、删除记录时验证经验总结(整理)
2017/06/09 jQuery
让Vue也可以使用Redux的方法
2018/05/23 Javascript
JS实现图片转换成base64的各种应用场景实例分析
2018/06/22 Javascript
vue配置font-awesome5的方法步骤
2019/01/27 Javascript
Jquery Datatables的使用详解
2020/01/30 jQuery
Element Input输入框的使用方法
2020/07/26 Javascript
JavaScript逻辑运算符相关总结
2020/09/04 Javascript
[41:05]Serenity vs Pain 2018国际邀请赛小组赛BO2 第二场 8.19
2018/08/21 DOTA
利用Python的Django框架中的ORM建立查询API
2015/04/20 Python
win10系统中安装scrapy-1.1
2016/07/03 Python
python模块之time模块(实例讲解)
2017/09/13 Python
Flask框架Flask-Login用法分析
2018/07/23 Python
Python3日期与时间戳转换的几种方法详解
2019/06/04 Python
Python数据结构dict常用操作代码实例
2020/03/12 Python
PyCharm2020最新激活码+激活码补丁(亲测最新版PyCharm2020.2激活成功)
2020/11/25 Python
浅谈pc和移动端的响应式的使用
2019/01/03 HTML / CSS
英国网上香水店:Fragrance Direct
2016/07/20 全球购物
工程管理专业个人求职信范文
2013/12/07 职场文书
优秀教师的感人事迹
2014/02/04 职场文书
自我推荐信范文
2014/05/09 职场文书
购房公证委托书(2014版)
2014/09/12 职场文书
中小学生学籍证明
2014/10/25 职场文书
2014年学生会部门工作总结
2014/11/07 职场文书
python关于集合的知识案例详解
2021/05/30 Python
matplotlib画混淆矩阵与正确率曲线的实例代码
2021/06/01 Python