WordPress 有人回復(fù)時(shí)郵件通知的實(shí)現(xiàn)方法 SAE 移植版
發(fā)布時(shí)間:2012-06-07 14:59:33 作者:佚名
我要評(píng)論
常見(jiàn)的 Wordress 郵件通知功能,使用起來(lái)非常的簡(jiǎn)單
1,先配置一下您的SMTP賬戶(hù)的用戶(hù)名和密碼。
2,將下面的內(nèi)容粘貼到當(dāng)前主題的 functions.php 中即可,注意別破壞了原來(lái)的結(jié)構(gòu)就行。(或者直接建一個(gè)文件,將代碼拷貝進(jìn)去,然后在 functions.php 中引用該文件即可。)
<?php
/**
* Email Me With The Replay For SAE
*
* Usage:將此段代碼粘貼到當(dāng)前主題的 functions.php 文件中即可。
* 或者將此文件放進(jìn)主題目錄,在 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 = '您的評(píng)論 ' . mb_substr(strip_tags(get_comment($parent_id)->comment_content), 0, 10, 'utf-8') . ' 有了回應(yīng) - ' . 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) {
//換行標(biāo)志
$lineBreak = "\n";
//縮進(jìn)標(biāo)志
$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 = '您的評(píng)論 ' . mb_substr(strip_tags(get_comment($parent_id)->comment_content), 0, 10, 'utf-8') . ' 有了回應(yīng) - ' . get_option("blogname");
//郵件主體內(nèi)容
//估計(jì)新浪考慮到安全問(wèn)題,全部用 htmlspecialchars() 過(guò)濾了,所以不要使用 html 標(biāo)記
$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) . ' 回復(fù)了您:' . $lineBreak;
$message .= $tabBreak . trim($comment->comment_content) . $lineBreak;
$message .= '您可以點(diǎn)擊 ' . get_comment_link($parent_id) . ' 查看具體情況' . $lineBreak;
$message .= $lineBreak;
$message .= '(系統(tǒng)郵件,請(qǐng)不要直接回復(fù))' . $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">有人回復(fù)我時(shí)郵件通知我</label>';
}
add_action('comment_form', 'add_checkbox');
代碼最近更新日期,2012-04-29
2,將下面的內(nèi)容粘貼到當(dāng)前主題的 functions.php 中即可,注意別破壞了原來(lái)的結(jié)構(gòu)就行。(或者直接建一個(gè)文件,將代碼拷貝進(jìn)去,然后在 functions.php 中引用該文件即可。)
復(fù)制代碼
代碼如下:<?php
/**
* Email Me With The Replay For SAE
*
* Usage:將此段代碼粘貼到當(dāng)前主題的 functions.php 文件中即可。
* 或者將此文件放進(jìn)主題目錄,在 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 = '您的評(píng)論 ' . mb_substr(strip_tags(get_comment($parent_id)->comment_content), 0, 10, 'utf-8') . ' 有了回應(yīng) - ' . 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) {
//換行標(biāo)志
$lineBreak = "\n";
//縮進(jìn)標(biāo)志
$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 = '您的評(píng)論 ' . mb_substr(strip_tags(get_comment($parent_id)->comment_content), 0, 10, 'utf-8') . ' 有了回應(yīng) - ' . get_option("blogname");
//郵件主體內(nèi)容
//估計(jì)新浪考慮到安全問(wèn)題,全部用 htmlspecialchars() 過(guò)濾了,所以不要使用 html 標(biāo)記
$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) . ' 回復(fù)了您:' . $lineBreak;
$message .= $tabBreak . trim($comment->comment_content) . $lineBreak;
$message .= '您可以點(diǎn)擊 ' . get_comment_link($parent_id) . ' 查看具體情況' . $lineBreak;
$message .= $lineBreak;
$message .= '(系統(tǒng)郵件,請(qǐng)不要直接回復(fù))' . $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">有人回復(fù)我時(shí)郵件通知我</label>';
}
add_action('comment_form', 'add_checkbox');
代碼最近更新日期,2012-04-29
相關(guān)文章

CyberPanel安裝WordPress并配置偽靜態(tài)規(guī)則
下面教你如何在 CyberPanel安裝WordPress以及配置偽靜態(tài),需要的朋友可以參考下2023-12-27
這篇文章主要介紹了wordpress無(wú)法安裝更新主題插件的解決辦法,需要的朋友可以參考下2020-12-27WordPress必備數(shù)據(jù)庫(kù)SQL查詢(xún)語(yǔ)句整理
發(fā)現(xiàn)幾條比較實(shí)用的,適合 WordPress 實(shí)用的SQL語(yǔ)句。于是就趕緊收集分享出來(lái)了,需要的朋友可以參考下2017-09-23wordpress在安裝使用中出現(xiàn)404、403、500及502問(wèn)題的分析與解決方法
wordpress是很多新手站長(zhǎng)搭建個(gè)人博客最喜愛(ài)的程序,但是最近在使用WordPress的時(shí)候遇到了一些問(wèn)題,所以想著將遇到問(wèn)題總結(jié)分享出來(lái),下面這篇文章主要給大家介紹了關(guān)于wo2017-08-11WordPress取消英文標(biāo)點(diǎn)符號(hào)自動(dòng)替換中文標(biāo)點(diǎn)符號(hào)的優(yōu)雅方法
這篇文章主要介紹了WordPress取消英文標(biāo)點(diǎn)符號(hào)自動(dòng)替換中文標(biāo)點(diǎn)符號(hào)的優(yōu)雅方法,需要的朋友可以參考下2017-04-04- 這篇文章主要給大家介紹了wordpress自定義上傳文件類(lèi)型的方法,如WordPress默認(rèn)允許上傳 .exe 后綴名的可運(yùn)行文件,那么我們?cè)趺唇褂脩?hù)在WordPress后臺(tái)發(fā)表文章時(shí)上傳 .e2016-12-19
- 大家可能發(fā)現(xiàn)了當(dāng)實(shí)現(xiàn)了前端用戶(hù)中心,后臺(tái)控制面板就失去了作用,那么限制其他用戶(hù)進(jìn)入后臺(tái)控制面板就很有必要了!那么我們要怎么做呢?通過(guò)下面這篇文章分享的方法后,只2016-12-19
WordPress實(shí)現(xiàn)回復(fù)文章評(píng)論后發(fā)送郵件通知的功能
這篇文章主要介紹了WordPress實(shí)現(xiàn)回復(fù)文章評(píng)論后發(fā)送郵件通知的功能,涉及wordpress針對(duì)評(píng)論與郵件的相關(guān)操作技巧,需要的朋友可以參考下2016-10-11WordPress使用自定義文章類(lèi)型實(shí)現(xiàn)任意模板的方法
這篇文章主要介紹了WordPress使用自定義文章類(lèi)型實(shí)現(xiàn)任意模板的方法,可通過(guò)自定義文章類(lèi)型來(lái)實(shí)現(xiàn)任意模版的使用,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2016-10-11WordPress后臺(tái)地址被改導(dǎo)致無(wú)法登陸后臺(tái)的簡(jiǎn)單解決方法
這篇文章主要介紹了WordPress后臺(tái)地址被改導(dǎo)致無(wú)法登陸后臺(tái)的簡(jiǎn)單解決方法,簡(jiǎn)單分析了后臺(tái)無(wú)法登陸的原因與相應(yīng)的解決方法,涉及針對(duì)wordpress配置項(xiàng)的簡(jiǎn)單修改,需要的朋友2016-10-11


