All, I have the standard mail code to send an email in PHP.
$to = $resultset['email_address'];
$subject = "New client inquiry from Website.com";
$message = $email_message;
$from = $your_email;
$headers = "From:" . $from;
mail($to,$subject,$message,$headers,"-f $from");
The variables are created earlier in my code. However what I want to check is to make sure that the mail function was executed successfully. With this code, how can I determine if sent the email and if it didn't echo out "failure"?
Simply said: This is not possible with the PHP mail()
command.
the return value from mail()
just indicates, whether the mail was successfully handed over to the MTA, but not if it was sent. If e.g. your MTA is postfix, and the postfix service is stopped, mail()
will happily return true
, as queueing the mail to postfix worked. It will however never be sent, if postfix is not manually started (or even correctly configured).
If you really want to make sure, the mail has been sent, you need to talk to a MTA via sockets. There are frameworks for that.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With