php - 更换空间后wordpress 无法发送邮件?

查看:114
本文介绍了php - 更换空间后wordpress 无法发送邮件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问 题

  1. 问题描述

题主公司由于业务需要,将公司网站(基于wordpress开发)从香港服务器迁移至国内服务器,
服务器环境由题主自己搭建,与香港服务器相同。迁移后,发现用户无法接受到邮件,自己尝试发邮件给自己,虽然提示成功,但还是无法收到邮件。

  1. 代码

       <?php 
       

    $to = 'xxxx@qq .com';
    $subject = 'The subject';
    $body = 'The email body content';

    //wp_mail, 发送邮件的函数,返回布尔值
    $mail = wp_mail( $to, $subject, $body);

    if (!$mail)

    {
            global $ts_mail_errors;
            global $phpmailer;
                if (!isset($ts_mail_errors)) 
                    $ts_mail_errors = array();
                if (isset($phpmailer)) 
                {
                $ts_mail_errors[] = $phpmailer->ErrorInfo;
                print_r($ts_mail_errors);
                }
     }
    else echo 'email was sent!';
    

    ?>

  2. 此段代码,在香港服务器上,和国内服务器上,都输出‘email was sent!’, 但是查看邮箱,仅收到香港服务器发送过来的邮件。

求大神指导!

解决方案

// 使用SMTP发送邮件
function mail_smtp( $phpmailer ){
$phpmailer->From = "xxx@example .com"; //发件人
$phpmailer->FromName = "xxx"; //发件人昵称
$phpmailer->Host = "smtp.exmail.qq.com"; //SMTP服务器地址
$phpmailer->Port = 465; //SMTP端口
$phpmailer->SMTPSecure = "ssl"; //SMTP加密方式,常用的有ssl/tls,一般25端口不填,端口465天ssl
$phpmailer->Username = "xxx@example .com"; //邮箱帐号,一般和发件人相同
$phpmailer->Password = 'xxx'; //邮箱密码
$phpmailer->IsSMTP(); //使用SMTP发送
$phpmailer->SMTPAuth = true; //启用SMTPAuth服务
}
add_action('phpmailer_init','mail_smtp');

查看了邮件的日志,其实不是发送不出去,是被拒收了。由于mail()函数很容易被拒收,或者打到垃圾箱,采用SMTP发送邮件,是个不错的选择。

这篇关于php - 更换空间后wordpress 无法发送邮件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