收集一波常见的加速NPM包的CDN,发现有些还是挺好用的,基本上可以替代unpkg、jsdelivr,用来做博客或者网站加载NPM使用还是可以的。......
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_SEMAIL', '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->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 style="border: 1px solid #EEE; overflow: auto; padding: 10px; margin: 1em 0;">span style="color: #299982;">'. trim(get_comment($parent_id)->comment_author) .'/span>:'. trim(get_comment($parent_id)->comment_content) .'/div>div style="border: 1px solid #EEE; overflow: auto; padding: 10px; margin: 1em 0 1em 60px;">span style="color: #299982;">'. trim($comment->comment_author) .'/span>:'. trim($comment->comment_content) .'/div>p style="margin-bottom: 10px;">点击a href="' . htmlspecialchars(get_comment_link($parent_id)) . ' style=">查看完整内容/a>/p style="margin-bottom: 10px;">(此邮件由系统发出,无需回复.)//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_SEMAIL,'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网站文章ID不连续如何解决?笔记已测试详细阅读
对于WordPress网站文章ID不连续的问题困扰了我很久,今天将WordPress文章ID不连续的原因和具体解决办法做详细的说明。 WordPress文章ID不连续的原因: 用WordPress做网站的站......
2023-08-17 24
-
wordpress建站教程:文章自动调用特色图片详细阅读
继续分享wordpress建站教程。我们在日常更新wordpress网站文章时基本都需要手动添加文章的缩略图,一般是根据文章内容来添加,虽然麻烦一点,但效果更好,对普通的企业wordpress外......
2023-08-14 66