php - 更换空间后wordpress 无法发送邮件?
PHP中文网
PHP中文网 2017-04-10 17:53:46
[PHP讨论组]
  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!’, 但是查看邮箱,仅收到香港服务器发送过来的邮件。

求大神指导!

PHP中文网
PHP中文网

认证0级讲师

全部回复(2)
伊谢尔伦

// 使用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发送邮件,是个不错的选择。

黄舟

这肯定和空间无关,你要先检查邮件服务器是否正常

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号