我正在使用Windows 10和cmd。
我用php example.php
启动example.php文件,但出现此错误:
PHP Fatal error: Uncaught Swift_TransportException: Failed to authenticate on SMTP server with username "mateusz" using 3 possible authenticators. Authenticator LOGIN returned Expected response code 235 but got code "535", with message "535-5.7.8 Username and Password not accepted. Learn more at
535 5.7.8 https://support.google.com/mail/?p=BadCredentials v26sm4139501lji.43 - gsmtp
". Authenticator PLAIN returned Expected response code 235 but got code "535", with message "535-5.7.8 Username and Password not accepted. Learn more at
535 5.7.8 https://support.google.com/mail/?p=BadCredentials v26sm4139501lji.43 - gsmtp
". Authenticator XOAUTH2 returned Expected response code 250 but got code "535", with message "535-5.7.8 Username and Password not accepted. Learn more at
535 5.7.8 https://support.google.com/mail/?p=BadCredentials v26sm4139501lji.43 - gsmtp
". in C:\xampp\htdocs\php\vendor\swiftmailer\swiftmailer\lib\classes\Swift\Transport\Esmtp\AuthHandler.php:191
Stack trace:
#0 C:\xampp\htdocs\php\vendor\swiftmailer\ in C:\xampp\htdocs\php\vendor\swiftmailer\swiftmailer\lib\classes\Swift\Transport\Esmtp\AuthHandler.php on line 191
Fatal error: Uncaught Swift_TransportException: Failed to authenticate on SMTP server with username "mateusz" using 3 possible authenticators. Authenticator LOGIN returned Expected response code 235 but got code "535", with message "535-5.7.8 Username and Password not accepted. Learn more at
535 5.7.8 https://support.google.com/mail/?p=BadCredentials v26sm4139501lji.43 - gsmtp
". Authenticator PLAIN returned Expected response code 235 but got code "535", with message "535-5.7.8 Username and Password not accepted. Learn more at
535 5.7.8 https://support.google.com/mail/?p=BadCredentials v26sm4139501lji.43 - gsmtp
". Authenticator XOAUTH2 returned Expected response code 250 but got code "535", with message "535-5.7.8 Username and Password not accepted. Learn more at
535 5.7.8 https://support.google.com/mail/?p=BadCredentials v26sm4139501lji.43 - gsmtp
". in C:\xampp\htdocs\php\vendor\swiftmailer\swiftmailer\lib\classes\Swift\Transport\Esmtp\AuthHandler.php:191
Stack trace:
#0 C:\xampp\htdocs\php\vendor\swiftmailer\ in C:\xampp\htdocs\php\vendor\swiftmailer\swiftmailer\lib\classes\Swift\Transport\Esmtp\AuthHandler.php on line 191
这是我的example.php文件:
<?php
require "vendor/autoload.php";
$transport = new Swift_SmtpTransport("ssl://smtp.gmail.com", 465);
$transport->setUsername('mateusz');
$transport->setPassword('my_password');
$mailer = new Swift_Mailer($transport);
$message = new Swift_Message();
$message->setFrom('my_email');
$message->setTo('my_email');
$message->setSubject('hello title');
$message->setBody('body random text');
$mailer->send($message);
这是我的composer.json文件:
{
"name": "mateu/php",
"require": {
"swiftmailer/swiftmailer": "^6.2"
},
"authors": [
{
"name": "velewqqw",
"email": "123k@gmail.com"
}
]
}
composer --version:
Composer version 1.10.5 2020-04-10 11:44:22
可能是什么问题? 谢谢您的帮助。