Monday, June 10, 2013

How to Use WordPress wp_mail() for Mailing to Thousands Recipient Without Timeout

We know how to send email using PHP  function mail(). WordPress has a function to send email. wp_mail() is used  to send email form WordPress site. wp_mail() has a lot of advantage instead of using php mail() function. PHP  mail() function can take only one recipient email address at once. If we want to sent mail to 10 people then we have to call mail() function 10 times. But we can use multiple  recipient address together in wp_mail() function. This is not a problem. When we want to send mail to thousands email address, then if we run thousands mail event in a single request then php will must timeout. So how can we send email to thousands people without timeout. We may run a PHP/WP cron job to send a chunk of mail in each call.  Then we have to use database to store the mail sending status. Each time when a scheduled event called then we should check the last sending status and should send next few mail in the same process. And the rest emails should be sent in next scheduled cron call.
I am not saying this is the right process. I have to digg into the codes of newslatter plugins, how they handle this bulk emailing process.  

How to Use wp_mail for Thousands Recipient