我遇到了phpMailer的问题。它在localhost上运行正常,但在我将其上传到Web主机时会出现身份验证错误。
“客户端: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);
答案 0 :(得分: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