PHP = > if (mail) + timeout?
I have a simplistic webform running on bluehost that when submitted, sends out mail to a distribution list.
Recently the mail server went down, and my php mail script hung when the submit button was clicked. The user tried one more time, and again the page just hung. Later when the mail server came back up, it sent out m开发者_如何学编程ultiple copies of the mail.
My question is, is there an easy way to put some sort of timeout on the script, so that if either a set period of time passes and the mail server has not acknowledged the request, or alternatively, if the number of unsuccessful attempts has exceeded a preset number, then the script will stop attempting to send the mail?
My script:
// try to send email
if (mail($to,$subject,$msg,$headers)) {
header('Location: complete.php');
} else
{
header('Location: incomplete.php');
}
Thanks for any advice you may be able to give, Rich.
PS. I do not have access to change any settings on the server, although I do have a .htaccess file saved to the local directory.
This is not possible. You may want to have a look at phpmailer which is way more advanced than the built-in mail() function php provides.
mail() always returns true if the mail has been submitted to the mailserver (and actually should not hang when the mailserver is down, but return false).
精彩评论