添加到你主题的functions.php里面。
先添加:
- //使用smtp发送邮件(请根据自己使用的邮箱设置SMTP)
- add_action('phpmailer_init', 'mail_smtp');
- function mail_smtp( $phpmailer ) {
- $phpmailer->FromName = '流年博客'; //发件人名称
- $phpmailer->Host = 'smtp.qq.com'; //修改为你使用的邮箱SMTP服务器
- $phpmailer->Port = 465; //SMTP端口
- $phpmailer->Username = '912027733@qq.com'; //邮箱账户
- $phpmailer->Password = 'mefgspbpbeia'; //邮箱密码
- $phpmailer->From = '912027733@qq.com'; //邮箱账户
- $phpmailer->SMTPAuth = true;
- $phpmailer->SMTPSecure = 'ssl'; //tls or ssl (port=25时->留空,465时->ssl)
- $phpmailer->IsSMTP();
- }
以上代码请把邮箱账户,密码什么的都换成自己的。
再添加:
- 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 = '912027733@qq.com';
- $to = trim(get_comment($parent_id)->comment_author_email);
- $subject = '您在 [' . get_option("blogname") . '] 网站的留言有了回复';
- $message = '
- <div style="background-color:#fff; border:1px solid #666666; color:#111; -moz-border-radius:8px; -webkit-border-radius:8px; -khtml-border-radius:8px; border-radius:8px; font-size:14px;font-family:微软雅黑; width:702px; margin:0 auto; margin-top:10px;">
- <div style="background:#5990de; width:100%; height:60px; color:white; -moz-border-radius:6px 6px 0 0; -webkit-border-radius:6px 6px 0 0; -khtml-border-radius:6px 6px 0 0; border-radius:6px 6px 0 0; ">
- <span style="height:60px; line-height:60px; margin-left:30px; font-size:16px;"> 您在<a style="text-decoration:none; color:#ff0;font-weight:600;"> [' . get_option("blogname") . '] </a>上的留言有回复啦!</span></div>
- <div style="width:90%; margin:0 auto">
- <p>' . trim(get_comment($parent_id)->comment_author) . ', 您好!</p>
- <p>您在《' . get_the_title($comment->comment_post_ID) . '》的留言:<br />
- <p style="background-color: #EEE;border: 1px solid #DDD;padding: 20px;margin: 15px 0;">'. trim(get_comment($parent_id)->comment_content) . '</p>
- <p>' . trim($comment->comment_author) . ' 给你的回复:<br />
- <p style="background-color: #EEE;border: 1px solid #DDD;padding: 20px;margin: 15px 0;">'. trim($comment->comment_content) . '</p>
- <p>你可以点击<a href="' . htmlspecialchars(get_comment_link($parent_id, array('type' => 'comment'))) . '">查看完整内容</a></p>
- <p>欢迎再次光临<a href="' . get_option('home') . '">' . get_option('blogname') . '</a>哦!</p>
- <p>(此邮件由系统自动发出, 请勿回复。)</p>
- </div></div>';
- $from = "From: \"" . get_option('blogname') . "\" <$wp_email>";
- $headers = "$from\nContent-Type: text/html; charset=" . get_option('blog_charset') . "\n";
- wp_mail( $to, $subject, $message, $headers );
- }
- }
- add_action('comment_post', 'comment_mail_notify');
这是通过本人美化以后的,邮件样式,具体样式如下。如果你不喜欢。可以自己更改CSS达到自己满意的效果。
生命在于折腾。
河北省石家庄市 2F
学习了。
浙江省金华市东阳市 1F
很不错的美化。。。