一区二区三区在线-一区二区三区亚洲视频-一区二区三区亚洲-一区二区三区午夜-一区二区三区四区在线视频-一区二区三区四区在线免费观看

服務器之家:專注于服務器技術及軟件下載分享
分類導航

DEDECMS|帝國CMS|Discuz|PHPCMS|Wordpress|ZBLOG|ECSHOP|蘋果CMS|極致CMS|CMS系統|

服務器之家 - 建站程序 - Wordpress - WordPress實現回復文章評論后發送郵件通知的功能

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

2019-08-31 15:29WordPress大學 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', '[email protected]'); //發送郵件帳號
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' => '[email protected]', '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');

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

 

 

延伸 · 閱讀

精彩推薦
主站蜘蛛池模板: 掀开奶罩边躁狠狠躁软学生 | 垫底辣妹免费观看完整版 | 黑帮大佬与我的365天2标清中文 | 欧美老女人b | 5g影院天天5g爽天天看 | 手机在线观看网站免费视频 | 四虎成人www国产精品 | 国产成人综合亚洲一区 | 日本亚洲娇小与黑人tube | 好爽好粗 | 五月色天在线视频综合观看 | 国产剧情在线播放 | 99久久精彩视频 | 肉大捧一进一出视频免费播放 | 91夜夜人人揉人人捏人人添 | 久久久无码精品亚洲A片软件 | 久久精品观看 | 精品高潮呻吟99AV无码视频 | 狠狠色成人综合 | 嘉嘉的丝袜美腿白丝 | 成人性生交小说免费看 | 99久久国产综合精品女不卡 | 精品日本三级在线观看视频 | 国产精品对白刺激久久久 | 深夜在线网址 | 男人天堂影院 | 边吃奶边扎下面 | 国产东北三老头伦一肥婆 | 99热在线只有精品 | 美女脱一净二净不带胸罩 | 亚洲精品福利你懂 | 国产一区二区三区欧美精品 | 香蕉eeww99国产精选播放 | 亚洲人成网站在线观看90影院 | 狠狠澡| 日韩不卡一区二区 | 精品一区二区免费视频蜜桃网 | 成人国产精品视频 | 91精品国产91久久久久久麻豆 | 国产99精品成人免费视频 | 太大了轻点阿受不了小说h 四色6677最新永久网站 |