无插件实现回复自动邮件回复

下面的代码放在主题文件夹中functions.php文件中的<?php ….. ?>区域内,下面的代码已经经过测试,你只需要更改其中的邮件信息即可。

 

 

/* comment_mail_notify v1.0 by willin kan. (有勾选栏,由访客自己决定) */
function comment_mail_notify($comment_id) {
$admin_notify = '1'; { admin 要不要收回覆通知 ( '1'=要 ; '0'=不要 )}
$admin_email = get_bloginfo ('admin_email'); ( $admin_email 可改為你指定的 e-mail. 这项可以不用设置,因为一般wp都已经开了回复自动邮件通知博主的)
$comment = get_comment($comment_id);
$comment_author_email = trim($comment->comment_author_email);
$parent_id = $comment->comment_parent ? $comment->comment_parent : '';
global $wpdb;
if ($wpdb->query("Describe {$wpdb->comments} comment_mail_notify") == '')
$wpdb->query("ALTER TABLE {$wpdb->comments} ADD COLUMN comment_mail_notify TINYINT NOT NULL DEFAULT 0;");
if (($comment_author_email != $admin_email && isset($_POST['comment_mail_notify'])) || ($comment_author_email == $admin_email && $admin_notify == '1'))
$wpdb->query("UPDATE {$wpdb->comments} SET comment_mail_notify='1' WHERE comment_ID='$comment_id'");
$notify = $parent_id ? get_comment($parent_id)->comment_mail_notify : '0';
$spam_confirmed = $comment->comment_approved;
if ($parent_id != '' && $spam_confirmed != 'spam' && $notify == '1') {
$wp_email = 'lin@' . preg_replace('#^www.#', '', strtolower($_SERVER['SERVER_NAME'])); // e-mail 發出點, no-reply 可改為可用的 e-mail.
$to = trim(get_comment($parent_id)->comment_author_email);
$subject = 'Your comment on [' . get_option("blogname") . '] just been replied by ' . trim($comment->comment_author) . ' ';
$message = '
<p>Hello,' . trim(get_comment($parent_id)->comment_author) . '.<br/>
您在 "<strong>' . get_the_title($comment->comment_post_ID) . '</strong>" 的评论,刚刚被 <strong>' . trim($comment->comment_author) . ' </strong>回复了.您想现在去查看吗?<br/>
<div style="margin:5px;padding:5px;border:1px solid #eee;background-color:#f8f8f8;color:#aaa;">您的评论:<br />'. trim(get_comment($parent_id)->comment_content) . '<br /></div>
<div style="margin-left:5px;margin-right:5px;padding:5px;border:1px solid #ccc;background-color:#f2f2f2;color:#333;">新的回复:<br />'. trim($comment->comment_content) . '</div>
<div style="margin-top:10px;padding-bottom:10px;border-bottom:1px solid #ccc;">
<a href="' . htmlspecialchars(get_comment_link($parent_id, array('type' => 'comment'))) . '">查看</a>,或者点击<a href="mailto:lin@blueandhack.com">回复博主</a> 给博主回复邮件.</div>
<div style="font-style:italic;margin-top:5px;">[DO Not reply this mail]</div>
<p><a href="' . get_option('home') . '">' . get_option('blogname') . '</a>.欢迎 <a href="http://feed.xiaw.top">订阅</a>.<br/>
</div>';
$from = "From: "" . get_option('blogname') . "" <$wp_email>";
$headers = "$fromnContent-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');

/* 自動加勾選欄 */
function add_checkbox() {
echo '<input type="checkbox" name="comment_mail_notify" id="comment_mail_notify" value="comment_mail_notify" checked="checked" style="margin-left:20px;" /><label for="comment_mail_notify">有人回复时通知我(默认勾选)</label>';
}
add_action('comment_form', 'add_checkbox');

// -- END ----------------------------------------

版权声明:
作者:珍惜
链接:https://xiaw.top/397.html
来源:生活回忆
文章版权归作者所有,未经允许请勿转载。

THE END
分享
二维码
< <上一篇
下一篇>>