How can I test if mail()
has successfully delivered mail?
You can use $_SERVER['REMOTE_ADDR']
in PHP to receive the user's remote IP address.
Use like so:
<?php
$ip = $_SERVER['REMOTE_ADDR'];
echo "User's IP address is: ".$ip;
?>
Try this:
if(@mail($emailRecipient, $subject, $message, $headers))
{
echo "Mail Sent Successfully";
}else{
echo "Mail Not Sent";
}
From http://php.net/mail
Returns TRUE if the mail was successfully accepted for delivery, FALSE otherwise.
The mail() function alone just notifies you that the "email" you have set up is legit and will be send my your email server.
You must check separately for the email address to be legit. A good article can be found here
If these two methods do not work for you well, you can use some "spam" approach using images and your server's log files.
As per Ben reply you can check successfully email delivery as below
$result = mail('abc@test.com', 'Test Subject', $message);
if(!$result) {
echo "Error";
} else {
echo "Success";
}
For better result you can use PHPMailer. Click on below link for detailed documentation of PHPMailer.
http://phpmailer.worxware.com/index.php?pg=tutorial
if(!$mail->Send()) {
echo 'Message was not sent.';
echo 'Mailer error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent.';
}
from the docs:
"Returns TRUE if the mail was successfully accepted for delivery, FALSE otherwise.
It is important to note that just because the mail was accepted for delivery, it does NOT mean the mail will actually reach the intended destination. "