Email queueing in php

Mar 12, 2012   //   by   //   Blog, MySQL Tutorial, PHP Tutorial  //  No Comments

the most proper way to sending email of minimal 1000 or more in php. reliable email queueing technique that is capable to handle that

i would insert a new record into a mail queue table for each email waiting to be sent and then use a separate process (like a CRON) to check the table periodically for any queued items.

if any emails are queued (and the email is not customised for each recipient) i would then group the emails by domain and send blocks together to reduce the total number of emails that have to be sent, i.e. if you have 1000 emails queued and 250 are to gmail accounts i would send the 250 in 25 blocks of 10 (remember to Bcc recipients to avoid them seeing each other).

to actually send the mail i would use PEAR mail over php’s mail() function

after sending the email either delete record(s) from the queue or change a status flag to show it was sent and loop – i would also add a counter to keep track of emails that failed to send and remove them after x failed attempts

to overcome timeout issues i would either,(depending on the situation) – set the settimelimit() to x seconds and keep track of the script execution time (killing the script after (x-1) seconds) – call the script from the command line to avoid timeouts – set a limit to the number of emails the script could send in one execution

Leave a comment

Share This Post

RSS Wordpress News