* @license GPL-3.0 License
* @version 2022.04.29
*/
if (kratos_option('m_smtp', false)) {
function mail_smtp($phpmailer)
{
$phpmailer->isSMTP();
$phpmailer->SMTPAuth = true;
$phpmailer->CharSet = "utf-8";
$phpmailer->SMTPSecure = kratos_option('m_sec');
$phpmailer->Port = kratos_option('m_port');
$phpmailer->Host = kratos_option('m_host');
$phpmailer->From = kratos_option('m_username');
$phpmailer->Username = kratos_option('m_username');
$phpmailer->Password = kratos_option('m_passwd');
}
add_action('phpmailer_init', 'mail_smtp');
}
// Debug
function wp_mail_debug($wp_error)
{
return error_log(print_r($wp_error, true));
}
// add_action('wp_mail_failed', 'wp_mail_debug', 10, 1);
function comment_approved($comment)
{
if (is_email($comment->comment_author_email)) {
$wp_email = kratos_option('m_username');
$to = trim($comment->comment_author_email);
$post_link = get_permalink($comment->comment_post_ID);
$subject = __('[通知]您的留言已经通过审核', 'kratos');
$message = '
' . __('您好,', 'kratos') . trim($comment->comment_author) . ':
' . __('您的留言已经通过了管理员的审核,摘要信息如下:', 'kratos') . '
' . __('文章', 'kratos') . ' |
' . __('内容', 'kratos') . ' |
' . __('操作', 'kratos') . ' |
《' . get_the_title($comment->comment_post_ID) . '》 |
' . trim($comment->comment_content) . ' |
查看留言 |
' . __('该邮件由系统自动发出,如果不是您本人操作,请忽略此邮件。', 'kratos') . '
' . htmlspecialchars_decode(get_option('blogname'), ENT_QUOTES) . '
' . wp_date("Y年m月d日", time()) . '
';
$from = "From: \"" . htmlspecialchars_decode(get_option('blogname'), ENT_QUOTES) . "\" <$wp_email>";
$headers = "$from\nContent-Type: text/html; charset=" . get_option('blog_charset') . "\n";
wp_mail($to, $subject, $message, $headers);
}
}
add_action('comment_unapproved_to_approved', 'comment_approved');
function comment_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 == '1')) {
$wp_email = kratos_option('m_username');
$to = trim(get_comment($parent_id)->comment_author_email);
$subject = __('[通知]您的留言有了新的回复', 'kratos');
$message = '
' . __('您好,', 'kratos') . trim(get_comment($parent_id)->comment_author) . ':
' . __('您的留言有了新的回复,摘要信息如下:', 'kratos') . '
' . __('原文', 'kratos') . ' |
' . __('回复', 'kratos') . ' |
' . __('作者', 'kratos') . ' |
' . __('操作', 'kratos') . ' |
' . trim(get_comment($parent_id)->comment_content) . ' |
' . trim($comment->comment_content) . ' |
' . trim($comment->comment_author) . ' |
' . __('查看回复', 'kratos') . ' |
' . __('该邮件由系统自动发出,如果不是您本人操作,请忽略此邮件。', 'kratos') . '
' . htmlspecialchars_decode(get_option('blogname'), ENT_QUOTES) . '
' . wp_date("Y年m月d日", time()) . '
';
$from = "From: \"" . htmlspecialchars_decode(get_option('blogname'), ENT_QUOTES) . "\" <$wp_email>";
$headers = "$from\nContent-Type: text/html; charset=" . get_option('blog_charset') . "\n";
wp_mail($to, $subject, $message, $headers);
}
}
add_action('comment_post', 'comment_notify');
add_action('comment_unapproved_to_approved', 'comment_notify');