【问题标题】:Sending mail with phpMailer but works on localhost使用 phpMailer 发送邮件但在本地主机上工作
【发布时间】:2014-09-02 06:31:35
【问题描述】:

我遇到了 phpMailer 的问题。它在本地主机上运行良好,但当我将其上传到网络主机时会出现身份验证错误。

“客户:535 验证数据不正确”

设置为 smtp.gmail.com,端口 587,使用 TLS 加密,如 http://email.about.com/od/accessinggmail/f/Gmail_SMTP_Settings.htm 所述

我用 www.mywebsiteaddress.com 替换了真实的网站地址。

这里:

2014-08-28 22:55:00 SERVER -> CLIENT: 220-lp.linkdatacenter.net ESMTP Exim 4.82 #2 Thu, 28 Aug 2014 22:55:00 +0000 220-We do not authorize the use of this system to transport unsolicited, 220 and/or bulk e-mail.
2014-08-28 22:55:00 CLIENT -> SERVER: EHLO www.mywebsiteaddress.com
2014-08-28 22:55:00 SERVER -> CLIENT: 250-lp.linkdatacenter.net Hello sigmaengco.com [213.131.64.210] 250-SIZE 52428800 250-8BITMIME 250-PIPELINING 250-AUTH PLAIN LOGIN 250-STARTTLS 250 HELP
2014-08-28 22:55:00 CLIENT -> SERVER: STARTTLS
2014-08-28 22:55:00 SERVER -> CLIENT: 220 TLS go ahead
2014-08-28 22:55:00 CLIENT -> SERVER: EHLO www.mywebsiteaddress.com
2014-08-28 22:55:00 SERVER -> CLIENT: 250-lp.linkdatacenter.net Hello sigmaengco.com [213.131.64.210] 250-SIZE 52428800 250-8BITMIME 250-PIPELINING 250-AUTH PLAIN LOGIN 250 HELP 2014-08-28 22:55:00 CLIENT -> SERVER: AUTH LOGIN
2014-08-28 22:55:00 SERVER -> CLIENT: 334 VXNlcm5hbWU6
2014-08-28 22:55:00 CLIENT -> SERVER: bGl0dGxlcGVhcmxzY2VudGVyQGdtYWlsLmNvbQ==
2014-08-28 22:55:00 SERVER -> CLIENT: 334 UGFzc3dvcmQ6
2014-08-28 22:55:00 CLIENT -> SERVER: dXRvcGlhdXRvcGlh
2014-08-28 22:55:02 SERVER -> CLIENT: 535 Incorrect authentication data
2014-08-28 22:55:02 SMTP ERROR: Password command failed: 535 Incorrect authentication data
2014-08-28 22:55:02 CLIENT -> SERVER: QUIT
2014-08-28 22:55:02 SERVER -> CLIENT: 221 lp.linkdatacenter.net closing connection
SMTP connect() failed. Message could not be sent.Mailer Error: SMTP connect() failed.

这里是相关部分的代码,我把真实信息换成了假信息。

    require_once('PHPMailer-master/PHPMailerAutoload.php');

    $mail = new PHPMailer;

    $mail->isSMTP();                                      // Set mailer to use SMTP
    $mail->Host = 'smtp.gmail.com';                     // Specify main and backup SMTP servers
    $mail->SMTPDebug  = 2;
    $mail->SMTPAuth = true;                               // Enable SMTP authentication
    $mail->Username = 'myemail@gmail.com';                 // SMTP username
    $mail->Password = 'mypassword';                           // SMTP password
    $mail->SMTPSecure = 'tls';                            // Enable encryption, 'ssl' also accepted
    $mail->Port = 587;                                  // set the SMTP port for the GMAIL 
    $mail->From = 'myemail@gmail.com';
    $mail->FromName = 'my website name';
    //$mail->addAddress('joe@example.net', 'Joe User');     // Add a recipient
    $mail->addAddress('myotheremail@yahoo.com');               // Name is optional
    $mail->addReplyTo($email, $name);

【问题讨论】:

  • 这应该可以让您很好地了解失败的原因:SMTP ERROR: Password command failed: 535 Incorrect authentication data 2014-08-28 22:55:02
  • @l'L'l 它与本地主机上使用的完全相同的密码可以正常工作。它与网络托管服务器上的设置有关。
  • 用于测试:您的密码不应包含特殊字符和变音符号。
  • @FranzHolzinger 密码只能由字母组成。
  • 如果您请求smtp.gmail.com,但最终连接到lp.linkdatacenter.net(即不是谷歌),您的DNS 被欺骗,或者他们的防火墙将您重定向到其他地方。无论哪种方式都不好。

标签: php localhost phpmailer web-hosting


【解决方案1】:

我使用了这个代码并且消息发送成功。

$mail->IsSMTP();
$mail->SMTPAuth = true;
$mail->Host = "mail.mysite.com"; //email account on my hosting
$mail->Port = 25; // port on non ssl-setting
$mail->Username = "myusername";  //username to log into hosting
$mail->Password = "mypassword";  //password to log into hosting

【讨论】:

    猜你喜欢
    • 2020-02-07
    • 2014-03-26
    • 2015-04-15
    • 1970-01-01
    • 2018-02-20
    • 2012-03-18
    • 1970-01-01
    • 1970-01-01
    • 2016-08-25
    相关资源
    最近更新 更多