WordPress教程 · WPtech

WordPress代码实现无需插件启用邮件评论

小编 · 10月22日 · 2019年 ·

很多网站都有评论邮件提醒功能,这样不仅可以提高用户回站的机率,还可以让评论者第一时间知道所评论内容的最新情况,一举两得。为 wordpress 添加评论回复邮件提醒功能很多人已经了解过,这个功能可以使用插件来实现,但我们一贯遵循“能用代码就用代码”的原则。本文将介绍下“免插件仅代码添加评论邮件提醒的几种实现方法以及我所推荐的清新邮件模版”。

WordPress代码实现无需插件启用邮件评论-字节智造

将以下代码添加至functions.php文件当中

//邮件提醒
add_action('phpmailer_init', 'mail_smtp');
function mail_smtp( $phpmailer ) {
	$phpmailer->FromName = '踏雕上月博客'; //发件人名称
	$phpmailer->Host = 'smtp.qq.com'; //修改为你使用的邮箱SMTP服务器
	$phpmailer->Port = 465; //SMTP端口
	$phpmailer->Username = 'xxxxx@qq.com'; //邮箱账户
	$phpmailer->Password = 'xxxxxxxxxxxxxxxx'; //授权码(此处填写QQ邮箱生成的授权码)
	$phpmailer->From = 'xxxxxxx@qq.com'; //邮箱账户
	$phpmailer->SMTPAuth = true;
	$phpmailer->SMTPSecure = 'ssl'; //tls or ssl (port=25时->留空,465时->ssl)
	$phpmailer->IsSMTP();
}

授权码获取截图

WordPress代码实现无需插件启用邮件评论-字节智造

完成,自行测试

0 条回应

必须 注册 为本站用户, 登录 后才可以发表评论!