WordPress adds the function of automatically notifying bloggers with comments by email

Source: Internet
Author: User
Tags comments php code svn wordpress blog

Method 1: windows and linux hosts

Select the desired code as needed and add the last code in the functions. php file of the topic?> Above:

Email notification is sent for all replies

By default, all comments filled in the email address will be sent to the comments by email, without any selection.

The code is as follows: Copy code

/* Comment_mail_policy v1.0 by willin kan. (all replies are sent by email )*/
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 = 'no-reply @'. preg_replace ('# ^ www. # ', '', strtolower ($ _ SERVER ['server _ name']); // email sending point. no-reply can be changed to available email.
$ To = trim (get_comment ($ parent_id)-> comment_author_email );
$ Subject = 'Your message in ['. get_option ("blogname").'] 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 posted a message in '. get_the_title ($ comment-> comment_post_ID).': <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> Can you click to view the complete response? Hot? Lt;/p>
<P> Welcome to '. get_option ('blogname').' again </p>
<P> (this email is automatically sent by the system. Do not reply.) </p>
</Div> ';
$ From = "From:" ". get_option ('blogname')." "<$ wp_email> ";
$ Headers = "$ from Content-Type: text/html; charset =". get_option ('blog _ charset ')."";
Wp_mail ($ to, $ subject, $ message, $ headers );
  }
}
Add_action ('comment _ post', 'comment _ mail_policy ');
// -- END ----------------------------------------

Method 2: add the comment automatic email notification function for WordPress on SAE


If you have purchased a virtual host or VPS, you can directly install an SMTP mail plug-in. However, if you are the same as me, you need to make some modifications when posting a blog on SAE. now.

First, modify the functions. Php file.
You need to copy and paste the following PHP code to your topic's functions. PHP file <? Php ......?> Between

You can use the SAE Editor or modify the code locally and then use SVN to upload the code. We recommend that you use SVN.

The code is as follows: Copy code

/* Comment_mail_notify by http://www.111cn.net (all replies are sent )*/
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 = 'no-reply @'. preg_replace ('# ^ www. # ', '', strtolower ($ _ SERVER ['server _ name']); // email sending point. no-reply can be changed to available email.
$ To = trim (get_comment ($ parent_id)-> comment_author_email );
$ Subject = 'Your message in ['. get_option ("blogname").'] 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 posted a message in '. get_the_title ($ comment-> comment_post_ID).': <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 <a href = "'. htmlspecialchars (get_comment_link ($ parent_id).'"> is the response complete? Hot? Lt;/a> </p>
<P> Welcome again <a href = "'. get_option ('Home '). '"> '. get_option ('blogname '). '</a> </p>
<P> (this email is automatically sent by the system. Do not reply.) </p>
</Div> ';
$ From = "From:" ". get_option ('blogname')." "<$ wp_email> ";
$ Headers = "$ from Content-Type: text/html; charset =". get_option ('blog _ charset ')."";
Wp_mail ($ to, $ subject, $ message, $ headers );
// Echo 'Mail to ', $ to,' <br/> ', $ subject, $ message;
  }
}
Add_action ('comment _ post', 'comment _ mail_policy ');

// -- END ------------------------------------------ next; we need to install an SMTP plug-in.
Download the Configure SMTP plug-in and upload it to the SAE blog through SVN.

Log on to the background to enable the plug-in and start configuration. Please carefully check the following configuration options.

Send e-mail via GMail? Do not select

SMTP host: smtp.163.com, which is a great 163 mailbox (domestic mailbox is recommended; otherwise, emails may not be received)

SMTP port: 25. This port is generally used by the SMTP server.

Secure connection prefix: Left White, not required

Use SMTPAuth? Required

SMTP username: Your user name, such as the hiadmin_email@163.com SMTP password: mailbox password, 123456789

Wordwrap length: White

Enable debugging? Enable debugging mode, not selected

Sender e-mail: the Sender's mailbox, also write the following hiadmin_email@163.com

Sender name: the name of the Sender. Enter the name you want to display and save the name. Then, test the name.
Click the Send Test e-mail button below.
At this point, the wordpress blog on your SAE will send you an email when there is a comment, and if you reply to other people's comments, there will also be an email. Of course, if you register a new user, you will receive an email 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.