发布于 2014-10-06 08:34:25 | 103 次阅读 | 评论: 0 | 来源: 网友投递

这里有新鲜出炉的PHP面向对象编程,程序狗速度看过来!

PHP开源脚本语言

PHP(外文名: Hypertext Preprocessor,中文名:“超文本预处理器”)是一种通用开源脚本语言。语法吸收了C语言、Java和Perl的特点,入门门槛较低,易于学习,使用广泛,主要适用于Web开发领域。PHP的文件后缀名为php。


本文为大家主要讲解的是解决163/sohu/sina不能够收到PHP MAIL函数发出邮件的问题,感兴趣的同学参考下.

最近准备改改自己的个人主页,加上发邮件到功能,发现居然不是那么好用。gmail和msn可以收到邮件,但是163/sina/sohu的邮箱居然都收不到,非常郁闷。其实代码也很简单。 php manual 已经说得相当清楚了。


// 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' . "rn";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "rn";
// Additional headers
$headers .= 'To: Mary <mary@example.com>, Kelly <kelly@example.com>' . "rn";
$headers .= 'From: Birthday Reminder <birthday@example.com>' . "rn";
$headers .= 'Cc: birthdayarchive@example.com' . "rn";
$headers .= 'Bcc: birthdaycheck@example.com' . "rn";
// 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", 问题就解决了。

 



最新网友评论  共有(0)条评论 发布评论 返回顶部

Copyright © 2007-2017 PHPERZ.COM All Rights Reserved   冀ICP备14009818号  版权声明  广告服务