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 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

Written by WPAPI

My name is Purab Kharat, Here is my Personal Blog: Work as an Senior Technical Lead at Smartsourcing Global Pvt Ltd in Princeton, NJ, USA. I contributor of many wordpress plugins and Drupal Modules. I am core developer of Drupal. Connect to purab on LinkedIn or Follow @purab on Twitter or Follow me on Google+ or Write Mail to or Chat with me on Skype : purabdk

This article has 5 comments

  1. Mark Adesina Reply


    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?

    • Wordpress API Reply

      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.

      • Petro Reply

        Hi there, I get the same error. My blog is hosted with supremecenter and thus nt on WAMP or LAMP. How can I fix this?

  2. iskolares Reply

    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 Comment

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