开发者

PHP: Sending huge quantity of emails in batch

开发者 https://www.devze.com 2023-02-14 08:24 出处:网络
Putting aside the disdain from j开发者_StackOverflowunk 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

Putting aside the disdain from j开发者_StackOverflowunk 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!


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.


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)


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


Are you running it through CGI or as a script on the command line? It's best to run it as a script on the command line.

If you say that it gets stuck, try running set_time_limit(0); to avoid PHP quitting from the execution being too long.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号