解決163/sohu/sina不能夠收到PHP MAIL函數(shù)發(fā)出郵件的問(wèn)題
更新時(shí)間:2009年03月13日 22:43:01 作者:
最近準(zhǔn)備改改自己的個(gè)人主頁(yè),加上發(fā)郵件到功能,發(fā)現(xiàn)居然不是那么好用。gmail和msn可以收到郵件,但是163/sina/sohu的郵箱居然都收不到,非常郁悶。其實(shí)代碼也很簡(jiǎn)單。 php manual 已經(jīng)說(shuō)得相當(dāng)清楚了。
復(fù)制代碼 代碼如下:
// 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,發(fā)現(xiàn)奇怪的內(nèi)容。
復(fù)制代碼 代碼如下:
Mar 1 11:28:03 <a title="shaohui" 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ā)送成功的,不過(guò)多加了一條-f 參數(shù)偽造發(fā)件人。這是唯一的不同,于是maillog 的其中一個(gè)字段ctladdr顯示也不一樣。不再是apache用戶,我懷疑163等國(guó)內(nèi)的郵件服務(wù)提供商,把所有的apache的用戶的郵件當(dāng)成垃圾郵件處理掉了。
復(fù)制代碼 代碼如下:
Feb 25 23:44:59 <a title="shaohui" 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)
根源找到,于是問(wèn)題就很好解決了,查一下php的手冊(cè),發(fā)現(xiàn)mail函數(shù)原來(lái)也是可以偽造發(fā)件人的。
復(fù)制代碼 代碼如下:
bool mail ( string $to , string $subject , string $message [, string $additional_headers [, string $additional_parameters ]] )
在第六個(gè)參數(shù)additional_parameters使用額外的參數(shù)"-f sender_addr@mydomain.com", 問(wèn)題就解決了。
相關(guān)文章
實(shí)現(xiàn)在同一方法中獲取當(dāng)前方法中新賦值的session值解決方法
這篇文章主要介紹了在同一方法中獲取當(dāng)前方法中新賦值的session值解決方法,需要的朋友可以參考下2014-06-06windows下的WAMP環(huán)境搭建圖文教程(推薦)
下面小編就為大家?guī)?lái)一篇windows下的WAMP環(huán)境搭建圖文教程(推薦)。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2017-07-07php基于curl實(shí)現(xiàn)的股票信息查詢類實(shí)例
這篇文章主要介紹了php基于curl實(shí)現(xiàn)的股票信息查詢類,結(jié)合完整實(shí)例形式分析了php使用curl調(diào)用API接口實(shí)現(xiàn)股票信息查詢功能的相關(guān)操作技巧,需要的朋友可以參考下2016-11-11php array_filter除去數(shù)組中的空字符元素
php array_filter除去數(shù)組中的空字符元素,array_filter() 函數(shù)根據(jù)回調(diào)函數(shù)過(guò)濾數(shù)組中的值,省略回調(diào)函數(shù)則默認(rèn)過(guò)濾空值,需要的朋友可以參考下。2011-11-11php基礎(chǔ)知識(shí):控制結(jié)構(gòu)
php基礎(chǔ)知識(shí):控制結(jié)構(gòu)...2006-12-12php快速導(dǎo)入大量數(shù)據(jù)的實(shí)例方法
在本篇文章里小編給大家分享的是關(guān)于php如何快速導(dǎo)入大量數(shù)據(jù)的相關(guān)知識(shí)點(diǎn)內(nèi)容,需要的朋友們學(xué)習(xí)下。2019-09-09PHP鉤子與簡(jiǎn)單分發(fā)方式實(shí)例分析
這篇文章主要介紹了PHP鉤子與簡(jiǎn)單分發(fā)方式,結(jié)合實(shí)例形式分析了PHP鉤子的定義與使用方法,以及多通道自由切換的實(shí)現(xiàn)技巧,需要的朋友可以參考下2017-09-09