Email from PHP code timeout

I have the following php code that sends an email from my webpage when a user clicks a submit button. It works great but every now & then, the email is not sent due to time outs. I’m thinking the reason sometimes it does not work is due to network traffic, etc. My question is, is there a buffering setting in the PHP.ini file I can adjust to make the timeout longer or anything else in the file I can adjust? Or is there anything in my code I can add to adjust a timeout limit?

[php]
$Message = "A pending assignment is ready for your review & signature.\n \nName : ${_REQUEST[‘name’]} \nPACTS#: ${_REQUEST[‘acts’]} \nDue Date: ${_REQUEST[‘date_due_complete’]} } ";
$Subject = “Please Review & Sign”;
//$Headers = “From: [email protected]” . “\r\n” . “CC: [email protected]”;
$Headers = “From: [email protected]”;
if (mail($Email, $Subject, $Message, $Headers))

{

echo "

A notification has been sent to the Supervisor.

";
echo "Once the Supervisor reviews it, they will notify the assigned officer to sign. ";

} else {

echo “The email was not sent. MAKE SURE you hit the refresh button so they will be notified or follow up with an email.”;

}

$url = ‘http://’ . $_SERVER[‘HTTP_HOST’] . dirname($_SERVER[‘PHP_SELF’]);
if ((substr($url, -1) == ‘/’) OR (substr($url, -1) == ‘//’)) {
$url = substr ($url, 0, -1);
}

exit();

} else { 

	echo '<h1 id="mainhead">Error!</h1>
	<p class="error">The following error(s) occurred:<br />';
	foreach ($errors as $msg) { 
		echo " - $msg<br />\n";
	}
	echo '</p><p>Please try again.</p><p><br /></p>';
	
} 

}
[/php]

How are you sure it is due to a timeout? mail() is not a very reliable function to begin with.

On the mail server I can see plus it errors out saying cancelled by the sender which tells me, I is getting cancelled on my end & its not the SMTP server’s issue.

You can change the timeout, but I would wonder if there was another reason it was happening.

http://php.net/manual/en/function.set-time-limit.php

Sponsor our Newsletter | Privacy Policy | Terms of Service