To improve communication between guest commenters and authors, I am fiddling with a script that sends an email to the author of a comment when it receives a reply.

Here is how the code looks so far:

Plugin Name: Comment Reply Notifier
Plugin URI: http://wordpress.stackexchange.com/users/24875/christine-cooper
Version: 0.1
Author: Christine Cooper
Description: When someone replies to a comment, an email is sent to the writer of the replied comment.
Author URI: http://wordpress.stackexchange.com/users/24875/christine-cooper

add_action('comment_post', 'comment');
function comment($comment_reply_id) 
    $comment = get_comment($comment_reply_id);
    if($comment->comment_parent != 0) 
        $old_comment = get_comment($comment->comment_parent);
        if($old_comment->user_id == 0)
            $email = $old_comment->comment_author_email;
            $name = $comment->comment_author;
            $content = $comment->comment_content;
            $post = get_post($comment->comment_post_ID);
            $title = $post->post_title;
            $link = get_permalink($comment->comment_post_ID);
            $blogname = wp_specialchars_decode(get_option('blogname'), ENT_QUOTES);
            $subject = sprintf('Comment reply: "%2$s" at %1$s', $blogname, $title );
            $notify_message  = sprintf('Someone replied to a comment you left on: %s', $title ) . "\r\n";
            $notify_message .= sprintf( 'Reply by: %1$s ', $name ) . "\r\n";
            $notify_message .= 'Comment: ' . "\r\n" . $content . "\r\n\r\n";
            $notify_message .= 'You can reply to the comment here: ' . "\r\n";
            $notify_message .= $link . "#comments\r\n\r\n";
            $message_headers = "Content-Type: text/plain; charset=\"" . get_option('blog_charset') . "\"\n";
            wp_mail( $email, $subject, $notify_message, $message_headers );


It works fine, feel free to try it. There are two things I want to add to it. I want to adjust the name and the email of the message. So I want to set the Blog name as the name of the sender and a custom email as the sender's mail (for instance no-reply@domain.com). How do I do it?

  • Ok, but how is that better than e.g. 'uComment', 'Send email only on Reply to My Comment' or 'Comment Reply Notifier'? Mar 31, 2013 at 21:55

1 Answer 1


Guess you need to use header to perform the sender... by default the sender is wordpress@yousite.domain

$headers = 'From: My Name <myname@mydomain.com>' . "\r\n";


wp_mail( $email, $headers, $subject, $notify_message, $message_headers );

Edited... source: http://codex.wordpress.org/Function_Reference/wp_mail

  • What about the sender name?
    – Christine Cooper
    Feb 12, 2013 at 18:27
  • ok.. its seems easier then it looks like. Now dunno if it works. Feel free to edit mu answer and improve it. Feb 12, 2013 at 18:30
  • Unfortunately, it didn't work. It appears that $sender replaced the title of the message, not the actual email that it was sent from and the name of the sender.
    – Christine Cooper
    Feb 12, 2013 at 18:34
  • 1
    Maybe it is related to headers? codex.wordpress.org/Function_Reference/wp_mail
    – Christine Cooper
    Feb 12, 2013 at 18:36
  • ahahha..we saw both same time. yea..was cheking that as well :D answer was updated. Feb 12, 2013 at 18:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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