WordPress无插件纯代码实现SMTP发送邮件替换php mail()发信方式

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

方法一、直接在function.php文件中添加以下密码

//使用smtp发邮件

add_action('phpmailer_init', 'mail_smtp');

function mail_smtp( $phpmailer ) {

$phpmailer->IsSMTP();

$phpmailer->SMTPAuth = true;//启用SMTPAuth服务

$phpmailer->Port = 465; //SMTP邮件发送端口,常用端口有:25、465和587(后两个为ssl安全连接端口)。

$phpmailer->SMTPSecure ="ssl"; //是否通过 ssl 连接,如果端口为25,则此处将"ssl"改为空白即"",否则不必改动

$phpmailer->Host = "smtp.gmail.com"; // SMTP服务器地址,在邮箱设置或者帮助中心中可以找到

$phpmailer->Username = "[email protected]"; //你的邮箱地址

$phpmailer->Password ="******"; //你的邮箱登陆密码

}

方法二、修改WordPress核心程序,但升级后需要重新修改
在WordPress的wp-includes目录下找到pluggable.php和class-phpmailer.php两个文件。

将pluggable.php中的”$phpmailer->IsMail(); “替换为:”$phpmailer->IsSMTP();”

在class-phpmailer.php中修改下面对应的设置:

public $Mailer = 'smtp';
public $Host = 'smtp.gmail.com'; //邮箱的SMTP服务器地址
public $Port = 465; //SMTP邮件发送端口
public $SMTPSecure = "ssl"; //是否验证 ssl或tls
public $SMTPAuth = true; //开启SMTPAuth
public $Username = '[email protected]'; //你的邮箱地址
public $Password = '******'; //你的邮箱登陆密码

2 thoughts on “WordPress无插件纯代码实现SMTP发送邮件替换php mail()发信方式

Leave a Comment