WordPress教程 简洁清新评论回复邮件模板

给自己的WordPress添加一个简洁的评论回复邮件模板,让用户收到来自你网站的回复邮件通知的时候也感受到你的小清新。废话不多了开始动手
把下面代码放到functions.php里,?>之前,(P.S. 如果之前有评论回复邮件的话,就把它覆盖掉)

//评论回复邮件   
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") . '] 的留言有了回應';   
$message = '> 您在 ' . get_option('blogname') . ' 博客上的留言有回复啦!' . trim(get_comment($parent_id)->comment_author) . ' 同学,您曾在文章《' . get_the_title($comment->comment_post_ID) . '》上发表评论:' . nl2br(get_comment($parent_id)->comment_content) . '' . trim($comment->comment_author) . '  给您的回复如下:' . nl2br($comment->comment_content) . '您可以点击 查看回复的完整內容 ,欢迎再次光临 ' . get_option('blogname') . ' 。';   
$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, ' ' , $subject, $message; // for testing   
}   
}   
add_action('comment_post', 'comment_mail_notify');

感谢您的观看,对您有用就分享出去吧 !

© 版权声明
THE END
喜欢就支持一下吧
点赞12 分享
评论 抢沙发

请登录后发表评论

    暂无评论内容