1

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');
3

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' )
    ) 
);
  • 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. – fuxia Mar 19 '12 at 12:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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