throttler bombs out after 1 email

Swift Mailer is a fantastic library for sending email with php. Discuss this library or ask any questions about it here.

Moderators: Chris Corbyn, General Moderators

Post Reply
roscoe
Forum Commoner
Posts: 85
Joined: Tue Aug 05, 2003 10:24 am
Location: essex uk

throttler bombs out after 1 email

Post by roscoe »

OK so took you advice on the throttler :D

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();
}



    }
But it only send out the first email , where have i gone wrong?? :cry:
roscoe
Forum Commoner
Posts: 85
Joined: Tue Aug 05, 2003 10:24 am
Location: essex uk

Post by roscoe »

my stupidity, fixed it!
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

Heh, 3 emails per minute :P
roscoe
Forum Commoner
Posts: 85
Joined: Tue Aug 05, 2003 10:24 am
Location: essex uk

Post by roscoe »

d11wtq wrote:Heh, 3 emails per minute :P
yeah, 3 x 60 = 180 which is below the 200 per hr threashold. So it will not get blacklisted bt hte smtp server
chuckl
Forum Commoner
Posts: 61
Joined: Wed May 23, 2007 7:36 am

Post by chuckl »

In your sample code above, you are creating the plugin $throttler, setting it to bytes per min throttling, and attaching it.
You then immediately change it to emails per minute throttling, and reattach it a second time.
Not sure that that is a good idea.
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

chuckl wrote:In your sample code above, you are creating the plugin $throttler, setting it to bytes per min throttling, and attaching it.
You then immediately change it to emails per minute throttling, and reattach it a second time.
Not sure that that is a good idea.
Well spotted, I never noticed that. It won't conflict because the key "throttler" was used for each attachPlugin() call so it simply remove the previous setting. It voids the first call to setBytesPerMinute() though.
Post Reply