最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

plugins - How to bulk send emails

programmeradmin3浏览0评论

I should send thousands of email in reaction to a specific event, so the email sending is not manual but it's automatic.

The server where is hosted my website has an hourly limit for email sending (about 500 for hour) so I need to partition it.

Is there some plugin that has that feature? Or some PHP library that helps me to do that?

Thanks

I should send thousands of email in reaction to a specific event, so the email sending is not manual but it's automatic.

The server where is hosted my website has an hourly limit for email sending (about 500 for hour) so I need to partition it.

Is there some plugin that has that feature? Or some PHP library that helps me to do that?

Thanks

Share Improve this question asked Sep 11, 2011 at 13:37 pAkY88pAkY88 1513 silver badges6 bronze badges 1
  • Be aware that any use of delay may hit limits on execution time and therefore terminate unexpectedly. Some hosting providers have a hard limit that cannot be overridded. In such circumstances you'd need to pop emails onto a queue stored to a database and send them in smaller batches using a cronjob. – Nick Amis Commented Feb 23, 2022 at 13:14
Add a comment  | 

2 Answers 2

Reset to default 3

I don't think using sleep() is a good idea, because it takes up resources while it's sleeping, and you could run into script timeout issues.

I also don't think it's a good idea to be sending any important or bulk e-mails from a web server, because that's not really what's it's designed to do. Messages sent from standard mail() / wp_mail() functions are more likely to be flagged as spam than those sent from real MTAs; You don't get any notice when messages bounce; The host may drop the messages because you overstep some arbitrary limit, or because they think you're spamming, and there's a good chance they won't even let you know they're doing it; etc...

I think the best way to do this would be to use a service that's designed to send bulk e-mail, like MailChimp. It will be much more reliable and efficient. You can use plugins like Import Users to MailChimp to sync your WP user accounts with the campaign members. There are also plugins like MailChimp STS to relay WP-generated messages through MailChimp. You may need to search the plugin repository to find exactly what you need, but there are a lot of MailChimp related plugins available.

If you do insist on sending the messages from your web server, you should at least use a library like SwiftMailer instead of wp_mail(). It goes to great lengths to reduce the likelihood of the message being mistakenly flagged as spam, and has an advanced batch-sending system.

You'll need something like the following (maybe-working example code) using get_users();:

$users = get_users( /* Add your args here */ );
foreach ( $users as $user )
{
    $user_email_addresses[] = $user->email; // receive array of user mail addresses here
}

function wpse28212_send_delayed_bulkmail( $email_addresses )
{
    $i = 0;
    foreach ( $user_email_addresses as $email_addy )
    {
        ++$i; // count users up

        $delay = 0; // in miliseconds (ms)

        if ( $i >= 500 )
        {
            $delay = 3600000; // 1 hour
        }
        sleep( $delay );

        wp_mail( $email_addy, 'subject', 'message' );
    }
}

Links:

  • wp_mail();
  • sleep();
  • usleep(); // alternate to sleep();

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论