How to: Automatically notify your members on new posts

Just paste the following code on your functions.php file:

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

Once saved, all registered users will receive an email when a new post is published.

This recipe is inspired from an example found in WordPress Codex.

Looking for WordPress hosting? Try WP Web Host. Prices starts at $5/month and you can try it for free!

How to: Automatically notify your members on new posts

Leave a Reply

Your email address will not be published. Required fields are marked *