Solve the problem that 163/sohu/sina cannot receive an email from the PHPMAIL function.

Source: Internet
Author: User
Recently, I was about to change my personal homepage and add the email to function. I found it was not so easy to use. Gmail and msn can receive emails, but the 163sinasohu mailbox cannot receive them, which is very depressing. In fact, the code is also very simple. Phpmanual is already quite clear. The code is as follows:
// 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: 100'. "\ 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. = 'http: birthdayarchive@example.com '. "\ r \ n ";
$ Headers. = 'bcc: birthdaycheck@example.com '. "\ r \ n ";
// Mail it
Mail ($ to, $ subject, $ message, $ headers );

Check the maillog of sendmail and find strange content.
The code is as follows:
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

However, if I use the mail command of Linux Shell, it can be sent successfully, but I add a-f parameter to forge the sender. This is the only difference, so the ctladdr field in maillog is different. I am no longer an apache user. I suspect that 163 and other domestic email service providers have disposed of all apache users' emails as spam.
The code is as follows:
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)

The root cause is found, so the problem is well solved. check the php manual and find that the mail function can also forge the sender.
The code is as follows:
Bool mail (string $ to, string $ subject, string $ message [, string $ additional_headers [, string $ additional_parameters])

When the sixth parameter additional_parameters uses the additional parameter "-f sender_addr@mydomain.com", the problem is solved.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.