I have a send mail function I am using for newsletters it keeps saying it has timed out at 30 seconds but I increased the time out variable to 60 seconds and tried again. It again gave me an error for a 30 second time out but on a line further down in the code. So I went back and increased the time out to 90 seconds and it gave me the error again with the 30 second time out.. but this time the error stated a line even further down the code
Here is my code I commented the lines the errors happened at at each change of the time out variable.
Here is the send mail function:
function authSendEmail($from, $to, $subject, $body)
{
//SMTP + SERVER DETAILS
/* * * * CONFIGURATION START * * * */
include("../includes/email_config.php");
/* * * * CONFIGURATION END * * * * */
//Connect to the host on the specified port
$smtpConnect = fsockopen($smtpServer, $port, $errno, $errstr, $timeout);
/*** this is where the first error occured: for the line below: increased to 60 secs ***/
$smtpResponse = fgets($smtpConnect, 515);
if(empty($smtpConnect))
{
$output = "Failed to connect: $smtpResponse";
return $output;
}
else
{
$logArray['connection'] = "Connected: $smtpResponse";
}
//Request Auth Login
fputs($smtpConnect,"AUTH LOGIN" . $newLine);
$smtpResponse = fgets($smtpConnect, 515);
$logArray['authrequest'] = "$smtpResponse";
//Send username
fputs($smtpConnect, base64_encode($username) . $newLine);
$smtpResponse = fgets($smtpConnect, 515);
$logArray['authusername'] = "$smtpResponse";
//Send password
fputs($smtpConnect, base64_encode($password) . $newLine);
$smtpResponse = fgets($smtpConnect, 515);
$logArray['authpassword'] = "$smtpResponse";
//Say Hello to SMTP
fputs($smtpConnect, "HELO $localhost" . $newLine);
$smtpResponse = fgets($smtpConnect, 515);
$logArray['heloresponse'] = "$smtpResponse";
//Email From
fputs($smtpConnect, "MAIL FROM: $from" . $newLine);
/** the line below is where the second timeout error occured: increased to 90 secs **/
$smtpResponse = fgets($smtpConnect, 515);
$logArray['mailfromresponse'] = "$smtpResponse";
//Email To
fputs($smtpConnect, "RCPT TO: $to" . $newLine);
$smtpResponse = fgets($smtpConnect, 515);
$logArray['mailtoresponse'] = "$smtpResponse";
//The Email
fputs($smtpConnect, "DATA" . $newLine);
$smtpResponse = fgets($smtpConnect, 515);
$logArray['data1response'] = "$smtpResponse";
//Construct Headers
$headers = "MIME-Version: 1.0" . $newLine;
$headers .= "Content-type: text/html; charset=iso-8859-1" . $newLine;
//$headers .= "To: <$to>" . $newLine;
//$headers .= "From: <$from>" . $newLine;
fputs($smtpConnect, "To: $to\nFrom: $from\nSubject: $subject\n$headers\n\n$body\n.\n");
/*** the line below is the third error **/
$smtpResponse = fgets($smtpConnect, 515);
$logArray['data2response'] = "$smtpResponse";
// Say Bye to SMTP
fputs($smtpConnect,"QUIT" . $newLine);
$smtpResponse = fgets($smtpConnect, 515);
$logArray['quitresponse'] = "$smtpResponse";
}
Here is the configuration file code:
$smtpServer = "******";
$port = "25";
$timeout = "90";
$username = "*******";
$password = "*****";
$localhost = "localhost";
$newLine = "\r\n";
Let me know thanks.