WordPress Add Comment reply email alert notification

Source: Internet
Author: User

Commenting on replying to posts, proactively sending emails to notify commentators, which is a great move to improve the user experience. Advocate Meng has been using Willin kan main comment reply email alert Notification Code, I believe many people also use, assuming you are not used. The best try.

According to your own needs, choose a code, according to their own needs, the new theme functions.php or pluggable.php(recommended)
Before the last?> of the file, you can:

Method One: All replies are sent by email notification

All comments that are filled in by default will be emailed to the reviewer, no matter what the settings are checked.

/* Comment_mail_notify v1.0 by Willin Kan.  (all replies are emailed) */function comment_mail_notify ($comment _id) {$comment = Get_comment ($comment _id); $parent _id = $comment->comment_parent?

$comment->comment_parent: "; $spam _confirmed = $comment->comment_approved; if ($parent _id! = ") && ($spam _confirmed! = ' spam ') {$wp _email = ' [email protected] '. Preg_replace (' # ^www.# ', ', Strtolower ($_server[' server_name ')); E-mail issue point, no-reply can be changed to available e-mail. $to = Trim (get_comment ($parent _id)->comment_author_email); $subject = ' You are in ['. Get_option (' Blogname '). ' The message has a reply '; $message = ' <div style= ' background-color: #eef2fa; border:1px solid #d8e3e8; Color: #111; padding:0 15px; -moz-border-radius:5px; -webkit-border-radius:5px; -khtml-border-radius:5px; " > <p> '. Trim (get_comment ($parent _id)->comment_author). ' Hello!</p> <p> you have been in the '. Get_the_title ($comment->comment_post_id). ' Message: <br/> '. Trim (get_comment ($parent _id)->comment_content). ' </p> <p> '. Trim ($comment->comment_author). ' Reply to you: <br/> '. Trim ($comment->comment_content). ' <br/>&Lt;/p> <p> You can click to view reply full content </p> <p> Welcome to visit again. Get_option (' Blogname '). ' </p> <p> (this email is sent by the system on its own initiative, do not reply.) </p> </div> '; $from = "From: \" ". Get_option (' Blogname '). "\" < $WP _email> "; $headers = "$from \ncontent-type:text/html; Charset= ". Get_option (' Blog_charset '). "\ n"; Wp_mail ($to, $subject, $message, $headers); }}add_action (' Comment_post ', ' comment_mail_notify ');//-END----------------------------------------


Method Two: Let the visitors choose whether to email notification

A check box appears below the comment box. Let the reviewer decide for themselves whether to receive email notifications.

/* Start */function comment_mail_notify ($comment _id) {$admin _notify = ' 1 ';//admin to receive reply notification (' 1 ' = to; ' 0 ' = not) $admin _email = Get_bloginfo (' Admin_email ');  $admin _email can be changed to your designated e-mail.  $comment = get_comment ($comment _id);  $comment _author_email = Trim ($comment->comment_author_email); $parent _id = $comment->comment_parent?  $comment->comment_parent: ";  Global $wpdb; if ($wpdb->query ("Describe {$wpdb->comments} comment_mail_notify") = = ") $wpdb->query (" ALTER TABLE {$wpdb-&G  t;comments} ADD COLUMN comment_mail_notify TINYINT not NULL DEFAULT 0; "); if ($comment _author_email! = $admin _email && isset ($_post[' comment_mail_notify ')) | |    ($comment _author_email = = $admin _email && $admin _notify = = ' 1 '))  $wpdb->query ("UPDATE {$wpdb->comments} SET comment_mail_notify= ' 1 ' WHERE comment_id= ' $comment _id '"); $notify = $parent _id?  Get_comment ($parent _id)->comment_mail_notify: ' 0 ';  $spam _confirmed = $comment->comment_approved; if ($parent_id! = "&& $spam _confirmed! = ' spam ' && $notify = = ' 1 ') {$wp _email = ' [email protected] '. Pre G_replace (' #^www.# ', ' ', Strtolower ($_server[' server_name '));    E-mail issue point, no-reply can be changed to available e-mail.    $to = Trim (get_comment ($parent _id)->comment_author_email); $subject = ' You are in ['. Get_option (' Blogname ').    ' The message has a reply '; $message = ' <div style= ' background-color: #eef2fa; border:1px solid #d8e3e8; Color: #111; padding:0 15px; -moz-border-radius:5px; -webkit-border-radius:5px; -khtml-border-radius:5px; " > <p> '. Trim (get_comment ($parent _id)->comment_author). ' Hello!</p> <p> you have been in the '. Get_the_title ($comment->comment_post_id). ' Message: <br/> '. Trim (get_comment ($parent _id)->comment_content). ' </p> <p> '. Trim ($comment->comment_author). ' Reply to you: <br/> '. Trim ($comment->comment_content). ' <br/></p> <p> You can click to see the full contents of the reply </p> <p> again to visit '. Get_option (' Blogname '). ' </p> <p> (this email is sent by the system on its own initiative, do not reply.)         </p> </div> '; $from = "From: \" ". Get_option (' Blogname ').         "\" < $WP _email> "; $headers = "$from \ncontent-type:text/html; Charset= ". Get_option (' Blog_charset ').         "\ n";  Wp_mail ($to, $subject, $message, $headers); }}add_action (' Comment_post ', ' comment_mail_notify '); /* Self-check bar */function Add_checkbox () {echo ' <input type= "checkbox" Name= "Comment_mail_notify" id= "Comment_mail_ Notify "value=" comment_mail_notify "checked=" Checked "style=" margin-left:20px; "/><label for=" Comment_mail_ Notify "> when someone replies, email me </label> ';} Add_action (' Comment_form ', ' add_checkbox ');

Method Three: Let the blog administrator decide what situation to send mail

Depending on your needs, you can configure the following code (look at the code gaze) and decide what happens before you send the message.

/* Comment_mail_notify v1.0 by Willin Kan. (No tick box) */function comment_mail_notify ($comment _id) {$admin _email = get_bloginfo (' admin_email ');//$admin _email can be changed to you specify  e-mail.  $comment = get_comment ($comment _id);  $comment _author_email = Trim ($comment->comment_author_email); $parent _id = $comment->comment_parent?  $comment->comment_parent: "; $to = $parent _id?  Trim (get_comment ($parent _id)->comment_author_email): ";  $spam _confirmed = $comment->comment_approved; if ($parent _id! = ") && ($spam _confirmed! = ' spam ') && ($to! = $admin _email) && ($comment _author _email = = $admin _email)) {/* above inference, determine the necessary conditions for sending the message: ($parent _id! = ") && ($spam _confirmed! = ' spam '): replied, and    Not spam can send, must!!    ($to! = $admin _email): Do not send to admin.    ($comment _author_email = = $admin _email): Only the admin reply can be sent.    The above conditions must be changed for the individual to be visible. */$WP _email = ' [email protected] '. Preg_replace (' #^www.# ', ' ', Strtolower ($_server[' server_name ')); E-mail issue point, no-Reply can be changed to an available e-mail. $subject = ' You are in ['. Get_option (' Blogname ').    ' The message has a reply '; $message = ' <div style= ' background-color: #eef2fa; border:1px solid #d8e3e8; Color: #111; padding:0 15px; -moz-border-radius:5px; -webkit-border-radius:5px; -khtml-border-radius:5px; " > <p> '. Trim (get_comment ($parent _id)->comment_author). ' Hello!</p> <p> you have been in the '. Get_the_title ($comment->comment_post_id). ' Message: <br/> '. Trim (get_comment ($parent _id)->comment_content). ' </p> <p> '. Trim ($comment->comment_author). ' Reply to you: <br/> '. Trim ($comment->comment_content). ' <br/></p> <p> You can click to see the full contents of the reply </p> <p> again to visit '. Get_option (' Blogname '). ' </p> <p> (this message is sent by the system on its own initiative.) Do not reply.)         </p> </div> '; $from = "From: \" ". Get_option (' Blogname ').         "\" < $WP _email> "; $headers = "$from \ncontent-type:text/html; Charset= ". Get_option (' Blog_charset') .         "\ n";  Wp_mail ($to, $subject, $message, $headers); }}add_action (' Comment_post ', ' comment_mail_notify ');//-END----------------------------------------

Method Four: Support for nested and @ user-style comment reminders

This method is reproduced from zww.me, this version of the comment reply notification is supported nested and @ user mode. If you have any questions, please go to the author page for feedback.

/* Mail notification by Qiqiboy */function comment_mail_notify ($comment _id) {$comment = Get_comment ($comment _id);//Get this comment-related data by ID     $content = $comment->comment_content; Match the comment content $match _count=preg_match_all ('/<a href= ' #comment-([0-9]+)? "rel=" nofollow ">/si", $content, $matchs     ); if ($match _count>0) {//is assumed to match to foreach ($matchs [1] as $parent _id) {//Send mail to each sub-match Simpaled_send_emai         L ($parent _id, $comment); }}elseif ($comment->comment_parent!= ' 0 ') {//Just in case.         It is helpful to delete the @ reply, but also to find the parent Comment ID to determine the Mail sending object $parent _id= $comment->comment_parent;     Simpaled_send_email ($parent _id, $comment); }else return; } add_action (' Comment_post ', ' comment_mail_notify '); function Simpaled_send_email ($parent _id, $comment) {//functions to send mail by qiqiboy.com $admin _email = get_bloginfo (' Admin_email ') )///admin mailbox $parent _comment=get_comment ($parent _id)//Get information about the person being replied to (or called a parent comment) $author _email= $comment->comment_author _email;//Comment Person Mailbox $to = Trim ($parent _comment->commEnt_author_email)//The reply person mailbox $spam _confirmed = $comment->comment_approved; if ($spam _confirmed! = ' spam ' && $to! = $admin _email && $to! = $author _email) {$wp _email = ' [Emai L protected] '. Preg_replace (' #^www\.# ', ' ', Strtolower ($_server[' server_name '));         e-Mail out point, no-reply can be changed to usable e-mail. $subject = ' You are in ['. Get_option (' Blogname ').         ' The message has a response '; $message = ' <div style= ' background-color: #eef2fa; border:1px solid #d8e3e8; color: #111;p adding:0 15px;-moz-border-radius:5px;-webkit-border-radius:5px;-khtml-border-radius:5px; " > <p> '. Trim (get_comment ($parent _id)->comment_author). ' Hello!</p> <p> you have been in the '. Get_the_title ($comment->comment_post_id). ' Message: <br/> '. Trim (get_comment ($parent _id)->comment_content). ' </p> <p> '. Trim ($comment->comment_author). ' Reply to you: <br/> '. Trim ($comment->comment_content). ' <br/&Gt;</p> <p> You can click <a href= "'. Htmlspecialchars (Get_comment_link ($parent _id,array ("type" = "All")). > See full content </a></p> <p> Welcome back to <a href= "'. Get_option (' home '). ' > '. Get_option (' Blogname '). ' </a></p> <p> (this email has been sent on its own initiative, do not reply.)         </p></div> '; $from = "From: \" ". Get_option (' Blogname ').         "\" < $WP _email> "; $headers = "$from \ncontent-type:text/html; Charset= ". Get_option (' Blog_charset ').         "\ n";     Wp_mail ($to, $subject, $message, $headers); } }

Instructions

Email, the Host support Mail () feature is required. Assuming you find no way to receive email, you can ask your host provider. Because everyone is a different host environment, some friends join this feature when, not always successful, at this moment, you can try the way SMTP sends e-mail.



WordPress Add Comment reply email alert notification

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.