I'm writing a fairly simple register php script that uses PHP's built in mail()
function to email the user an activation link.
The problem is that I can catch the normal errors such as email formatting but once it fires off to the server and say a user has put in an email address that fails, I don't know how to catch this error and tell the user whats happened.
For example at the moment I get this:
Warning: mail() [function.mail]: SMTP server response: 554 : Recipient address rejected: Relay access denied in ** on line 70
Any ideas what I could do about errors like this? I'm aware of using the @ symbol to suppress the error but I kinda of want to do more than that and handle the issue.
Use the boolean result to detect an error:
$success = @mail(...);
Then you want to find out which internal error caused the problem, so use:
$error = error_get_last();
preg_match("/\d+/", $error["message"], $error);
switch ($error[0]) {
case 554:
...
default:
...
Note that this works with php 5.2 onward only.
There is no way to verify delivery or see transport error mails with PHP. You would need a pop3 polling handler 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