久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

WordPress實現回復文章評論后發送郵件通知的功能

這篇文章主要介紹了WordPress實現回復文章評論后發送郵件通知的功能,涉及wordpress針對評論與郵件的相關操作技巧,需要的朋友可以參考下

本文實例講述了WordPress實現回復文章評論后發送郵件通知的功能。分享給大家供大家參考,具體如下:

很多時候,人們都希望在自己的評論被管理員回復后會收到通知。該函數的作用就是回復后自動郵件通知評論者。

把下面的代碼加到wordpress的主題函數里面,然后修改下郵件帳號密碼。

該函數是針對SAE平臺的wordpress,非SAE平臺不能使用,有需要的話留言我也會寫出相應方法。

復制代碼
代碼如下:
//郵件回復
function comment_mail_notify($comment_id) {
define('MAIL_SMTP', 'smtp.exmail.qq.com'); //smtp服務器
define('MAIL_PORT', 25); //smtp端口
define('MAIL_SENDEMAIL', '123456789@qq.com'); //發送郵件帳號
define('MAIL_PASSWORD', '123456'); //發送郵件密碼
$admin_notify = '1';
$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 : '';
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 ? '1' : '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']));
$to = trim(get_comment($parent_id)->comment_author_email);
$subject = '你在' . get_option("blogname") . '回復被關注啦~';
$message = '
<div style="width: 502px; height: auto; margin-bottom: 50px; margin-left: auto; margin-right: auto; font-size: 13px; line-height: 14px;">
<div style="width: 502px; margin-top: 10px;">
<div style="font-size: 16px; color: #373737; text-align: center;">'.get_bloginfo("name").'</div>
<div style="font-size: 15px; color: #f0f7eb; padding: 9px; margin-top: 20px; overflow: hidden; background: #299982; padding-left: 30px; padding-right: 40px;">你在 '. get_the_title($comment-&gt;comment_post_ID) .' 的評論有了回復:</div>
</div>
<div style="width: 420px; margin-top: 30px; padding: 0 40px 20px; border-left: 1px dashed #299982; border-right: 1px dashed #299982; color: rgba(0,0,0,0.7); background: #f9f9f9; overflow: hidden;">
<div class="one origin" style="border: 1px solid #EEE; overflow: auto; padding: 10px; margin: 1em 0;"><span style="color: #299982;">'. trim(get_comment($parent_id)-&gt;comment_author) .'</span>:'. trim(get_comment($parent_id)-&gt;comment_content) .'</div>
<div class="one reply" style="border: 1px solid #EEE; overflow: auto; padding: 10px; margin: 1em 0 1em 60px;"><span style="color: #299982;">'. trim($comment-&gt;comment_author) .'</span>:'. trim($comment-&gt;comment_content) .'</div>
<p style="margin-bottom: 10px;">點擊<a href="' . htmlspecialchars(get_comment_link($parent_id)) . ' style=">查看完整內容</a></p>
<p style="margin-bottom: 10px;">(此郵件由系統發出,無需回復.)</p>
</div>
</div>
';
$from = "From: \"" . get_option('blogname') . "\" <$wp_email>";
$headers = "$from\nContent-Type: text/html; charset=" . get_option('blog_charset') . "\n";
$mail = new SaeMail(); //對象
$mail->setOpt(array( 'from' => 'admin@xtwind.com', 'to' => trim($to),//接收信箱
'smtp_host' => MAIL_SMTP , //host
'smtp_port' => MAIL_PORT, //port
'smtp_username' => MAIL_SENDEMAIL,
'smtp_password' => MAIL_PASSWORD,
'subject' => $subject,
'content' => $message,
'content_type' => 'HTML'
// 'tls' => true,
//'charset' => 'gbk' ) );
$ret = $mail->send();
}
}
add_action('comment_post', 'comment_mail_notify');

如果使用上面的不行,可以看看前面這篇文章:

《php使用SAE原生Mail類實現各種類型郵件發送的方法》

希望本文所述對大家基于wordpress的網站建設有所幫助。

【網站聲明】本站除付費源碼經過測試外,其他素材未做測試,不保證完整性,網站上部分源碼僅限學習交流,請勿用于商業用途。如損害你的權益請聯系客服QQ:2655101040 給予處理,謝謝支持。

相關文檔推薦

這篇文章主要介紹了PHP使用微信開發模式實現搜索已發送圖文及匹配關鍵字回復的方法,涉及php針對微信json格式數據的解析與正則匹配相關操作技巧,需要的朋友可以參考下
wordpress是很多新手站長搭建個人博客最喜愛的程序,但是最近在使用WordPress的時候遇到了一些問題,所以想著將遇到問題總結分享出來,下面這篇文章主要給大家介紹了關于wordpress在安
這篇文章主要為大家詳細介紹了php實現評論回復刪除功能,具有一定的參考價值,感興趣的小伙伴們可以參考一下
這篇文章主要為大家介紹了Wordpress自動提取內容中第一張圖片作縮略圖的方法,可通過在模板中添加自定義函數實現該功能,是非常實用的技巧,需要的朋友可以參考下
這篇文章主要為大家介紹了Wordpress實現文章支持和反對功能的方法,通過添加自定義函數實現文章的支持和反對功能,是比較典型的WordPress二次開發技巧,具有一定的參考借鑒價值,需要的朋
這篇文章主要為大家介紹了WordPress首頁顯示多個圖片及文字友情鏈接的方法,可實現對原有文字友情鏈接的靈活控制功能,非常具有實用價值,需要的朋友可以參考下
主站蜘蛛池模板: 一级黄色生活视频 | 黑人精品| 日韩一区二区在线视频 | 日韩av第一页 | 亚洲精品一区二 | 国产精品久久久久久久一区探花 | 特黄视频 | 国产欧美一区二区三区在线播放 | 欧美 中文字幕 | 国产欧美一区二区三区久久人妖 | 日韩精品在线视频免费观看 | 国产精品视频999 | 国产成人精品久久 | 精品久久久久久久久久久久 | 一二三区在线 | 国产精品一区二区日韩 | 在线视频 中文字幕 | 国产精品精品视频一区二区三区 | 国产网站在线免费观看 | 最近中文字幕免费 | 免费观看一区二区三区毛片 | 国产精品一区在线观看 | 亚洲一区精品在线 | va精品| 激情六月丁香 | 国产精品美女久久久久久免费 | 91高清在线视频 | 国产一区在线免费观看 | 亚洲另类自拍 | 91九色porny首页最多播放 | 一区日韩| 91精品国产手机 | 亚洲视频一 | 欧美在线亚洲 | 精品国产99 | 久久99精品视频 | 精品久久久久久亚洲精品 | 亚洲视频 欧美视频 | 国产精品毛片一区二区在线看 | 国产成人叼嘿视频在线观看 | 91色视频在线观看 |