limiting the amount of emails sent at a time in a batch send



I want to limit these script two send 100 email and then pause for a few seconds and then send another 100 emails and repeat this tell it has sent all the emails that are dated for today. This script is runs by cron so it is running in the background.

How would I do this and is it the best way to do it. I am using swift mailer to send the mail.

I think I would use limit 100 in the query but how would I tell it to get the next 100.

$today = date("Y-m-d");
# Cache the Contact that will recive campain messages today
$query = "SELECT emailmessages. * , contacts.* FROM emailmessages, contacts WHERE emailmessages.contact_id = contacts.id AND emailmessages.nextmessagedate = '$today' AND contacts.emailstatus = 'Active'"; $DB_Contact_Result = mysql_query($query);
if (!$DB_Contact_Result) {
die('Invalid query: ' . mysql_error());
}
while ($this_row = mysql_fetch_array ($DB_Contact_Result)){

$CustomerID=$this_row["id"];

//get the message for the contact
$query1 = "SELECT * FROM emailcampaign where member_id = '$this_row[members_id]' AND campaign_id = '$this_row[emailcampaign]' AND day = '$this_row[email_number]'";

$DB_Mail_Result = mysql_query($query1);
if (!$DB_Mail_Result) {
die('Invalid query: ' . mysql_error());
}
$Mail_row = mysql_fetch_array($DB_Mail_Result);
//get member stuff
$query2 = "SELECT * FROM member where members_id = '$this_row[members_id]'";

$DB_Member_Result = mysql_query($query2);
if (!$DB_Member_Result) {
die('Invalid query: ' . mysql_error());
}

$subject=stripslashes($Mail_row['subject']);

$message=stripslashes($Mail_row['textmessage']);

$hmessage=stripslashes($Mail_row['htmlmessage']);

$swiftPlain = $message;
$MailFrom1=$this_row['emailaddress'];
$MailFromName1=$this_row['firstname'];

$full_name=stripslashes($this_row['firstname']) ." " . stripslashes($this_row['lastname']);
//Create the message
$message = new Swift_Message($subject);
$message->attach(new Swift_Message_Part($swiftPlain));
$message->attach(new Swift_Message_Part($swiftHtml, "text/html"));
$message->setReturnPath($MailAddReplyTo);
$message->setReplyTo($MailFrom1,$MailFromName1);
//Now check if Swift actually sends it
$swift->send($message, $this_row['emailaddress'],$MailFrom1,$MailFromName1);

#After we send the email we need to update the database to send the next message
# get the next message number
$nextday=getnextday(stripslashes($this_row['emailcampaign']),stripslashes($this_row['members_id']),stripslashes($this_row['email_number']));
# get the new dates
$newdate=getnewdate(stripslashes($this_row['emailstarted']),$nextday);
#update the emailmessages
//unsubscribecode
updateemailmessages($unpass,$nextday,$newdate,stripslashes($this_row['em_id']),stripslashes($this_row['email_number']));



}//end of mail loop

.



Relevant Pages

  • Re: [PHP] limiting the amount of emails sent at a time in a batch send
    ... all the emails that are dated for today. ... I am using swift mailer ... I think I would use limit 100 in the query but how would I tell it to get ... }//end of mail loop ...
    (php.general)
  • Re: [PHP] limiting the amount of emails sent at a time in a batch send
    ... all the emails that are dated for today. ... I am using swift mailer ... I think I would use limit 100 in the query but how would I tell it to get ... }//end of mail loop ...
    (php.general)
  • Re: HELP! Need AD Query for Last login
    ... query the DCs in the USA domain, how would I modify the script? ... I'm new to VB script and making this simple modification is beyond me at ... >> ' Because the lastLogon attribute is not replicated, ... Then, for each Domain Controller, ADO is used to search the ...
    (microsoft.public.scripting.vbscript)
  • Re: LDAP query information
    ... a "Dim" statement. ... script is run. ... Microsoft MVP Scripting and ADSI ... Can you please provide me info on what to do with the below query? ...
    (microsoft.public.windows.server.scripting)
  • Re: LDAP query information
    ... execution of the vbscript? ... The error message indicates the line number in the script, ... Dim strBase, strFilter, strAttributes, strQuery, adoRecordset ... ' Construct LDAP syntax query. ...
    (microsoft.public.windows.server.scripting)