Send email in batches

I have a script to email out a newsletter which is setup as a cron job… There are now to many email addreses in the database to send out in one go. How can I break it up into batches of say 65 per hour and run as a cron untill it has sent to all records in the database?

Thanks

Create a table that has two columns, e-mail and status. Populate it with the e-mail addresses to send the newsletter to, and set the status to 0 for all rows.

Your script fetches the first 65 rows of the table with status of 0, sends the mails, and updates the status to 1 for those rows. Next time it runs, it’ll find the next 65 mails, etc. until there are no rows with a status of 0. It’s a work queue.

I was thinking along those lines…

What about getting the cron to run enough times till all the emails have been sent with a 2 hour gap between each patch?

If it runs every two hours, it’ll eventually send all the mails no matter how many there are. You can only subtract 65 so many times before you have 0 left. Or am I reading that wrong?

Just run it every 2 hours. The script should not error if it querys the db and finds nothing to do.

Was only wanting the cron to run on the first of each month, sending the email to all in the database, but 65 at a time every 2 hours untill they have all been sent

The script could leave a note in the database about when it last checked the database, whether it should be sending emails, and about it’s progress.

That way whenever the script starts up, it can check to see the month it last checked is different from the current month. If it is, start sending the emails again.

You can also have cron jobs set up to send every 2 hours on a certain day, such as the 1 day, or every few hours on the first couple of days of the month.


Paul Wilkins

Ahh yes I have it working thanks…

Is there away to some how check if the email are getting bounced back so they can be deleted from the database if they no longer exist?

Thanks

Whole other topic involving customizing your mail software, so you’ll need to do some searching specific to the mail server you’re using.