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.

9 Responses to “PHPMailer "The following From address failed:" problem and solution”

  1. Manuel Conde says:

    Thanks very very much for your contribution.

    I was searching in google for 2 days for this solution with no a real solution from no one.

    With http://www.swiftmailer.org/ I finally can send emails with SMTP auth without problems (where PHPMailer didn\'t do).

    Swiftmailer is a great tool. Congratulations to the creators.

  2. Hernanc says:

    Hi there,
    I had a similar problem. I was getting this error:
    ERROR: MAIL not accepted from server: 550 Access denied -- Invalid HELO name (See RFC2821 4.1.1.1)

    Some time later I realized that I was querying my local server using only the host name:
    http://simplehostname/file.php

    When I used the full dns it worked perfectly:
    http://simplehostname.mydomainname.com/file.php

    Cheers!

  3. Terri Ann says:

    I was getting this error -- but it turns out it was because I was forcing a specific port -- SMTP was authenticating but the from address failed. I just removed the port assignment.

  4. Ardee Aram says:

    Wonderful. Just ditched PHPMailer and used Swiftmailer. Mailing now works perfectly well.

    Thank you very much for this post! I\'ll do a backlink if it\'s ok with you to spread the word :)

  5. J S says:

    Looks like they closed your bug fix request… without fixing it :/ I\'m going to try Swiftmailer

  6. John Daniels says:

    Here is a fix I applied succesfully when I ran into the problem of 554 Invalid HELO format with PHPMailer:

    In class.smtp.php search for the function Hello

    Replace: SendHello("EHLO", $host)) with SendHello("EHLO", "[" . $host . "]"))
    Replace: SendHello("HELO", $host)) with SendHello("HELO", "[" . $host . "]"))

  7. martin says:

    i also had a problem with EHLO error with my server.applying suggestion from john daniels really works!
    thanx alot man.

  8. Glen says:

    Worked several hours with PHPMailer, never got it to work. Found this blog and tried Swift mailer. Worked right out of the block. The docs were very easy to understand, and Swift was easy to test on my home server, and easy to upload/install on the professional web server. Thanks!

  9. Kaspar says:

    Hey man!

    Thanks a lot! I had been struggling with phpmailer for a crappy job for like 4houres till i finally found your post and tried SwiftMailer. Much better one, and easy to use too!

    Thanks for sharing this info!

Leave a Reply

Внимание: Моля, въведете само ПЪРВИТЕ ТРИ цифри от картинката
Important: Please enter just the first three digits from the image