Send email to site users about new wordpress posts

For increasing traffic of website. It is good to send email to users about new post. we have script for Send email to site users about new wordpress posts.

There are many wordpress plugins available for sending email but I given small code for sending email to wordpress users without using any wordpress plugins

Send email to site users about new wordpress posts
Send email to site users about new wordpress posts

If you are wordpress developer then only use following code. Open your functions.php file from your theme and put following code in that file. Just copy and paste the following code on your functions.php file:

function send_email_users($post_ID)  {
    global $wpdb;
    $usersarray = $wpdb->get_results("SELECT user_email FROM $wpdb->users;");
    $users = implode(",", $usersarray);
    mail($users, "New Article is Published", 'A new article have been published on http://www.purabtech.in. Please visit');
    return $post_ID;
}
add_action('publish_post', 'send_email_users');

You just need to change my domain name to your domain name and put that in your functions.php file. If you are having any issues then Please write to me.
This wordpress hack, tip or trick written by wordpressapi.

Here is some very useful links for wordpress.

Check Following articles for great wordpress hacks of the all the time.

how to create contact us page without wordpress plugin
Add the extra new users details or fields to wordpress without plugin
Display wordpress Tags In A Dropdown Menu without plugin
How to change the Visual Editor Font Size wordpress without plugin
Display wordpress Tags In A Dropdown Menu without plugin
wordpress pagination style without wordpress plugin
show popular posts without wordpress plugin in theme
How to send smtp email through wordpress without plugin
How to put digg button in wordpress without plugin
Get the recent comments without using wordpress plugin or widget
How to Add the social Bookmar Icons in WordPress theme without wordpress plugins
How to exclude pages from wordpress menu without plugin
Show related posts with wordpress post without using any plugin

Published by

Purab

I am Purab from India, Software development is my profession and teaching is my passion. Programmers blog dedicated to the JAVA, Python, PHP, DevOps and Opensource Frameworks. Purab's Github Repo Youtube Chanel Video Tutorials Connect to on LinkedIn

5 thoughts on “Send email to site users about new wordpress posts”

  1. Hello,

    Please I need help.

    I get this error while trying to use the code:

    Catchable fatal error: Object of class stdClass could not be converted to string in C:\wamp\www\mark\wp-content\themes\mytheme\functions.php on line 529

    And here is what i have in line 529:
    $users = implode(“,”, $usersarray);

    Please what could be the problem?

    1. mail function uses the sendmail mail server. Sendmail can be configured before using this script…this script can be run on linux server. you are using the windows with wamp server.. that’s why you are getting the error. use the linux server for email testing.

  2. Thanks for this! I have a slight problem though.

    How do I tweak the code to only send email if a new post is published on one specific category?

    change $post_ID to a constant category ID? thanks!

Leave a Reply

Your email address will not be published.