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 am currently using the below code to email users when a new post is published, but I need it to BCC all users and not TO all users. Any ideas?

function email_members($post_ID)  {
global $wpdb;
$usersarray = $wpdb->get_results("SELECT user_email FROM $wpdb->users;");
$users = implode(",", $usersarray);
mail($users, "New WordPress recipe online!", 'A new recipe have been published on http://www.wprecipes.com');
return $post_ID;
}

add_action('publish_post', 'email_members');
share|improve this question

1 Answer 1

First: Don’t use mail(). Use wp_mail() instead.

wp_mail( 
    // Send it to yourself
    get_option( 'admin_email' ), 
    'Your subject', 
    'Your message', 
    // extra headers
    array (
        'Bcc:' . implode( ",", $usersarray ),
        'From:' . get_option( 'admin_email' )
    ) 
);
share|improve this answer
    
So is this the way it should look? function email_members($post_ID) { global $wpdb; $usersarray = $wpdb->get_results("SELECT user_email FROM $wpdb->users;"); $users = implode(",", $usersarray); wp_mail( // Send it to yourself get_option( 'admin_email' ), 'Your subject', 'Your message', // extra headers array ( 'Bcc:' . implode( ",", $usersarray ), 'From:' . get_option( 'admin_email' ) ) ); return $post_ID; } add_action('publish_post', 'email_members'); –  Shae Mar 19 '12 at 12:19
    
@Shae Yeah, seems to be okay. You don’t have to return anything on an action. –  toscho Mar 19 '12 at 12:48

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.