tags:

views:

28

answers:

4

I've been using the PHP mail() function.

If the mail doesn't send for any reason, I'd like to echo the error message. How would I do that?

Something like

$this_mail = mail('[email protected]', 'My Subject', $message);

if($this_mail) echo 'sent!';
else echo error_message;

Thanks!

+4  A: 

sending mail in php is not a one-step process. mail() returns true/false, but even if it returns true, it doesn't mean the message is going to be sent. all mail() does is add the message to the queue(using sendmail or whatever you set in php.ini)

there is no reliable way to check if the message has been sent in php. you will have to look through the mail server logs.

kgb
Oh, okay. Thanks for the answer!
Rohan
A: 

There is no error message associated with the mail() function. There is only a true or false returned on whether the email was accepted for delivery. Not whether it ultimately gets delivered, but basically whether the domain exists and the address is a validly formatted email address.

Joseph
A: 

As the others have said, there is no error tracking for send mail it return the boolean result of adding the mail to the outgoing queue. If you want to track true success failure try using SMTP with a mail library like Swift Mailer, Zend_Mail, or phpmailer.

prodigitalson
A: 

You can use the PEAR mailer, which has the same interface, but returns a PEAR_Error when there is problems.

amccausl