空白网络

wordpress评论回复代码
//评论邮件通知 function comment_mail_notify($comment_id) { $com...
扫描右侧二维码阅读全文
11
2016/06

wordpress评论回复代码

//评论邮件通知
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_the_title($comment->comment_post_ID) . '] 的评论有回复啦 by:' . get_option('blogname') . '';
$message = '
<div id="isForwardContent"><div style="color:#555;font:12px/1.5 微软雅黑,Tahoma,Helvetica,Arial,sans-serif;none">
<table border="0" cellspacing="0" cellpadding="0">
</table>
<div>
<h2 style="border-bottom:1px solid #e9e9e9;font-size:14px;font-weight:normal;padding:10px 0 10px;"><span style="color: #12ADDB">&gt; </span>您在 <a style="text-decoration:none;color: #12ADDB;" href="' . get_option('home') . '" title="' . get_option('blogname') . '" target="_blank">' . get_option('blogname') . '</a> 中的留言有回复啦!</h2>
<div style="font-size:13px;color:#777;margin-top:18px">' . trim(get_comment($parent_id)->comment_author) . ' 同学,您曾在《 ' . get_the_title($comment->comment_post_ID) . ' 》中发表评论:

<p style="background-color: #f5f5f5;padding: 10px 15px;margin:18px 0">' . nl2br(get_comment($parent_id)->comment_content) . '</p>
<p>' . trim($comment->comment_author) . ' 给您的回复如下:</p>
<p style="background-color:#f5f5f5;padding: 10px 15px;margin:18px 0">' . nl2br($comment->comment_content) . '</p>
<p>您可以点击 <a style="text-decoration:none; color:#12addb" href="' . htmlspecialchars(get_comment_link($parent_id)) . '" title="单击查看完整的回复内容" target="_blank">查看完整的回复內容</a>,欢迎再次光临 <a style="text-decoration:none; color:#12addb" href="' . get_option('home') . '" title="' . get_option('blogname') . '" target="_blank">' . get_option('blogname') . '</a>!</p>
</div>
</div>
<div style="color:#D5D5D5;letter-spacing: 3px;font-size:14px;text-align:center;padding-top:0;padding-right:0;padding-bottom:0;padding-left:0;margin-top:15px;margin-right:0;margin-left:0;text-transform: uppercase;border-top: 1px solid rgba(0,0,0,.05);">欢迎来到:<a target="_blank" style="text-decoration:none;" href="' . get_option('home') . '/728"><span style="color:#D5D5D5;padding-bottom: 2px;border-bottom: 1px solid #D5D5D5;letter-spacing: 3px;font-size:14px;">空白网络</span></a></div>
</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 );
//echo 'mail to ', $to, '<br/> ' , $subject, $message; // for testing
}
}
add_action('comment_post', 'comment_mail_notify');

 


将上述代码全选复制粘贴到functions.php  也就是你的模板函数中

百度下wordpress开启邮箱功能的代码或者下载插件

插件名叫WP SMTP

就可以进行测试了。

Last modification:March 16th, 2017 at 09:38 pm
If you think my article is useful to you, please feel free to appreciate

Leave a Comment