Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP: Sending huge quantity of emails in batch

Putting aside the disdain from junk marketing I need to send around 15,000 emails to customers. My coworker has tried to send them through php mail loop but obviously it gets stuck quickly. Is there a conventional (i.e. through PHP script) to accomplish this swiftly? If not, how do you suggest I do this (maybe through exec) without too much overhead?

Thanks!

like image 769
Gal Avatar asked Mar 03 '11 10:03

Gal


3 Answers

I've used PEAR's Mail_Queue to queue up 200,000+ mails at a time. Populating a database is easy and quick, even with customised content, and then a fairly simple script sends around 250 a time - if the load average isn't too high. Then it loops around and sends the next batch.

You won't send them any faster than is usually possible, but it will do it without any problems.

The tutorial gives you almost everything you need - just loop around th 'send_messages.php' script (from the command line is better) until the database queue is empty.

like image 118
Alister Bulman Avatar answered Oct 16 '22 10:10

Alister Bulman


You could look at using something like Gearman to create a queue system as recommended here. Another option would be to look at a paid service like Amazon's Simple Email Service (SES)

like image 2
robjmills Avatar answered Oct 16 '22 11:10

robjmills


No matter how you implement immediate delivery: it'll be a lengthy process that's always subject to interruptions and you can't afford restarting the delivery and sending the same message twice to 5,000 customers.

I believe that a reliable system must use queues. The main script simply adds recipients to a queue and then you have a secondary process that picks items from the queue, get them sent and finally mark them as sent. This secondary process can be launched manually (maybe from the command line) or via cron tab.

I've never used but I have this in my bookmarks: http://ledscripts.com/free/php/phpledmailer

like image 1
Álvaro González Avatar answered Oct 16 '22 10:10

Álvaro González