Skip to main content
GameDev.net gamedev.net
🔒 Locked

[web] Bulk Mailing

Started by benryves Mar 12, 2007 at 10:03 AM 6 replies 1.1k views
Original Post
benryves
benryves
I have an application (PHP, MySQL) which needs to send potentially large volumes of email at infrequent intervals. Now, the "easy" way to do this is to find out where the emails need to go, build up the email body, and simply mail in a loop. However, this will lead to the script timing out. Not good. [smile] My current (and faintly Heath Robinson) solution is to INSERT DELAYED the to, subject, and header fields into a database table. This appears to be fast enough; the entire script that looks up the destinations, formats the body of the messages and stores them in the queue currently takes ~2 seconds to execute for 300 messages. On the other end, a scheduled task remotely requests (via WGET) and therefore executes a script every two minutes, which selects 100 messages from the queue and mails them out. Can anyone suggest a cleaner method? I have at my disposal MySQL 3.23, PHP 4, Apache and (on the far end) a Windows machine running a scheduled task every two minutes to try and get things working.
[Website] [+++ Divide By Cucumber Error. Please Reinstall Universe And Reboot +++]
Kylotan
Kylotan
If you can't run any of your own processes on the server, then I doubt there's a much cleaner way available.
Sander
Sander
Surely you can schedule a cron job on your webserver to wget a php file that sends out the blocks of 100 mails. That way you at least keep everything on the same machine and more managable.

If you webhost doesn't allow you to use cronjobs then it's time to move to another. Most web hosting companies let you use cron jobs and even shell access (ssh) is becoming more commonplace. The latter would allow you to write a shell script to replace the "wget mailer.php" step.
benryves
benryves
Quote:
Original post by Sander
Surely you can schedule a cron job on your webserver to wget a php file that sends out the blocks of 100 mails.
Only up to a granularity of once every 12 hours, unfortunately.
[Website] [+++ Divide By Cucumber Error. Please Reinstall Universe And Reboot +++]
Sir P
Sir P
Yo,

The best way to do this, to optimise your system correctly would be by using a shell script that takes care of this talking to your mail relayer directly at the command line however if you do not have full cron, I can only assume you do not have command line access...

and so, why not code your PHP to stagger itself?

Your php code starts on manual trigger or however you wish it to start... it sends X number of emails and then does a while loop.. checks the current time and continues to loop untill the time is 30 minutes later than when the loop started to run... and then sends the next bunch of mails.. then waits again for another 30 minutes..

Easy. So you are looping against the time.

Use microtime for it if needs be.

Though try and get root access and do it at command =]

Best of luck, let me know how it goes :)
www.Xyber-Wars.com - New unique text based BBMORPG. join the beta now!
markadrake
markadrake
If you cannot schedule cron jobs on your current web host I'd take into consideration what your getting for your money. If your paying for your hosting, move yoruself over to BlueHost -> they are a great company and you get a lot for your money including great customer service. (Can you tell that I use them quite frequently?)

For our mass mailer I set up a table in the database and a limiter. The limiter is set to 100 emails per hour. The crong job calls the php file which grabs the next limiter amount of email addresses and sends out mails. The database is updated with the id number of the last e-mail address used to send mail. It checks for any left inthe database and if there are the status of the mailer is kept at "in progress", if there are no more e-mail addresses or the script grabs less then 100 it's automatically set to "compelted".

The file remains to be called every hour but searches for mailings "in progress". This is also where I store the content (or body) of the mail being sent.

I've had as many as 7 mass mail programs running at once (each client is on the same shared hosting via BlueHost).

Complicated I know but alittle insight on what a fellow web designer has done.
benryves
benryves
Thanks for your comments. [smile]

My current solution is really quite horrendous, but does keep everything on the same server; each page has an iframe linking to the mailer script - the script sends mails one by one until the mail queue table is empty.

I have no shell access either.

Really, it would be best to connect to this table remotely and send the mails from an external machine, but I don't have access to any machines that I can guarantee will not be switched off.
[Website] [+++ Divide By Cucumber Error. Please Reinstall Universe And Reboot +++]

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.