/ Published in: PHP
Send an email to all registered users when a post is published, for wordpress 3.1+
Expand |
Embed | Plain Text
/** * Automatically Notify Your Members on New Posts * Send an email to all registered users when a post is published, for wordpress 3.1+ * Simply place this code into your functions.php file. * source : http://wp-snippets.com/575/automatically-notify-your-members-on-new-posts/ */ function email_members($post_ID) { //global $wpdb; //$usersarray = $wpdb->get_results("SELECT user_email FROM $wpdb->users;"); $usersarray = $wp_user_search->get_results(); $arrUsers[] = $arr[$iU]->user_email; } // for mail($users, "New post notification : " . get_bloginfo('name') , "A new post has been published on " . get_bloginfo('siteurl') ); return $post_ID; } add_action('publish_post', 'email_members');
Comments
Subscribe to comments
You need to login to post a comment.

Use wp_mail instead op mail.
Thanks! How do you modify that to add a FROM email address? becuase right now, I get a default email from my hosting provider that doesn't work. The from is NOT from the admin or any other registered user. In an older version of the code (that now creates error with WP 3.0+ there was this line:
$usersarray = $wpdb->getresults("SELECT useremail FROM $wpdb->users;");>Can it be adapted for this snippet? Thanks again. Franck.Using
wp_mailinstead ofmailmakes the FROM to be: [email protected]