When PHP's mail() returns false
Published 2011-03-05I was recently diagnosing why someone's contact form email script stopped emailing them. The mail() function was returning false as documented in PHP's manual, but why? In order to see the conversation with the SMTP server, I had to do the following steps:
- Download PHPMailer for PHP5/6 from phpmailer.worxware.com and extract it locally
- Fill in the relevant email addresses and servers in examples/test_smtp_basic_no_auth.php
- Upload class.phpmailer.php, class.smtp.php, and examples/test_smtp_basic_no_auth.php to the remote server
- Test examples/test_smtp_basic_no_auth.php
The resulting debug output looked something like this (replacing customer information with X's):
SMTP -> FROM SERVER:X ESMTP Exim 4.69 #1 Sat, 05 Mar 2011 13:06:43 -0700 220-We do not authorize the use of this system to transport unsolicited, 220 and/or bulk e-mail. SMTP -> FROM SERVER: X Hello X [X.X.X.X] 250-SIZE 52428800 250-PIPELINING 250-AUTH PLAIN LOGIN 250-STARTTLS 250 HELP SMTP -> FROM SERVER:250 OK SMTP -> FROM SERVER:550-Verification failed for 550-No Such User Here 550 Sender verify failed SMTP -> ERROR: RCPT not accepted from server: 550-Verification failed for 550-No Such User Here 550 Sender verify failed SMTP Error: The following recipients failed: X@X.com Mailer Error: SMTP Error: The following recipients failed: X@X.com SMTP server error: Verification failed for 550-No Such User Here 550 Sender verify failed
This is a lot more helpful than just returning false.