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) . '》的留言: 你可以点击 查看回复完整内容 感谢你对 ' . get_option('blogname') . ' 的关注,欢迎订阅本站! |
这两段代码都是加在当前主题文件中的function.php函数里边的!然后保存试试看吧。
以上代码来自v7v3,修订于5v13,嘿嘿
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。
评论(0)