SMTP插件篇已经介绍完了,身为一个插件不爱好者,把插件代码话是我们折腾的目的!

很简单,话不多说直奔主题。

1、让wordpress支持SMTP方式来发送邮件。在主题文件的function.php加入以下文件

//smtp
add_action('phpmailer_init', 'mail_smtp');
function mail_smtp( $phpmailer ) {
$phpmailer->FromName = '歧路亡羊(v13)';
$phpmailer->Host = 'smtp.exmail.qq.com';
$phpmailer->Port = 465;
$phpmailer->Username = 'admin@v13.com';
$phpmailer->Password = '********';
$phpmailer->From = 'admin@v13.com';
$phpmailer->SMTPAuth = true;
$phpmailer->SMTPSecure = 'ssl'; //tls or ssl (port=25留空,465为ssl)
$phpmailer->IsSMTP();
}

这个时候我们的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 = 'webmaster@' . preg_replace('#^www.#', '', strtolower($_SERVER['SERVER_NAME']));
    $to = trim(get_comment($parent_id)->comment_author_email);
    $subject = '你在 [' . get_option("blogname") . '] 的留言有了回应';
    $message = '
    留言回复通知 | v7v3(维7维3)
  ' . 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) . '

 

你可以点击 查看回复完整内容

 

  感谢你对 ' . get_option('blogname') . ' 的关注,欢迎订阅本站

 

更多内容请:本站Q群 | 联系站长 | 投稿 | 投稿须知 | 关于我们 | 联系我们

歧路亡羊(wp.5v13.com)

'; $from = "From: "" . get_option('blogname') . "" <$wp_email>"; $headers = "$fromnContent-Type: text/html; charset=" . get_option('blog_charset') . "n"; wp_mail( $to, $subject, $message, $headers ); } } add_action('comment_post', 'comment_mail_notify');

这两段代码都是加在当前主题文件中的function.php函数里边的!然后保存试试看吧。

以上代码来自v7v3,修订于5v13,嘿嘿

发表回复

后才能评论