PHPMailer "The following From address failed:" problem and solutionПубликувано / posted 2007-12-20 в категория / in category: Web development
|
Today I had to debug strange issue with sending mails using a up2messenger system (which uses phpmailer). The problem occured when we changed SMTP server. This system worked fine for months with the old SMTP but the new one (up2email.nl) totally refused to cooperate.
After long hours of google-ing and debuging I found the problem -- that SMTP was qmail with greetdelay path applied and configured in strange way (20 seconds (!!!) greet delay).
What greetdelay patch do: "greetdelay is a program to introduce a small delay before an SMTP greeting. It can also optionally enforce RFC 2821's recommendation that SMTP clients not send any commands before receiving the greeting message.".
"to introduce a small delay before an SMTP greeting" is not the problem. "that SMTP clients not send any commands before receiving the greeting message" is the problem.
PHPmailer connects to the STMP and sends EHLO / HELO before receiving greeting. In result, if greetdelay is configured to force RFC2821 recomendation -- "A 554 response is given if greetdelay shuts down the SMTP session."
Ouptut with $mailer->SMTPDebug = 2; looks like:
SMTP -> FROM SERVER:
SMTP -> FROM SERVER:
554 SMTP protocol violation
SMTP -> ERROR: EHLO not accepted from server: 554 SMTP protocol violation
SMTP -> FROM SERVER:
SMTP -> ERROR: HELO not accepted from server:
SMTP -> ERROR: AUTH not accepted from server:
SMTP -> NOTICE:
EOF caught while checking if connected
PHPmailer wrongly returns error:
The following From address failed: someuser@somedomain.tld
which is misleading.
The problem is that phpmaile tries to send HELO/ELHO and qmail returns "554 SMTP protocol violation" and closes the connection.
Solution:
- use different SMTP host;
- if you really have to use SMTP with greetdelay patch -- measure the greetdelay using telnet to your SMTP host on port 25 and wait to see how many seconds are passed before showing the greeting. Then in class.smtp.php find "# get any announcement stuff" and just after that line put "sleep(seconds);" where seconds is the measured delay (add 1-2 seconds to that to be safe). Please note that this is quite dirty fix.
- wait for fix of this bug. You can check it's progress at phpmailer bugtracker bugID: 1854809
- don't use PHP Mailer. Use Swift mailer instead. It is quite better than PHPMailer, there are PHP4 / PHP5 versions, TLS support, etc… I've switched to Swift and I'm glad 2 months ago and so far I'm quite happy with it.
|
|
