Andrew Ballard wrote:
On Tue, Jul 29, 2008 at 4:52 PM, Richard Kurth
<[EMAIL PROTECTED]> wrote:
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


I've done something very similar. I have a delivery timestamp column
in the table that is initially NULL, and I set it to UTC_TIMESTAMP()
for each row as I send the message. My query looks like this then:

SELECT * FROM mail_queue WHERE delivery_timestamp IS NULL LIMIT 100.

Andrew

Then what do you do to get the next 100 emails without sending the same ones

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to