cat /etc/php.ini | grep sendmail_path
sendmail_path = sendmail -t -i

which sendmail

yum list installed | grep sendmail

sendmail—stat=Service unavailable

今天尝试着想要在linux终端上直接用mail命令(e.g: echo “hello” | mail -s “hello test”给我139.com的邮箱发邮件时,139.com邮箱根本收不到,但是总是可以在/var/mail/root下面找到我刚才发的邮件,其实这是因为发送失败了,从而被sendmail回退了邮件回来。

要想看失败原因, check /var/log/maillog:

Aug  1 18:41:40 localhost sendmail[5279]: o71Afeih005279: from=root, size=220, class=0, nrcpts=1, msgid=<201008011041.o71Afeih005279@localhost.localdomain>, relay=root@localhost
Aug  1 18:41:42 localhost sendmail[5281]: o71Afekr005281: from=<root@localhost.localdomain>, size=480, class=0, nrcpts=1, msgid=<201008011041.o71Afeih005279@localhost.localdomain>, proto=ESMTP, daemon=MTA, relay=localhost []
Aug  1 18:41:42 localhost sendmail[5279]: o71Afeih005279:, ctladdr=root (0/0), delay=00:00:02, xdelay=00:00:02, mailer=relay, pri=30220, relay=[] [], dsn=2.0.0, stat=Sent (o71Afekr005281 Message accepted for delivery)
Aug  1 18:41:44 localhost sendmail[5283]: o71Afekr005281: to=<>, ctladdr=<root@localhost.localdomain> (0/0), delay=00:00:03, xdelay=00:00:02, mailer=esmtp, pri=120480, [], dsn=5.0.0, stat=Service unavailable
Aug  1 18:41:44 localhost sendmail[5283]: o71Afekr005281: o71Afikr005283: DSN: Service unavailable
Aug  1 18:41:44 localhost sendmail[5283]: o71Afikr005283: to=<root@localhost.localdomain>, delay=00:00:00, xdelay=00:00:00, mailer=local, pri=31717, dsn=2.0.0, stat=Sent


I fixed the problem by changing the hostname of my server. Apparently “localhost.localdomain” will get rejected automatically by a lot of mail servers. As soon as I changed my hostname to “” (a domain that is hosted on the server), everything just worked and I had no more problems sending e-mail.

可以用hostanme 命令临时修改主机名,hostname; 还是失败了

Aug  1 19:11:33 localhost sendmail[5579]: o71BBVB9005579: from=root, size=221, class=0, nrcpts=1, msgid=<>, relay=root@localhost
Aug  1 19:11:35 localhost sendmail[5580]: o71BBX3b005580: from=<>, size=436, class=0, nrcpts=1, msgid=<>, proto=ESMTP, daemon=MTA, relay=localhost []
Aug  1 19:11:35 localhost sendmail[5579]: o71BBVB9005579:, ctladdr=root (0/0), delay=00:00:04, xdelay=00:00:02, mailer=relay, pri=30221, relay=[] [], dsn=2.0.0, stat=Sent (o71BBX3b005580 Message accepted for delivery)
Aug  1 19:11:39 localhost sendmail[5582]: o71BBX3b005580: to=<>, delay=00:00:04, xdelay=00:00:04, mailer=esmtp, pri=120436, [], dsn=4.0.0, stat=Deferred: 450 Requested action not taken:cmmx01, AS0QrJA75wiRVlVMWIvlAA--.3152S2, dynamic, reputation,, please try again

切记:修改完hostname以后需要重启sendmail 服务,重启服务后,一切ok.

PHP Mail函数伪造发件人

bool mail  ( string $to  , string $subject  , string $message  [, string $additional_headers  [, string $additional_parameters  ]] )

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

Share this Post:
Digg Google Bookmarks reddit Mixx StumbleUpon Technorati Yahoo! Buzz DesignFloat Delicious BlinkList Furl

No Responses to “Linux系统下PHP发送邮件失败的解决办法”

Leave a Reply:

Name (required):
Mail (will not be published) (required):
Comment (required):
XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>