方法一:使用插件
使用Configure SMTP或者WP Mail SMTP插件。
方法二:在主题functions.php中添加代码
functionmail_smtp($phpmailer){$phpmailer->IsSMTP();$phpmailer->SMTPAuth=true;//启用SMTPAuth服务$phpmailer->Port=465;//SMTP邮件发送端口,这个和下面的对应,如果这里填写25,则下面为空白$phpmailer->SMTPSecure="ssl";//是否验证 ssl,这个和上面的对应,如果不填写,则上面的端口须为25$phpmailer->Host="smtp.163.com";//邮箱的SMTP服务器地址,如果是QQ的则为:smtp.exmail.qq.com$phpmailer->Username="*****@163.com";//邮箱地址$phpmailer->PassWord="*******";//邮箱密码}add_action('phpmailer_init','mail_smtp');
以后邮件回复设置中的变量wp_email要和上面的Username一致。
方法三:修改wp-includes目录下的pluggable.php和class-phpmailer.php文件(仅适用于WP3.0以上版本)
(1) 在pluggable.php中搜索如下代码
$phpmailer->IsMail();
替换为:
$phpmailer->IsSMTP();
(2) 在class-phpmailer.php中配置如下信息:
var$Mailer='smtp';var$Host='smtp.163.com';//邮箱的SMTP服务器地址var$Port=465;//SMTP邮件发送端口。一般默认为25,示例用的是465$SMTPSecure="ssl";//是否验证ssl$SMTPAuth=true;//开启SMTP$Username='xxxx@163.com';//邮箱地址var$Password='******';//邮箱密码
原文地址:http://boliquan.com/use-smtp-instead-of-mail/