Sendmail dsn = 5.0.0 PHP向yahoo发送邮件时服务不可用

我有关于sendmail的问题,我已经search了类似的问题,但找不到任何有用的东西。

我目前正在用sendmail使用服务器(带有LAMP堆栈的Debian),在网站上发送用户注册的validation邮件。 这通常工作正常,Gmail例如收到邮件,一切正常完美。 但是我最近发现,用雅虎它根本不起作用,邮件似乎没有被雅虎收到。 所以我自己build立了一个雅虎帐户进行testing,并观察了以下行为,我尽可能详细地描述:

我使用下面的PHP代码片段来发送邮件:

$toEmail = '...'; $subject = '...'; $message = '...'; $headers = array(); $headers[] = "MIME-Version: 1.0"; $headers[] = "Content-type: text/plain; charset=utf-8"; $headers[] = "From: [email protected]"; $headers[] = "Subject: {$subject}"; $headers[] = "X-Mailer: PHP/".phpversion(); if(mail($toEmail, $subject, $message, implode("\r\n",$headers))) { return TRUE; } 

我得到了一个在服务器上工作的sendmail安装,处理来自PHP的邮件命令。

如上所述,除了雅虎之外(几乎所有我不知道的其他人),这对于几乎所有的地址都是完全正常的。 使用触发发送邮件的网站上的表格,我几秒钟内收到邮件。 以下是/var/log/mail.log显示的日志

 May 3 14:19:12 btfmx5 sendmail[544]: u43CJCtW000544: from=www-data, size=1174, class=0, nrcpts=1, msgid=<[email protected]>, relay=www-data@localhost May 3 14:19:13 btfmx5 sm-mta[545]: u43CJDBO000545: from=<[email protected]>, size=1419, class=0, nrcpts=1, msgid=<[email protected]>, proto=ESMTP, daemon=MTA-v4, relay=localhost [127.0.0.1] May 3 14:19:13 btfmx5 sendmail[544]: u43CJCtW000544: [email protected], ctladdr=www-data (33/33), delay=00:00:01, xdelay=00:00:01, mailer=relay, pri=31174, relay=[127.0.0.1] [127.0.0.1], dsn=2.0.0, stat=Sent (u43CJDBO000545 Message accepted for delivery) May 3 14:19:13 btfmx5 sm-mta[547]: STARTTLS=client, relay=gmail-smtp-in.l.google.com., version=TLSv1/SSLv3, verify=FAIL, cipher=ECDHE-RSA-AES128-GCM-SHA256, bits=128/128 May 3 14:19:13 btfmx5 sm-mta[547]: u43CJDBO000545: to=<[email protected]>, ctladdr=<[email protected]> (33/33), delay=00:00:00, xdelay=00:00:00, mailer=esmtp, pri=121419, relay=gmail-smtp-in.l.google.com. [64.233.184.26], dsn=2.0.0, stat=Sent (OK 1462278313 o16si26784998wme.6 - gsmtp) 

但是,当我尝试发送到雅虎地址,上面的PHP代码返回TRUE,但没有收到邮件在雅虎帐户。 以下是这种情况下显示的日志:

 May 3 14:26:50 btfmx5 sendmail[571]: u43CQoiH000571: from=www-data, size=1174, class=0, nrcpts=1, msgid=<[email protected]>, relay=www-data@localhost May 3 14:26:50 btfmx5 sm-mta[572]: u43CQogB000572: from=<[email protected]>, size=1419, class=0, nrcpts=1, msgid=<[email protected]>, proto=ESMTP, daemon=MTA-v4, relay=localhost [127.0.0.1] May 3 14:26:50 btfmx5 sendmail[571]: u43CQoiH000571: [email protected], ctladdr=www-data (33/33), delay=00:00:00, xdelay=00:00:00, mailer=relay, pri=31174, relay=[127.0.0.1] [127.0.0.1], dsn=2.0.0, stat=Sent (u43CQogB000572 Message accepted for delivery) May 3 14:26:51 btfmx5 sm-mta[574]: STARTTLS=client, relay=mta5.am0.yahoodns.net., version=TLSv1/SSLv3, verify=FAIL, cipher=ECDHE-RSA-AES128-GCM-SHA256, bits=128/128 May 3 14:26:53 btfmx5 sm-mta[574]: u43CQogB000572: to=<[email protected]>, ctladdr=<[email protected]> (33/33), delay=00:00:03, xdelay=00:00:03, mailer=esmtp, pri=121419, relay=mta5.am0.yahoodns.net. [66.196.118.37], dsn=5.0.0, stat=Service unavailable May 3 14:26:53 btfmx5 sm-mta[574]: u43CQogB000572: u43CQrgB000574: DSN: Service unavailable May 3 14:26:53 btfmx5 sm-mta[574]: u43CQrgB000574: to=<[email protected]>, delay=00:00:00, xdelay=00:00:00, mailer=local, pri=30000, dsn=2.0.0, stat=Sent 

我现在尝试从命令行使用sendmail发送电子邮件到雅虎地址,以从详细模式获得更多信息。

但令我惊讶的是,这封电子邮件是由雅虎(在垃圾邮件文件夹,但谁在乎)收到! 现在我完全不解,如何从命令行工作,而不是在使用PHP?

我用来发送邮件的命令:

 echo "Subject: testmail" | sendmail -v [email protected] 

