The failure happens and gives this message:
I have checked all emails are valid, and the only thing I notice is the performance of the server sucks the CPU to as much as 7.2 (dual CPU) and the system becomes unresponsive to mail.<b>Fatal error</b>: <br /><strong>Uncaught Error</strong> of type [swift_connection_exception] with message [There was a problem reading line 1 of an SMTP response. The response so far was:<br />[]. It appears the connection has died without saying goodbye to us! Too many emails in one go perhaps?]<br /> @0 swift::send() in /public_html/mailcron.php on line 162<br /> @1 swift::command() in /public_html/mylib/Swift.php on line 437<br /><br /> in <b>/public_html/mylib/Swift/Errors.php</b> on line <b>99</b><br />
The script is below:
Code: Select all
set_time_limit(0);
ignore_user_abort();
foreach($_POST AS $key => $value) {
${$key} = $value;
}
foreach($_GET AS $key => $value) {
${$key} = $value;
}
global $stopped, $entrydate;
$table= "sendoutlist";
$stopped = "n";
$entrydate = date("Y-m-d");
//2007-09-21 10:09:46
$null = "0000-00-00";
require_once ("/home/connect.inc");
$sql2 = "SELECT * FROM sendoutlist WHERE entrydate < '$entrydate' AND done = '$null' AND stopped = '$stopped' or entrydate = '$entrydate' AND done = '$null' AND stopped = '$stopped' LIMIT 1";
echo $sql2;
$resultsx = mysql_query($sql2) or die("An error ocurred :".mysql_error());
while ($row = mysql_fetch_array($resultsx)) {
$myID = $row['jobid'];
$title = $row['mailSubject'];
$listname = $row['listname'];
$lastemail = $row['lastemail'];
//echo $myID;
if ($lastemail != "")
{//check listcounter
require_once ("/home/connect.inc");
$sql3 = "SELECT * FROM listcounter WHERE listname = '$listname' AND jobid = '$myID'";
echo $sql3;
$results3 = mysql_query($sql3) or die("An error ocurred :".mysql_error());
while ($row = mysql_fetch_array($results3)) {$themail = $row['lastemail'];
$howmany = $row['howmany'];
// count of emails should not exceed 4200 per 24 hours
}
require_once ("/home/connect.inc");
//echo "$mailSubject,$myID, $mailBody,$listname";
$mailBody = "";
$table= "walter";
// For each vac line...
$sql4 = "SELECT * FROM $table WHERE jobid = '$myID'";
//echo $sql4;
$results4 = mysql_query($sql4) or die("An error ocurred :".mysql_error());
while ($row = mysql_fetch_array($results4)) {
//echo $sql2;
// split subscriber info into array
$ID = $row["jobid"];
$contact = $row["user"];
$emailadd = $row["useremail"];
$mycat = $row["cat"];
$title = $row["title"];
$salary = $row["salary"];
$location = $row["location"];
$description = $row["skills"];
$benefits = $row["benefits"];
//$description = preg_replace("/[^[:alnum:]]/", " ", $description);
$description=str_replace("#","/n",$description);
//echo "$ID";
$mailBody =$mailBody."\n\nHere is the latest vacancy, ID number {$ID} \n\n Job Title: {$title} \n\n Salary: {$salary} Benefits{$benefits} Location {$location}\n\n{$description} \n\n If you would like to apply for this position please email {$emailadd} or call {$contact} at \n\Employment Agency Ltd\\n\nIf you wish to unsubscribe to $mycat mail list, please unsubscribe at http://www.123.com";
//echo "123 $mailBody";
//exit;
}
// Set up reply address for mailing list
$mailFrom = "Employment <jobs@111.com>";
// Ensure that subject and body of email have
// automatically inserted escape slashes removed
//echo"$mailBody <br>";
$name = "Employment";
$email = "jobs@111.com";
$title = $_POST["mailSubject"];
$sender = $email;
//$sendout = $_POST["to"];
//$sendout ="ros@222.com";
// Attempt to read subscriber file
$x=0;
require_once ("/home/connect.inc");
$table= "jobmail";
$sql5 = "SELECT * FROM $table WHERE mylist = '$listname'";
$resultsb = mysql_query($sql5) or die("An error ocurred :".mysql_error());
while ($row = mysql_fetch_array($resultsb)) {
$theid = $row["id"];
$sendout = $row["mymail"];
// $listtype = $row["mylist"];
$theirname = $row["myname"];
// $thedate = $row["mydate"];
$x= $x +1;
echo"$sendout<br>";
require_once "mylib/Swift.php";
//change this to smtp
require_once "mylib/Swift/Connection/SMTP.php";
//echo "$listname <br>$sendout, $theirname<br>";
require_once "mylib/Swift/Plugin/Throttler.php";
//$swift =& new Swift(new Swift_Connection_SMTP("smtp.host.tld"));
$mailBody2 = "Dear $theirname,\n\n".$mailBody;
$body=stripslashes($mailBody2);
//echo "$body<br>";
//Enable disk caching if we can
if (is_writable("/tmp"))
{
Swift_CacheFactory::setClassName("Swift_Cache_Disk");
Swift_Cache_Disk::setSavePath("/tmp");
}
$swift =& new Swift(new Swift_Connection_SMTP("localhost"));
$message =& new Swift_Message("Latest Vacancy" . $title);
$message->attach(new Swift_Message_Part($body));
$throttler =& new Swift_Plugin_Throttler();
$throttler->setBytesPerMinute(20000000); //Roughly 20MB
$swift->attachPlugin($throttler, "throttler");
//or maybe you want to set the number of messages per minute?
$throttler->setEmailsPerMinute(4); //Max of 1 email every 15 seconds
//$swift->attachPlugin($throttler, "throttler");
//Try sending the email
$sent = $swift->send($message, $sendout, $sender);
echo "$sendout<br>$ID<br>";
//echo "$sent";
//Disconnect from SMTP, we're done
}
if ($sent)
{
$today =date("Ymd");
if ($x == $howmany){echo "$x = $howmany";
$lastadd = $sendout;
$mymessage = "done sending $ID to all in the list -lat address is $lastadd Success!";
//$message->attach(new Swift_Message_Part($body));
$mailSubject = "notification";
$mailFrom = "jobs@222.com";
$mymail = "P@111.com";
mail($mymail, $mailSubject, $mymessage, $mailFrom);
//$sent = $swift->send($message, $sendout, $sender);
//echo"<br>$sent";$stopped = "n";
require_once ("/home/connect.inc");
$sqlU = "UPDATE sendoutlist SET done = '$today', stopped = '$stopped', lastemail = '$lastemail' WHERE jobid ='$myID'";
//echo $sql;
$myresult2U = mysql_query($sqlU) or die("An error ocurred :".mysql_error());
require_once ("/home/connect.inc");
$sqlL = "UPDATE listcounter SET datedone = '$today', lastemail = '$lastemail' WHERE jobid ='$myID'";
//echo $sql;
$myresult2L = mysql_query($sqlL) or die("An error ocurred :".mysql_error());
}
if ($x > $howmany){
$lastadd = $sendout;
$mymessage = "done sending $ID to $lastadd Success!\n\nSent out $x";
//$sent = $swift->send($message, $sendout, $sender);
$mailSubject = "notification";
$mailFrom = "jobs@111.com";
$mymail = "p@111.com";
mail($mymail, $mailSubject, $mymessage, $mailFrom); require_once ("/home/connect.inc");
$stopped = "n";
$sqlU = "UPDATE sendoutlist SET done = '$today', stopped = '$stopped' , lastemail = '$lastemail' WHERE jobid='$myID'";
//echo $sql;
echo"arrived at 221";
$myresult2U = mysql_query($sqlU) or die("An error ocurred :".mysql_error());
require_once ("/home/connect.inc");
$sqlL = "UPDATE listcounter SET datedone = '$today', lastemail = '$lastemail' WHERE jobid ='$myID'";
echo $sqlL;
$myresult2L = mysql_query($sqlL) or die("An error ocurred :".mysql_error());
}
if ($x < $howmany){
$lastadd = $sendout;
require_once ("/home/connect.inc");
$table= "jobmail";
$z= 0;
// For each vac line...p@.
$sql2 = "SELECT * FROM $table WHERE mylist = '$listname'";
//echo $sql2;
$results = mysql_query($sql2) or die("An error ocurred :".mysql_error());
while ($row = mysql_fetch_array($results)) {
$lastmail = $row['mymail'];
$z = $z + 1;
}
If ($z==$x){
$mymessage = "done sending $ID to $lastadd Success!\n\nSent out $x";
$mailSubject = "notification";
$mailFrom = "jobs@111.com";
$mymail = "perry@222.com";
mail($mymail, $mailSubject, $mymessage, $mailFrom);
///$sent = $swift->send($message, $sendout, $sender);
require_once ("/home/connect.inc");
$stopped = "n";
$sqlU = "UPDATE sendoutlist SET done = '$today', stopped = '$stopped' , lastemail = '$lastemail' WHERE jobid='$myID'";
//echo $sql;
$myresult2U = mysql_query($sqlU) or die("An error ocurred :".mysql_error());
}else{
$mymessage = "done sending $ID Failed to complete, last email to $lastadd \n\nSent out $z";
$mailSubject = "notification";
$mailFrom = "jobs@111.com";
$mymail = "ros@222.com";
mail($mymail, $mailSubject, $mymessage, $mailFrom);
//$sent = $swift->send($message, $sendout, $sender);
require_once ("/home/connect.inc");
$stopped = "y";
$sqlU = "UPDATE sendoutlist SET done = '$today', stopped = '$stopped' , lastemail = '$lastmail' WHERE jobid='$myID'";
//echo $sql;
$myresult2U = mysql_query($sqlU) or die("An error ocurred :".mysql_error());}
} }else
{ $mymessage = "sending_failed $ID, Stopped on $sendout";
$mailSubject = "notification";
$mailFrom = "jobs@111.com";
$mymail = "ros@222.com";
mail($mymail, $mailSubject, $mymessage, $mailFrom);
//$sent = $swift->send($message, $sendout, $sender);
// store last email out
require_once ("/home/connect.inc");
$stopped = "y";
$sqlU = "UPDATE sendoutlist SET done = '$today', stopped = '$stopped' , lastemail = '$lastemail' WHERE jobid='$myID'";
//echo $sql;
$myresult2U = mysql_query($sqlU) or die("An error ocurred :".mysql_error());
//$message= "";
//$swift->log->dump();
}}
} //end of while
//echo"endit";
// $swift->disconnect();