Search code examples
phpwordpressgmail

Best practice for sending bulk emails through WordPress


I am building a site through WordPress and coded in my own bulk email. I used a plugin to ensure that emails are sent authentically through my gmail account. I use wp_mail to trigger the email.

My first strategy was to send to: myself and bcc: everyone. This gave a gmail error for too many recipients.

Then, I split the email into chunks of 49, and it worked well. Now, I’m creating an unsubscribe link and I realized that I have no way to include the recipients email address in the email because it’s the same email bcc’d to 50 people.

What is the best approach to solve this problem? Can I send to: hundreds of people without gmail getting upset at me?


Solution

  • No, usually you can't send hundreds of mails just like that, you will be blocked and it may have repercussions like having your domain-name credibility hurt for a long time.

    there are several ways:

    Ask your Hoster about his stance. For example, my Hoster allows 1 Mail every 1.5 seconds in average. I'm using a cronjob that calls a wordpress endpoint in which i loop thru several 1000 emails (legit newsletters), each loop 2 seconds of break. this is just an example, it doesn't make quite sense, but the important part is: set the timeout fresh on each loop, set a sleep. i tested this with 100000 mails and it worked without a hitch on the website.

    for ($i = 1; $i <= $total; $i++) {
       set_time_limit(20);
       sleep(2);
       wp_mail($email, $subject, $body);  //i set up an smtp plugin for this
    }
    

    Another, and frankly more professional solution, is using a service like mailgun.com, there you can hammer as many mails thru their API as you want. But of course, it costs some $ :-)