12行纯代码实现wordpress SMTP发信(最简单版)

作者: 站长 上传时间: 浏览: N/A 下载: N/A 格式: N/A 评分: N/A

1、去QQ或163邮箱,开通SMTP发信权限


2、获取密匙


3、主题的function.php文件加入以下代码(以下以QQ邮箱的SMTP发信为例)

//使用smtp发送邮件(请根据自己使用的邮箱设置SMTP)
add_action('phpmailer_init', 'mail_smtp');
function mail_smtp( $phpmailer ) {
$phpmailer-> FromName = '某某某'; //发件人
$phpmailer-> Host = 'smtp.qq.com'; //修改为你使用的SMTP服务器
$phpmailer-> Port = 465; //SMTP端口,开启了SSL加密
$phpmailer-> Username = '[email protected]'; //邮箱账户(你邮箱地址)
$phpmailer-> Password = 'xxxxx'; //输入密匙(开通SMTP发信后,可以获取密匙)
$phpmailer-> From = '[email protected]'; //对方接收邮件时,显示的邮箱地址(一般填你自己的邮箱地址)
$phpmailer-> SMTPAuth = true;
$phpmailer-> SMTPSecure = 'ssl'; //tls or ssl (port=25留空,465则填写ssl)
$phpmailer-> IsSMTP();
}

Leave a Comment