Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I've created this function:

function email_subscribed_users($event)
{
    $users = get_users('role=subscriber');

    foreach ($users as $user) {
        $accepted = get_user_meta($user->ID, 'accepted', true);
        if ($accepted) {
            wp_mail($recipients, $event->event_title, $event->event_desc, 'From: <example@example.com>');
        }
    }
}

But it requires a lot of time sending the emails knowing that the users will increase by time.What function should I use to send the emails efficiently or there is a newsletter plugin to do this?

share|improve this question
1  
Have you searched for "Newsletter Plugins"? –  Howdy_McGee Oct 31 '13 at 20:45
1  
Careful, if you start sending out a ton of unsolicited mail from your domain you're going to get blacklisted. You're much better off using a service like aweber, mailchimp, etc. –  Andrew Bartel Oct 31 '13 at 22:13
    
Yes @Howdy_McGee i searched but the plugins send emails when a new post or a new page is published.The problem is that i've created a section called "events" and it's neither post or page it simply uses $wpdb thats why I need a function to do that :/ –  Antonio Papa Nov 1 '13 at 8:26
    
What newsletter plugin does what i want do you know any? –  Antonio Papa Nov 1 '13 at 8:31
add comment

1 Answer

You can directly query for users having a specific user_meta value. This will gain some performance over loading all the users first and then iterating over them and loading the meta_value afterwards.

Have a look at the WP_User_Query class.


If we are speaking of larger numbers of mails you may be better off to use a full-blown newsletter plugin (that will automatically queue the mails and not try to send them all at once). And if you are really sending a lot of mails (like +5.000 in one newsletter) I would advise you to use an external mail service provider (CakeMail, Mailchimp ...).

share|improve this answer
1  
if there is no personalization done in the mail you might be able to save time by sending it to multiple recipients by using BCC. –  Mark Kaplun Nov 1 '13 at 5:00
    
I used Wysija newsletter but i don't know how to send emails "programmatically" when i call my own function send_emails().That is what I want can I do that with Wysija or any other newsletter? –  Antonio Papa Nov 1 '13 at 8:47
1  
@AntonioPapa Actually Wysija already adds jobs to wp-cron itself to shedule the emails in batches (like 50 mails per cron run), so you might have a look at that, maybe you are able to create those cronjobs by yourself to make it send emails at regular intervals (wordpress.org/plugins/wp-crontrol is a great plugin for looking which jobs are sheduled). –  s1lv3r Nov 1 '13 at 15:49
    
Thanks i will check it –  Antonio Papa Nov 1 '13 at 16:23
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.