WordPress 有人回复时邮件通知的实现方法 SAE 移植版
框架(架构)  /  管理员 发布于 7年前   243
1,先配置一下您的SMTP账户的用户名和密码。
2,将下面的内容粘贴到当前主题的 functions.php 中即可,注意别破坏了原来的结构就行。(或者直接建一个文件,将代码拷贝进去,然后在 functions.php 中引用该文件即可。)
复制代码代码如下:
<?php
/**
* Email Me With The Replay For SAE
*
* Usage:将此段代码粘贴到当前主题的 functions.php 文件中即可。
* 或者将此文件放进主题目录,在 functions.php 中包含此文件
*
* 基于 comment_mail_notify v1.0 by willin kan. http://kan.willin.org/?p=1295(已失效)
* changelist
* 2012-03-29
* version 0.1
*
* 2012-04-29
* version 0.2
* edit $subject to this code
* $subject = '您的评论 ' . mb_substr(strip_tags(get_comment($parent_id)->comment_content), 0, 10, 'utf-8') . ' 有了回应 - ' . get_option("blogname");
*
*
* @author IT不倒翁, willin kan
* @copyright (C) 2011,2012 Just Use It!
* @link yungbo.com
* @version 0.2
*/
function comment_mail_notify($comment_id) {
//换行标志
$lineBreak = "\n";
//缩进标志
$tabBreak = "\t";
$admin_notify = '1'; // are you willing to receive the email? 1 is yes.
$admin_email = get_bloginfo('admin_email'); // you can change $admin_email to your e-mail optionaly.
$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->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 = 'no-reply@' . preg_replace('#^www\.#', '', strtolower($_SERVER['SERVER_NAME'])); // e-mail
$to = trim(get_comment($parent_id)->comment_author_email);
$subject = '您的评论 ' . mb_substr(strip_tags(get_comment($parent_id)->comment_content), 0, 10, 'utf-8') . ' 有了回应 - ' . get_option("blogname");
//邮件主体内容
//估计新浪考虑到安全问题,全部用 htmlspecialchars() 过滤了,所以不要使用 html 标记
$message = '您好,' . trim(get_comment($parent_id)->comment_author) . $lineBreak;
$message .= '您曾在 ' . get_option("blogname") . ' 留言:' . $lineBreak;
$message .= $tabBreak . trim(get_comment($parent_id)->comment_content) . $lineBreak;
$message .= trim($comment->comment_author) . ' 回复了您:' . $lineBreak;
$message .= $tabBreak . trim($comment->comment_content) . $lineBreak;
$message .= '您可以点击 ' . get_comment_link($parent_id) . ' 查看具体情况' . $lineBreak;
$message .= $lineBreak;
$message .= '(系统邮件,请不要直接回复)' . $lineBreak;
$message .= get_option('blogname') . $lineBreak;
$message .= home_url() . $lineBreak;
/*SAE 配置位置*/
$saeTo = $to;
$saeSubject = $subject;
$saeMessage = $message;
$saeSMTPUser = '';//SMTP邮箱
$saeSMTPPass = '';//SMTP密码
$mail = new SaeMail();
$result = $mail->quickSend($saeTo, $saeSubject, $saeMessage, $saeSMTPUser, $saeSMTPPass);
// if ($result === false)
// var_dump($mail->errno(), $mail->errmsg());
}
}
add_action('comment_post', 'comment_mail_notify');
/* Auto checked */
function add_checkbox() {
echo '<input type="checkbox" name="comment_mail_notify" id="comment_mail_notify" value="comment_mail_notify" checked="checked" /><label for="comment_mail_notify">有人回复我时邮件通知我</label>';
}
add_action('comment_form', 'add_checkbox');
代码最近更新日期,2012-04-29
122 在
学历:一种延缓就业设计,生活需求下的权衡之选中评论 工作几年后,报名考研了,到现在还没认真学习备考,迷茫中。作为一名北漂互联网打工人..123 在
Clash for Windows作者删库跑路了,github已404中评论 按理说只要你在国内,所有的流量进出都在监控范围内,不管你怎么隐藏也没用,想搞你分..原梓番博客 在
在Laravel框架中使用模型Model分表最简单的方法中评论 好久好久都没看友情链接申请了,今天刚看,已经添加。..博主 在
佛跳墙vpn软件不会用?上不了网?佛跳墙vpn常见问题以及解决办法中评论 @1111老铁这个不行了,可以看看近期评论的其他文章..1111 在
佛跳墙vpn软件不会用?上不了网?佛跳墙vpn常见问题以及解决办法中评论 网站不能打开,博主百忙中能否发个APP下载链接,佛跳墙或极光..
Copyright·© 2019 侯体宗版权所有·
粤ICP备20027696号