throttler bombs out after 1 email
Posted: Fri Aug 10, 2007 7:25 am
OK so took you advice on the throttler
Put some code in:
But it only send out the first email , where have i gone wrong?? 
Put some code in:
Code: Select all
require_once ("/home/arsenal/public_html/control/hideme/connect.inc");
$table= "walter";
$sql2 = "SELECT * FROM $table WHERE jobid = '$myID'";
$results = mysql_query($sql2) or die("An error ocurred :".mysql_error());
while ($row = mysql_fetch_array($results)) {
// 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("/[^[]]/", " ", $description);
$description=str_replace("#","/n",$description);
if ($ID == $myID) {
$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\nPerry Clayman Employment Agency Ltd\n330 High Holborn\nLondon\nWC1V 7QT\nTel: +44 (0)20 7421 1898\nFax: +44 (0)20 7421 1899\n\nIf you wish to unsubscribe to $mycat mail list, please unsubscribe at http://www.pclayman.com";
}
}
If ($ID=="" ){ echo "the vacancy $myID does not exist, please check your job number.";
exit;
}
// Set up reply address for mailing list
$mailFrom = "Perry Clayman Employment <jobs@pclayman.com>";
// Ensure that subject and body of email have
// automatically inserted escape slashes removed
$name = "Employment";
$sender = "jobs@i.com";
$title = $_POST["mailSubject"];
//$sendout = $_POST["to"];
//$sendout ="ros@su.com";
//Validate the email address using a regex (I suggest you use a better one than this!!)
// Attempt to read subscriber file
require_once ("/home/arsenal/public_html/control/hideme/connect.inc");
$table= "jobmailtest";
//this is where it gets the mail addresses and there are 4 for this list
$sql = "SELECT * FROM $table WHERE mylist = '$listname'";
$results = mysql_query($sql) or die("An error ocurred :".mysql_error());
while ($row = mysql_fetch_array($results)) {
$theid = $row["id"];
$sendout = $row["mymail"];
$theirname = $row["myname"];
$x= $x +1;
require_once "mailoutattach/mylib/Swift.php";
//change this to smtp
require_once "mailoutattach/mylib/Swift/Connection/SMTP.php";
require_once "mailoutattach/mylib/Swift/Plugin/Throttler.php";
//$swift =& new Swift(new Swift_Connection_SMTP("smtp.host.tld"));
$mailBody = "Dear $theirname,/n/n".$mailBody;
$body=stripslashes($mailBody);
//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(3); //Max of 1 email every 2 seconds
$swift->attachPlugin($throttler, "throttler");
//Try sending the email
$sent = $swift->send($message, $sendout, $sender);
//Disconnect from SMTP, we're done
$swift->disconnect();
if ($sent)
{
print "Email sent to all subscribers";
print " Job Spec = $myID\n";
exit();
}
else
{ echo"sending_failed";
//$swift->log->dump();
exit;
echo "failed to send";
exit();
}
}