mail.log的相应日志条目:

 May 3 14:34:35 btfmx5 sendmail[581]: u43CYZp5000581: from=alumpi, size=18, class=0, nrcpts=1, msgid=<[email protected]>, relay=root@localhost May 3 14:34:35 btfmx5 sm-mta[582]: u43CYZx0000582: from=<[email protected]>, size=340, class=0, nrcpts=1, msgid=<[email protected]>, proto=ESMTP, daemon=MTA-v4, relay=localhost [127.0.0.1] May 3 14:34:37 btfmx5 sm-mta[582]: STARTTLS=client, relay=mta7.am0.yahoodns.net., version=TLSv1/SSLv3, verify=FAIL, cipher=ECDHE-RSA-AES128-GCM-SHA256, bits=128/128 May 3 14:34:39 btfmx5 sm-mta[582]: u43CYZx0000582: to=<[email protected]>, ctladdr=<[email protected]> (1000/1000), delay=00:00:04, xdelay=00:00:04, mailer=esmtp, pri=30340, relay=mta7.am0.yahoodns.net. [63.250.192.45], dsn=2.0.0, stat=Sent (ok dirdel) May 3 14:34:39 btfmx5 sendmail[581]: u43CYZp5000581: [email protected], ctladdr=alumpi (1000/1000), delay=00:00:04, xdelay=00:00:04, mailer=relay, pri=30018, relay=[127.0.0.1] [127.0.0.1], dsn=2.0.0, stat=Sent (u43CYZx0000582 Message accepted for delivery) 

详细输出sendmail命令:

 [email protected]... Connecting to [127.0.0.1] via relay... 220 MYSERVER.de ESMTP Sendmail 8.14.4/8.14.4/Debian-8; Tue, 3 May 2016 14:34:35 +0200; (No UCE/UBE) logging access from: localhost(OK)-localhost [127.0.0.1] >>> EHLO MYSERVER.de 250-MYSERVER.de Hello localhost [127.0.0.1], pleased to meet you 250-ENHANCEDSTATUSCODES 250-PIPELINING 250-EXPN 250-VERB 250-8BITMIME 250-SIZE 250-DSN 250-ETRN 250-AUTH DIGEST-MD5 CRAM-MD5 250-DELIVERBY 250 HELP >>> VERB 250 2.0.0 Verbose mode >>> MAIL From:<[email protected]> SIZE=18 [email protected] 250 2.1.0 <[email protected]>... Sender ok >>> RCPT To:<[email protected]> >>> DATA 250 2.1.5 <[email protected]>... Recipient ok 354 Enter mail, end with "." on a line by itself >>> . 050 <[email protected]>... Connecting to mta7.am0.yahoodns.net. via esmtp... 050 220 mta1523.mail.gq1.yahoo.com ESMTP ready 050 >>> EHLO MYSERVER.de 050 250-mta1523.mail.gq1.yahoo.com 050 250-PIPELINING 050 250-SIZE 41943040 050 250-8BITMIME 050 250 STARTTLS 050 >>> STARTTLS 050 220 Start TLS 050 >>> EHLO MYSERVER.de 050 250-mta1523.mail.gq1.yahoo.com 050 250-PIPELINING 050 250-SIZE 41943040 050 250 8BITMIME 050 >>> MAIL From:<[email protected]> SIZE=340 050 250 sender <[email protected]> ok 050 >>> RCPT To:<[email protected]> 050 >>> DATA 050 250 recipient <[email protected]> ok 050 354 go ahead 050 >>> . 050 250 ok dirdel 050 <[email protected]>... Sent (ok dirdel) 250 2.0.0 u43CYZx0000582 Message accepted for delivery [email protected]... Sent (u43CYZx0000582 Message accepted for delivery) Closing connection to [127.0.0.1] >>> QUIT 221 2.0.0 MYSERVER.de closing connection 

所以主要的问题是:为什么发送到例如Gmail的工作,但发送到雅虎失败?

第二个问题:为什么通过命令行发送到雅虎工作,但通过PHP失败?

我希望我提供了所有必要的信息,预先感谢您的帮助!

感谢评论,我能弄明白(我对这种pipe理员的东西比较陌生,对信封发件人不太了解等等):

从日志中可以看出,使用PHP时,sendmail使用的信封发件人是[email protected],使用命令行时,是[email protected],所以我试着改变它们。 但这不是一个问题,没有理由为这两种情况的不同行为。

事实上,只有当我使用合适的邮件地址作为信封发送者/返回path时,才意识到我会得到一个反弹消息,并且可能有用的信息。 在这样做之后,我收到了一个退回邮件到这个邮件地址,其中包含:

 554 Message not allowed - Headers are not RFC compliant[291] 

所以是的,最初的错误是非常不明确的:

正如问题中发布的PHP代码所示,我将发送主题头两次。 一旦在header-array中,并且直接使用PHP mail()函数的主题参数。 似乎大多数邮件提供商都不会给出一个关于这方面的信息,但是雅虎呢。

所以,我清理了我的PHP代码来发送一个主题,并使用有用的返回path,现在它完美的工作(甚至不去垃圾邮件文件夹):

 $toEmail = '...'; $subject = '...'; $message = '...'; $headers = array(); $headers[] = "MIME-Version: 1.0"; $headers[] = "Content-type: text/plain; charset=utf-8"; $headers[] = "From: [email protected]"; $headers[] = "X-Mailer: PHP/".phpversion(); if(mail($toEmail, $subject, $message, implode("\r\n",$headers), '-f [email protected]')) { return TRUE; }