general related post

how to get wordpress to email more than one email address for comment notifications

categories:Development, Wordpress
tags:

OK so i recently got a request from a client where the client wanted new comment notifications to go out to five seperate email address’s.
Firstly i tried typing the email address’s into the General settings Email address field and then seperating each address with a comma or semi colon, but wordpress removed the additional comma’s and semi colons.

Then after doing some research i came across something on the wordpress.org website.
The below is a simple function that send an email out to specified email address’s.

function email_friends( $post_ID )
{
$subject = "New comment posted on Website";

$headers = "From: website@website.comrn";
$headers .= "Reply-To: website@website.comrn";
$headers .= "MIME-Version: 1.0rn";
$headers .= "Content-Type: text/html; charset=ISO-8859-1rn";

$to = 'email1@domain.com, email2@domain.com, email3@domain.com';

$message = "
Feedback - new comment.

Hi, a new comment was just posted on the website.
click here to login and approve or delete this comment.

Thank you.
";

wp_mail( $to, $subject, $message, $headers );
return $post_ID;
}

Now we simply call the above function when a comment is posted by using wordpress’s add_action();

add_action('comment_post', 'email_friends');

Now everytime a comment is posted the notification will be sent out to all the email address’s listed in the function.
Hope this helps, Nathaniel.


Leave a Reply

Please note that if your comment is in no way related to the contents of this post it will not be published.

D2C Services

HTML, CSS, JQUERY, PHP, Wordpress, Codeigniter, Expression Engine.

What ever your CMS or need D2C can develop it for you

PSD to HTML, PSD to Worpdress theme, PSD to Expression Engine.

You Design we Code, let us give life to your PSD

Custom Online Application Development.

Contact us to build your custom CMS, Project management system or Intranet.

Contact D2C

Call D2C on +27 72 333 0239 or fill out the below form

loading