I am sending mails from php mail() : and I want to receive a failed message if sending is failed to the destinatio .
$to = '[email protected]';
$email_from = "[email protected]";
$full_name = 'XXXX';
$from_mail = $full_name.'<'.$email_from.'>';
$subject = "testing sender name";
$message = "";
$message .= '
<p><strong>This is only a test mail. Please do not reply.</strong><br />
';
$from = $from_mail;
//$headers = "" .
// "Reply-To:" . $from . "\r\n" .
// "X-Mailer: PHP/" . phpversion();
$headers = "From:" . $from_mail . "\r\n" .
"Reply-To:" . $from_mail . "\r\n" .
"X-Mailer: PHP/" . phpversion();
$headers .= 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
if(!mail($to,$subject,$message,$headers))
{
echo 'failed !!';
}
But although $to
mail does no exist,it is not showing failed !!
to check if it is sending mail as intended; <? php $email = "[email protected]"; $subject = "Email Test"; $message = "this is a mail testing email function on server"; $sendMail = mail($email, $subject, $message); if($sendMail) { echo "Email Sent Successfully"; } else { echo "Mail Failed"; } ?>
It could be, for example, because you're missing necessary parameters, have typos in your recipient's email address, or need to set up an SMTP relay. Out of all the possible options as to why your PHP mail() isn't sending email, we found that most issues stem from Postfix being configured incorrectly.
It is the SMTP mail delivery (which PHP hands off the message to) which is taking time. Possibly, the delay you see is greylisting on the receiving server, meaning that the receiving mail server refuses to accept the message until the sending server (which your PHP script handed it to) tries a few times.
The mail method is just sending the mail out. If it does not receive any errors (e.g. by not finding the server etc), it will return succesfull. You will not be able to know if the mail actually landed in the inbox of the recipient unless you create some code around bounced emails etc.
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