Warning: mysqli_query(): (HY000/1030): Got error 28 from storage engine in /home/wwwroot/zhuchunshu.com/wp-includes/wp-db.php on line 2056
wordpress评论回复自动邮件提醒 - VPS测评推荐网站 - 朱纯树博客
Warning: mysqli_query(): (HY000/1030): Got error 28 from storage engine in /home/wwwroot/zhuchunshu.com/wp-includes/wp-db.php on line 2056
Warning: mysqli_query(): (HY000/1030): Got error 28 from storage engine in /home/wwwroot/zhuchunshu.com/wp-includes/wp-db.php on line 2056
class="post-template-default single single-post postid-1657 single-format-standard m-excerpt-cat comment-open site-layout-2 text-justify-on m-sidebar">
cloudacead cloudacead


转自 https://wpbom.com/2499.html


SMTP邮件 功能在WordPress 中是很常用的功能, 虽然WordPress自带了mail函数,但用自带mail函数发送邮件很容易失败或者被拒收。

有很多虚拟主机基本都是禁用了 mail 函数,所以我们只能使用SMTP服务发送邮件,网上关于SMTP的WordPress插件有很多,今天我分享一种不需要插件纯代码实现STMP邮件发送的功能。



function comment_mail_notify($comment_id) {
$comment = get_comment($comment_id);
$parent_id = $comment->comment_parent ? $comment->comment_parent : '';
$spam_confirmed = $comment->comment_approved;
if (($parent_id != '') && ($spam_confirmed != 'spam')) {
$wp_email = 'no-reply@' . preg_replace('#^www\.#', '', strtolower($_SERVER['SERVER_NAME']));

$to = trim(get_comment($parent_id)->comment_author_email);
$subject = '您在 [' . get_option("blogname") . '] 的留言有了回应';
<!DOCTYPE html>
    <meta charset="utf-8">
<body style="width:100%;height:800px;background-color:#EEF3FA; font-size:14px;font-family:Microsoft YaHei;">
    <div style="margin:100px auto;background-color:#fff;  width:866px; border:1px solid #F1F0F0;box-shadow: 0 0 5px #F1F0F0;">
    <div style="width:838px;height: 78px; padding-top: 10px;padding-left:28px; background-color:#F7F7F7;">
        <a style="cursor:pointer; font-size:30px; color:#333;text-decoration: none; font-weight: bold;"
           href="'. get_option('home') .'">' . get_option('blogname') . '</a><span
            style="color:#999; font-size:14px;padding-left:20px;">一个技术型主机测评网站</span>
    <div style="padding:30px;">
        <div style="height:50px; line-height:50px; font-size:16px; color:#9e9e9e;">你有一条新的评论</div>
        <div style="line-height:30px;  font-size:16px; margin-bottom:20px; text-indent: 2em;">
            您在<a href="' . get_option('home') . '" target="_blank">' . get_option('blogname') . '</a> 上的留言有回复啦!
        <div style="line-height:40px;  font-size:14px;">
            <label style="color:#999;">评论人:</label>
            <span style="color:#333;">'.trim($comment->comment_author).' </span>
        <div style="line-height:40px;  font-size:14px;">
            <label style="color:#999;">评论地址:</label>
            <a href="'.htmlspecialchars(get_comment_link($parent_id)).'" style="color:#333;">'.htmlspecialchars(get_comment_link($parent_id)).'</a>
        <div style="line-height:40px;  font-size:14px;">
            <label style="color:#999;">评论时间:</label>
            <span style="color:#333;">'.trim($comment->comment_date).'</span>
        <div style="line-height:40px;  font-size:14px;">
            <label style="color:#999;">PS:</label>
            <span style="color:#333;">请不要回复此邮件,此邮件来自博客自动发送</span>

$from = "From: \"" . get_option('blogname') . "\" <$wp_email>";
$headers = "$from\nContent-Type: text/html; charset=" . get_option('blog_charset') . "\n";
wp_mail( $to, $subject, $content, $headers );
//echo 'mail to ', $to, '<br/> ' , $subject, $message; // for testing

add_action('comment_post', 'comment_mail_notify');
赞(0) 打赏
未经允许不得转载:VPS测评推荐网站 - 朱纯树博客 » wordpress评论回复自动邮件提醒


  • 暂无文章

评论 7

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
  1. #0

    Hey there! I’m at work surfing around your blog from my new iphone!

    Just wanted to say I love reading your blog and look
    forward to all your posts! Keep up the fantastic

  2. #0

    This articlе will assist the internet viewers for creating new weblog or even a weblog from
    start to end.

    crypto exchange8个月前 (04-26)回复
  3. #0

    Hi, Neat post. There’s a problem along with your website in internet explorer, could test this?
    IE nonetheless is the market chief and a large element of people will miss your magnificent writing due
    to this problem.

  4. #0


    灰太狼2年前 (2020-10-22)回复
  5. #0


    风凉2年前 (2020-07-29)回复
    • 把Typecho一插件的样式照搬过来了

      zhuchunshu2年前 (2020-07-29)回复
      • ✗得意✗ 简约化好点撒

        风凉2年前 (2020-07-29)回复