wordpress   发布时间:2019-10-30  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了WordPress实现回复文章评论后发送邮件通知的功能大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

本文实例讲述了WordPress实现回复文章评论后发送邮件通知的功能。分享给大家供大家参,具体如下:

很多时候,人们都希望在自己的评论被管理员回复后会收到通知。该函数的作用就是回复后自动邮件通知评论者。

把下面的代码加到wordpress的主题函数里面,然后修改下邮件帐号密码。

该函数是针对SAE平台的wordpress,非SAE平台不能使用,有需要的话留言我也会写出相应方法。

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("updat{$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") . '回复被关注啦~';
$@R_673_8798@ge = '


'.geT_Bloginfo("name").'
你在 '. get_the_title($comment->comment_post_ID) .' 的评论有了回复:
'. trim(get_comment($parent_id)->comment_author) .':'. trim(get_comment($parent_id)->comment_content) .'
'. trim($comment->comment_author) .':'. trim($comment->comment_content) .'
点击查看完整内容

(此邮件由系统发出,无需回复.)

'; $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' => $@R_673_8798@ge, 'content_type' => 'HTML' // 'tls' => true, //'charset' => 'gbk' ) ); $ret = $mail->send(); } } add_action('comment_post', 'comment_mail_notify');

希望本文所述对大家基于wordpress的网站建设有所帮助。

大佬总结

以上是大佬教程为你收集整理的WordPress实现回复文章评论后发送邮件通知的功能全部内容,希望文章能够帮你解决WordPress实现回复文章评论后发送邮件通知的功能所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。