email wordpress users using BCC

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

Related posts

Leave a Reply

1 comment

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