直接把下面的代码扔到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 发出点, no-reply 可改为可用的 e-mail. $to = trim(get_comment($parent_id)->comment_author_email); $subject = '您在 [' . get_option("blogname") . '] 的留言有了回复'; $message = ' <div style="background-color:#eef2fa; border:1px solid #d8e3e8; color:#111; padding:0 15px; -moz-border-radius:5px; -webkit-border-radius:5px; -khtml-border-radius:5px;"> <p>' . trim(get_comment($parent_id)->comment_author) . ', 您好!</p> <p>您曾在《' . get_the_title($comment->comment_post_ID) . '》的留言:<br /> <span style="font-weight:bold;">' . trim(get_comment($parent_id)->comment_content) . '</span></p> <p>-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-</p> <p>' . trim($comment->comment_author) . ' 给您的回复:<br /> <span style="font-weight:bold;">' . trim($comment->comment_content) . '</span><br /></p> <p>您可以点击 <a href="' . htmlspecialchars(get_comment_link($parent_id, array('type' => 'comment'))) . '">查看回复完整內容</a></p> <p>-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-</p> <p style="color:#ff0000;">請勿回復本郵件,您的回復我無法收到.如果您有問題,請到 <a href="' . get_option('home') . '">' . get_option('blogname') . '</a> 給我留言.</p> </div>'; $message = convert_smilies($message); $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 ); //echo 'mail to ', $to, '<br/> ' , $subject, $message; // for testing } } add_action('comment_post', 'comment_mail_notify');
以上是邮件的默认样式,下面是美化代码,把下面内容替换上面$message = ‘到$message = convert_smilies($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:12px; width:702px; margin:0 auto; margin-top:10px; font-family:微软雅黑, Arial;"> <div style="background:#666666; 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:12px;"> 您在<a style="text-decoration:none; color:#00bbff;font-weight:600;" href="' . get_option('home') . '">' . get_option('blogname') . ' </a>博客上的留言有回复啦!</span></div> <div style="width:90%; margin:0 auto"> <p>' . trim(get_comment($parent_id)->comment_author) . ', 您好!</p> <p>您曾在 [' . get_option("blogname") . '] 的文章 《' . get_the_title($comment->comment_post_ID) . '》 上发表评论: <p style="background-color: #EEE;border: 1px solid #DDD; padding: 20px;margin: 15px 0;">' . nl2br(get_comment($parent_id)->comment_content) . '</p> <p>' . trim($comment->comment_author) . ' 给您的回复如下: <p style="background-color: #EEE;border: 1px solid #DDD;padding: 20px; margin: 15px 0;">' . nl2br($comment->comment_content) . '</p> <p>您可以点击 <a style="text-decoration:none; color:#00bbff" href="' . htmlspecialchars(get_comment_link($parent_id)) . '">查看回复的完整內容</a></p> <p>欢迎再次光临 <a style="text-decoration:none; color:#00bbff" href="' . get_option('home') . '">' . get_option('blogname') . '</a></p> <p>(此邮件由系统自动发出, 请勿回复.)</p> </div> </div>';
下面是美化后的样子,是不是很熟悉,很多人在用,你可以自己修改下,让它更美观!