wordpress评论邮件自动通知
比较实用的WordPress评论邮件自动通知功能,主要的目的在于提高回访性,如果有朋友去你的网站咨询问题,但是过后他可能忘记这回事,有可能就不了了之了,这时候有邮件回复通知就不会让他错过了.
实现评论邮件自动通知的功能只要把以下代码添加到functions.php即可,此方法仅限于Linux主机使用,代码如下:
//评论邮件自动通知 function comment_mail_notify( $comment_id ) { $admin_email = get_bloginfo ( 'admin_email' ); $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 )) { $wp_email = 'no-reply@' . preg_replace( '#^www.#' , '' , strtolower ( $_SERVER [ 'SERVER_NAME' ])); $subject = '您在 [' . get_option( "blogname" ) . '] 的评论有新的回复' ; $message = ' <div style= "font: 13px Microsoft Yahei;padding: 0px 20px 0px 20px;border: #ccc 1px solid;border-left-width: 4px; max-width: 600px;margin-left: auto;margin-right: auto;" > <p> ' . trim(get_comment($parent_id)->comment_author) . ' , 您好!</p> <p>您曾在 [ ' . get_option("blogname") . ' ] 的文章 《 ' . get_the_title($comment->comment_post_ID) . ' 》 上发表评论:<br />' . nl2br (get_comment( $parent_id )->comment_content) . '</p> <p> ' . trim($comment->comment_author) . ' 给您的回复如下:<br>' . nl2br ($comment->comment_(www.111cn.net)content) . '</p> <p style= "color:#f00" >您可以点击 <a href= "' . htmlspecialchars(get_comment_link($parent_id, array('type' => 'comment'))) . '" >查看回复的完整?热?lt;/a></p> <p style= "color:#f00" >欢迎再次光临 <a href= "' . get_option('home') . '" > ' . get_option(' blogname ') . ' </a></p> <p style= "color:#999" >(此邮件由系统自动发出,请勿回复。)</p> </div>'; $message = convert_smilies( $message ); $from = "From: " " . get_option('blogname') . " " <$wp_email>" ; $headers = "$fromnContent-Type: text/html; charset=" . get_option( 'blog_charset' ) . "n" ; wp_mail( $to , $subject , $message , $headers ); } } add_action( 'comment_post' , 'comment_mail_notify' );如果系统不支持mail函数我们需要要安装一个SMTP的插件,下载好Configure SMTP插件、通过SVN上传到SAE博客上,登陆后台启用插件并开始配置、请仔细看下面的配置选项.
Send e-mail via GMail? 不用勾选
SMTP host:smtp.163.com,俺使用的伟大的163邮箱(推荐使用国内的邮箱,否则有可能收不到邮件)
SMTP port:25,一般SMTP服务器都是使用的这个端口
Secure connection prefix:留白、不用选
Use SMTPAuth? 必选
Wordwrap length:留白
Enable debugging? 启用调试模式,不选
Sender e-mail:发送者邮箱,还写上面的hiadmin_email@163.com
Sender name:发送者的姓名,把你希望显示的名称填上即可.
保存之后我们自己测试一把去,点击下面的 Send Test e-mail 按钮,到此你的SAE上的wordpress博客在有评论的时候都会发送邮件给你,然后如果你在回复其他人的评论的时候也会有邮件过去,当然如果新用户注册的时候也会有邮件通知的.
查看更多关于wordpress评论邮件自动通知 - WordPress的详细内容...