Solve the problem that 163/Sohu/Sina cannot receive an email from the PHP mail function.

Source: Internet
Author: User

CopyCode 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 ='
<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: 100'. "\ 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. = '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. copy Code 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.Copy codeCode: 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)

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.Copy codeThe 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.