Notify your users of new posts on your blog

Posted on March 3rd, 2011

The following snippet will get all user emails from your database and will send an email to them automatically when a post is published.
Of course, you shouldn’t use that code on your blog as it does not currently have any unsubscribe option.

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

add_action('publish_post', 'email_members'); 

Tags: ,