PhpMailer SMTP 错误用户名命令失败:535 5.7.8



PHPMailer 5.2 一直告诉我,我无法发送电子邮件。

我知道凭据是正确的(Firefox检查电子邮件,laravel发送电子邮件(。

我缺少哪个设置/命令?

PHP代码:

$mail->isSMTP();
$mail->Host = ******;
$mail->SMTPAuth = true;
$mail->Username = ******;
$mail->Password = ******;
$mail->SMTPSecure = false;
$mail->Port = 25;
$mail->SMTPDebug  = 3;
$mail->SMTPOptions = [
    'ssl' => [
        'verify_peer' => false,
        'verify_peer_name' => false,
        'allow_self_signed' => true
    ]
];

SMTP调试:

2017-03-22 19:06:14 Connection: opening to *************:25, timeout=300, options=array (
                                        'ssl' =>
                                        array (
                                          'verify_peer' => false,
                                          'verify_peer_name' => false,
                                          'allow_self_signed' => true,
                                        ),
                                      )
2017-03-22 19:06:14 Connection: opened
2017-03-22 19:06:14 SERVER -> CLIENT: 220 ************* ESMTP Postfix
2017-03-22 19:06:14 CLIENT -> SERVER: EHLO *******
2017-03-22 19:06:14 SERVER -> CLIENT: 250-*************
                                      250-PIPELINING
                                      250-SIZE 15728640
                                      250-ETRN
                                      250-STARTTLS
                                      250-AUTH PLAIN LOGIN CRAM-MD5
                                      250-AUTH=PLAIN LOGIN CRAM-MD5
                                      250-ENHANCEDSTATUSCODES
                                      250-8BITMIME
                                      250 DSN
2017-03-22 19:06:14 CLIENT -> SERVER: STARTTLS
2017-03-22 19:06:14 SERVER -> CLIENT: 220 2.0.0 Ready to start TLS
2017-03-22 19:06:14 CLIENT -> SERVER: EHLO *******
2017-03-22 19:06:14 SERVER -> CLIENT: 250-*************
                                      250-PIPELINING
                                      250-SIZE 15728640
                                      250-ETRN
                                      250-AUTH PLAIN LOGIN CRAM-MD5
                                      250-AUTH=PLAIN LOGIN CRAM-MD5
                                      250-ENHANCEDSTATUSCODES
                                      250-8BITMIME
                                      250 DSN
2017-03-22 19:06:14 CLIENT -> SERVER: AUTH CRAM-MD5
2017-03-22 19:06:14 SERVER -> CLIENT: 334 ***********************************
2017-03-22 19:06:14 CLIENT -> SERVER: **************************************
2017-03-22 19:06:16 SERVER -> CLIENT: 535 5.7.8 Error: authentication failed: ***********************************
2017-03-22 19:06:16 SMTP ERROR: Username command failed: 535 5.7.8 Error: authentication failed: ***********************************
2017-03-22 19:06:16 SMTP Error: Could not authenticate.
2017-03-22 19:06:16 CLIENT -> SERVER: QUIT
2017-03-22 19:06:16 SERVER -> CLIENT: 221 2.0.0 Bye
2017-03-22 19:06:16 Connection: closed
2017-03-22 19:06:16 SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting

AuthType 应该可以解决您的问题:

$mail->AuthType = 'LOGIN';

其他选项包括:普通、登录、NTLM、CRAM-MD5 XOAUTH2

https://phpmailer.github.io/PHPMailer/classes/SMTP.html#method_authenticate

我不知道缺少哪些命令,但我的建议是使用 swift mailer 而不是 php mailer。以下代码对于使用 Swift 邮件程序发送邮件很有用。您可以从以下链接下载 swift 邮件库,并确保下载 swift 5.0.1。

http://swiftmailer.org/downloads/archive

<?php
require_once 'Swift-5.0.1/lib/swift_required.php';
// Grab the Data
$emailc=$emailid;
 $name=filter_var(''.$name1.'',FILTER_SANITIZE_STRING);
  $uname1=filter_var(''.$uname.'',FILTER_SANITIZE_STRING);
   $psw1=filter_var(''.$psw.'',FILTER_SANITIZE_STRING);
 $email=filter_var($emailc,FILTER_SANITIZE_EMAIL);

// Create our body messag
 $data = "Nanme:".$name."<br>Your username is <b>".$uname1."</b> and password is <b>".$psw1."</b> ";

//Create the transport
    $transport = Swift_SmtpTransport::newInstance('smtp.gmail.com',587,'tls')
    ->setUsername('xyz@gmail.com')
    ->setPassword('xyz121212');

// Create the mailer
 $mailer = Swift_Mailer::newInstance($transport);
 $message = Swift_Message::newInstance('Demo')
  ->setFrom (array('demo@gmail.com' => 'Demo'))
  ->setTo (array(''.$email.'' => 'Add Recipients'))
  ->setSubject ('Thanks, This mail is for remind your appoinment')
  ->setBody ($data, 'text/html');
// Send the message
 $result = $mailer->send($message); 
?>

最新更新