Maison  >  Article  >  développement back-end  >  更换空间后wordpress 无法发送邮件?

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

WBOY
WBOYoriginal
2016-12-01 00:25:561873parcourir

  1. 问题描述

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

  1. 代码

    <code>   <?php </code></code>

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

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

    if (!$mail)

    <code>{
            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!';
    </code>

    ?>

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

求大神指导!

回复内容:

  1. 问题描述

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

  1. 代码

    <code>   <?php </code></code>

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

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

    if (!$mail)

    <code>{
            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!';
    </code>

    ?>

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

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

Déclaration:
Le contenu de cet article est volontairement contribué par les internautes et les droits d'auteur appartiennent à l'auteur original. Ce site n'assume aucune responsabilité légale correspondante. Si vous trouvez un contenu suspecté de plagiat ou de contrefaçon, veuillez contacter admin@php.cn