向WordPress发布更新的订阅者发送大量电子邮件

I need to send individual emails to 1500+ subscribers from a WordPress template page. They are not WordPress users but their details are stored in a non WordPress table.

Upon post update, I need to fetch their email addresses from the table and send individual emails to them. The email contains a unique link to unsubscribe.

I have everything working. The only thing is that when the post is updated, it keeps loading and loading as it is sending emails and eventually times out.

Can anyone please advise if there is a better solution to update the post but schedule emails or send emails in chunks of 50s?

As already mentioned in the comments there are some possibilities you can go with - letting WordPress send all those emails on save_post is certainly not a good Idea.

Here are three possible ways you can solve it:

1) Instead of wp_mail() you may want to implement a PHP library for sending many emails fast at once for instance PHPMailer (https://github.com/PHPMailer/PHPMailer).

Advantage: You do not need an external service and no cronjob.

Disadvantage: If the number of subscribers is growing to high this will fail, too.

2) Use an internal cronjob for WP and send chuncks of 50. There are many tutorials out there how WordPress Cronjobs work (https://codex.wordpress.org/Function_Reference/wp_cron)

Advantages: No external service required and almost no limitation in the number of subscribers.

Disadvantages: It will take some time until the WordPress cronjob has finished. It will slow down your site especially if you have many updates.

3) Use an external service like Mailchimp. Just have a look into their API and trigger the email sending.

Advantages: Many additional options. You do not have to implement any sending logic.

Disadvantages: Eventually costs money. Requires Integration of their API. You have to keep subscriber list synchronous.

There are a couple of WordPress plug-ins that do mass mailing. As an example, Mass Email To users. I am going to assume you've looked at them already. I have not used any of them.

What I used to use for an email list of 12,000 subscribers is use PHPList. It has an open source free version which allows you to send 300 messages a month and unlimited subscribers. It allows you to have subscribe/unsubscribe functions with the list and manage your subscribers without adding 1500 accounts to WordPress.

https://www.phplist.com

One of the issues to be aware of is that many ISPs have a 500 message per hour limitation per domain. This means that a list of 1500 people will take at least four hours to send. Why four hours? If you send 500 per hour, you might trip a daemon that blocks your website for using too many resources. Plus you can't receive any emails, since the cap is for every email. But if you dial down your send rate to 400, you should be fine. Even without a restriction, chances are it's going to take a while to send out a message to 1500 subscribers.

I moved onto a email provider like Mailchimp because at 450 emails per hour, it was taking 26+ hours to send an email and mailing list managers tend to be finicky. This gives you all your solutions on one server, which is nice when managing projects.

Good luck.