解決163/sohu/sina不能夠收到PHP MAIL函數發出郵件的問題_PHP教程

來源:互聯網
上載者:User
複製代碼 代碼如下:
// multiple recipients
$to = 'aidan@example.com' . ', '; // note the comma
$to .= 'wez@example.com';
// subject
$subject = 'Birthday Reminders for August';
// message
$message = '


Birthday Reminders for August


Here are the birthdays upcoming in August!












Person Day Month Year
Joe 3rd August 1970
Sally 17th August 1973



';
// 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 , Kelly ' . "\r\n";
$headers .= 'From: Birthday Reminder ' . "\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 shaohui.org sendmail[27526]: n213S1Xc027524: to=, ctladdr= (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 shaohui 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", 問題就解決了。

http://www.bkjia.com/PHPjc/319905.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/319905.htmlTechArticle複製代碼 代碼如下: // multiple recipients $to = 'aidan@example.com' . ', '; // note the comma $to .= 'wez@example.com'; // subject $subject = 'Birthday Reminders for August...

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.