当前位置:秋硕笔记 > 记录 > 正文

wordpress添加留言邮件回复功能

直接贴代码了,放到主题文件夹下的functions.php。

/*
* 评论邮件回复
*/
function yz_comment_mail_notify($comment_id){
$mail_user_name = akina_option('mail_user_name') ? akina_option('mail_user_name') : 'poi';
$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 = $mail_user_name . '@' . preg_replace('#^www\.#', '', strtolower($_SERVER['SERVER_NAME']));
$to = trim(get_comment($parent_id)->comment_author_email);
$subject = '你在 [' . get_option("blogname") . '] 的留言有了回应';
$message = '

'. get_option("blogname") .'您有一条来自 ' . get_option("blogname") . ' 的回复

' . trim(get_comment($parent_id)->comment_author) . ', 你好!

你在《' . get_the_title($comment->comment_post_ID) . '》的留言:

'
. trim(get_comment($parent_id)->comment_content) . '

' . trim($comment->comment_author) . ' 给你的回复:

'
. trim($comment->comment_content) . '

点击查看完整内容
Copyright © '.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 );
}
}
add_action('comment_post', 'yz_comment_mail_notify');

感觉很棒!可以赞赏支持我哟~

赞(0) 打赏

评论抢沙发