WordPress 有人回復時郵件通知的實現(xiàn)方法 SAE 移植版
發(fā)布時間:2012-06-07 14:59:33 作者:佚名
我要評論

常見的 Wordress 郵件通知功能,使用起來非常的簡單
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 .= '(系統(tǒng)郵件,請不要直接回復)' . $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
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 .= '(系統(tǒng)郵件,請不要直接回復)' . $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
相關文章
CyberPanel安裝WordPress并配置偽靜態(tài)規(guī)則
下面教你如何在 CyberPanel安裝WordPress以及配置偽靜態(tài),需要的朋友可以參考下2023-12-27- 這篇文章主要介紹了wordpress無法安裝更新主題插件的解決辦法,需要的朋友可以參考下2020-12-27
- 發(fā)現(xiàn)幾條比較實用的,適合 WordPress 實用的SQL語句。于是就趕緊收集分享出來了,需要的朋友可以參考下2017-09-23
wordpress在安裝使用中出現(xiàn)404、403、500及502問題的分析與解決方法
wordpress是很多新手站長搭建個人博客最喜愛的程序,但是最近在使用WordPress的時候遇到了一些問題,所以想著將遇到問題總結分享出來,下面這篇文章主要給大家介紹了關于wo2017-08-11WordPress取消英文標點符號自動替換中文標點符號的優(yōu)雅方法
這篇文章主要介紹了WordPress取消英文標點符號自動替換中文標點符號的優(yōu)雅方法,需要的朋友可以參考下2017-04-04- 這篇文章主要給大家介紹了wordpress自定義上傳文件類型的方法,如WordPress默認允許上傳 .exe 后綴名的可運行文件,那么我們怎么禁止用戶在WordPress后臺發(fā)表文章時上傳 .e2016-12-19
- 大家可能發(fā)現(xiàn)了當實現(xiàn)了前端用戶中心,后臺控制面板就失去了作用,那么限制其他用戶進入后臺控制面板就很有必要了!那么我們要怎么做呢?通過下面這篇文章分享的方法后,只2016-12-19
WordPress實現(xiàn)回復文章評論后發(fā)送郵件通知的功能
這篇文章主要介紹了WordPress實現(xiàn)回復文章評論后發(fā)送郵件通知的功能,涉及wordpress針對評論與郵件的相關操作技巧,需要的朋友可以參考下2016-10-11WordPress使用自定義文章類型實現(xiàn)任意模板的方法
這篇文章主要介紹了WordPress使用自定義文章類型實現(xiàn)任意模板的方法,可通過自定義文章類型來實現(xiàn)任意模版的使用,具有一定參考借鑒價值,需要的朋友可以參考下2016-10-11WordPress后臺地址被改導致無法登陸后臺的簡單解決方法
這篇文章主要介紹了WordPress后臺地址被改導致無法登陸后臺的簡單解決方法,簡單分析了后臺無法登陸的原因與相應的解決方法,涉及針對wordpress配置項的簡單修改,需要的朋友2016-10-11