Sign up ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have custom post type "Art masters". Each post is master's profile.

In their profiles isset custom fiels name "master_email". I need to send for master email notification every time if new comment is posted.

How i can call post new comment function for use wp_mail? Thank you for help!

share|improve this question

2 Answers 2

up vote 5 down vote accepted

You can try something like this in your functions.php

function send_comment_email_notification( $comment_ID, $commentdata ) {
    $comment = get_comment( $comment_id );
    $postid = $comment->comment_post_ID;
    $master_email = get_post_meta( $postid, 'master_email', true);
    if( isset( $master_email ) && is_email( $master_email ) ) {
        $message = 'New comment on <a href="' . get_permalink( $postid ) . '">' .  get_the_title( $postid ) . '</a>';
        add_filter( 'wp_mail_content_type', create_function( '', 'return "text/html";' ) );
        wp_mail( $master_email, 'New Comment', $message );
add_action( 'comment_post', 'send_comment_email_notification', 11, 2 );
share|improve this answer
Thank you for help. I will try it :) – Bohdan Hdal Dec 10 '11 at 8:17
That's OK but 2 things need to be pointed out: 1. get_comment( $comment_id ) should be get_comment( $comment_ID ) 2. in order for this function to work, post meta (custom field) should have name - value pair declared: master_email - – Dameer Mar 27 '13 at 7:35

You can try this.


function yoursite_wp_mail_from($content_type) {
   return ''; 


function yoursite_wp_mail_from_name($name) {
   return 'Helen Hou-Sandi'; 
share|improve this answer

protected by toscho Sep 6 '12 at 3:29

Thank you for your interest in this question. Because it has attracted low-quality answers, posting an answer now requires 10 reputation on this site.

Would you like to answer one of these unanswered questions instead?

Not the answer you're looking for? Browse other questions tagged or ask your own question.