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

2018-09-07 21:29

阅读:302

  复制代码 代码如下:
// multiple recipients
// 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=

但是,如果我使用Linux Shell 的mail命令是可以发送成功的,不过多加了一条-f 参数伪造发件人。这是唯一的不同,于是maillog 的其中一个字段ctladdr显示也不一样。不再是apache用户,我怀疑163等国内的邮件服务提供商,把所有的apache的用户的邮件当成垃圾邮件处理掉了。
复制代码 代码如下:
Feb 25 23:44:59 <a title=shaohui href=

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

在第六个参数additional_parameters使用额外的参数 问题就解决了。


评论


亲,登录后才可以留言!