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 = '[email protected]' . preg_replace('#^www\.#', '', strtolower($_SERVER['SERVER_NAME']));
$to = trim(get_comment($parent_id)->comment_author_email);
$subject = '你在' . get_option("blogname") . '回复被关注啦~';
$message = '
<p style="width: 502px; height: auto; margin-bottom: 50px; margin-left: auto; margin-right: auto; font-size: 13px; line-height: 14px;">
<p style="width: 502px; margin-top: 10px;">
<p style="font-size: 16px; color: #373737; text-align: center;">'.get_bloginfo("name").'</p>
<p 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) .' 的评论有了回复:</p>
</p>
<p 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;">
<p 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) .'</p>
<p 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) .'</p>
<p style="margin-bottom: 10px;">点击<a href="' . htmlspecialchars(get_comment_link($parent_id)) . ' style=">查看完好内容</a></p>
<p style="margin-bottom: 10px;">(此邮件由零碎收回,无需回复.)</p>
</p>
</p>
';
$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');

假如应用下面的不行,能够看看后面这篇文章:

《php应用SAE原生Mail类完成各品种型邮件发送的办法》

心愿本文所述对大家基于wordpress的网站建立有所协助。

以上就是安达网络工作室关于《WordPress实现回复文章评论后发送邮件通知的功能》的一些看法。更多内容请查看本栏目更多内容!

版权声明:本文为 安达网络工作室 转载文章,如有侵权请联系我们及时删除。
相关文章
WordPress 图片用独自域名贮存办法

之前我都是用二级域名的方式来存储图片、JS 和 CSS ,前些天在推特上的一位顺序员 yoursunny 通知我,光用二...

网络盛传的对于Wordpress的九大谬论

关于一个刚接触Wordpress的老手来说,或多或少都会遭到网络上对于Wordpress的一些评论影响。有的甚至被奉为...

如何将WordPress博客订阅到QQ邮箱详细该怎样操作

1、登录QQ邮箱,点击右下角&ldquo;浏览空间&rdquo;,进入浏览空间。 2、进入浏览空间后,点击页面右上角&ld...

wordpress应用外链图片作为文章缩略图的办法

1、要有一个确定图片地址的办法:文章中的第一张图片,或许应用自定义栏目添加一个自定义值。2、在前台调用...

WordPress开发中短代码的完成及相干函数应用技巧

其实完成短代码很简略,咱们只要要用到 WordPress 外面的一个函数就能够搞定短代码,外加本人的一个小函数,...

无需插件wordpress生成动态缓存文件的办法

说起wordpress生成动态缓存的话首先想到的就是WP Super Cache插件,的确如此,大少数的wordpress站长们都在...

需求提交

客服服务

亿鸽在线客服系统