朱纯树博客
VPS测评推荐网站
cloudacead cloudacead

wordpress评论回复自动邮件提醒

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

我只是改了改邮件内容样式

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

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

首先将下面代码修改后复制到functions.PHP文件,再测试发送邮件功能。


//评论回复邮件

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']));
//发件人e-mail地址

$to = trim(get_comment($parent_id)->comment_author_email);
$subject = '您在 [' . get_option("blogname") . '] 的留言有了回应';
$content='
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
</head>
<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>
    <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>
        <div style="line-height:40px;  font-size:14px;">
            <label style="color:#999;">评论人:</label>
            <span style="color:#333;">'.trim($comment->comment_author).' </span>
        </div>
        <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>
        <div style="line-height:40px;  font-size:14px;">
            <label style="color:#999;">评论时间:</label>
            <span style="color:#333;">'.trim($comment->comment_date).'</span>
        </div>
        <div style="line-height:40px;  font-size:14px;">
            <label style="color:#999;">PS:</label>
            <span style="color:#333;">请不要回复此邮件,此邮件来自博客自动发送</span>
        </div>
    </div>
</div>
</body>
</html>
';

$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评论回复自动邮件提醒

评论 9

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

    Great post. I was checking constantly this blog and I’m impressed! Extremely helpful information specially the last part 🙂 I care for such information much. I was seeking this particular information for a very long time. Thank you and best of luck. ラ ブ ド ー ル

  2. #0

    Pretty component to content. I simply stumbled upon your blog and in accession capital to say that I get actually loved account your weblog posts. Anyway I?ll be subscribing on your augment or even I success you get right of entry to persistently rapidly.

  3. #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
    work!

    sing movie online free10个月前 (05-30)回复
  4. #0

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

    crypto exchange11个月前 (04-26)回复
  5. #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.

    houston junk car buyer11个月前 (04-23)回复
  6. #0

    受教了。。。

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

    看看你的美化咋样?

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

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

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