2014-09-02 157 views
1

我遇到了phpMailer的问题。它在本地主机上正常工作,但在将其上传到Web主机时会出现身份验证错误。用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 = '[email protected]';     // 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 = '[email protected]'; 
    $mail->FromName = 'my website name'; 
    //$mail->addAddress('[email protected]', 'Joe User');  // Add a recipient 
    $mail->addAddress('[email protected]');    // Name is optional 
    $mail->addReplyTo($email, $name); 
+0

这应该给你的失败原因的一个好主意:'SMTP错误:密码命令失败:535个不正确的认证数据2014年8月28日22:55:02' – 2014-09-02 06:38:13

+0

@欧莱雅L'L,则在本地主机上使用的相同的确切密码工作正常。它与网络托管服务器上的设置有关。 – Amzraptor 2014-09-02 06:45:40

+1

用于测试:您的密码不应包含特殊字符和变音符号。 – 2014-09-02 06:51:16

回答

0

我用这个代码和消息发送成功。

$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