Send Comment Notification Email To Author

Send Comment Notification Email To Author In WordPress


Original Posts

Send Comment Notification Email To Author In WordPress

When a user left a comment on your site, and the comment get a new reply, this code will send a notification email to the author. Also, you can send a copy to yourself with Bcc to ensure this feature working fine.

However, there is another issue. With default settings in WordPress, the email filed in comment form is not required. And that’s what we would customize in the next post.

add_action( 'comment_post', 'send_comment_notification_mail', 10, 2 );
function send_comment_notification_mail( $comment_ID, $comment_approved ) {

    if( 1 === $comment_approved ){

        $comment = get_comment( $comment_ID );

        if($comment->comment_parent != 0){

            $parent_id = $comment->comment_parent;
            $parent_comment = get_comment( $parent_id );
            $author_mail = $parent_comment->comment_author_email;
            $post_link = get_permalink($parent_comment->comment_post_ID);
            $post_title = get_the_title($parent_comment->comment_post_ID);

            $comment_link = $post_link."#comment-".$parent_id;
            $comment_link = urldecode($comment_link);

            $to = $parent_comment->comment_author." <".$author_mail.">";
            $content = "Your comment in '".$post_title."' has a new reply。\n".

            $headers[] = 'From: ARON HACK <>';
            // $headers[] = 'Cc:';
            $headers[] = 'Bcc:';

                    "[AROH HACK] Comment Reply Notification",

Hooks Used In This Tutorial


Related Posts

The Complete WordPress Customization Tutorial – Just Copy And Paste And Work

Content Protection by

Leave a Reply

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