在主题functions.php里添加以下代码:
add_action( 'phpmailer_init', 'qiangwai_phpmailer' );
function qiangwai_phpmailer($phpmailer)
{
$phpmailer->isSMTP();
$phpmailer->Host = 'smtp.gmail.com';
$phpmailer->SMTPAuth = true; // Force it to use Username and Password to authenticate
$phpmailer->Port = 465;
$phpmailer->Username = '';
$phpmailer->Password = '';
$phpmailer->SMTPSecure = "ssl"; // Choose SSL or TLS, if necessary for your server
//$phpmailer->From = "[email protected]";
//$phpmailer->FromName = "youname";
}
注意,有可能会出现失败的情况,提示说 主机不支持mail()函数,其实是谷歌账号保护导致无法使用smtp服务。
解决方法是进谷歌的账号 安全性,启用弱应用的账户访问权限。