laravel 无法使用 gmail 对 SMTP 服务器错误进行身份验证
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/33939393/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Failed to authenticate on SMTP server error using gmail
提问by Diane Kaplan
I'm trying to set up email for my first laravel project, and was thrilled that there's a laracast for it: https://laracasts.com/lessons/mailers
我正在尝试为我的第一个 laravel 项目设置电子邮件,并且很高兴有一个 laracast:https://laracasts.com/lessons/mailers
I've followed the simple steps, chose gmail in mail.php (x's added for anonymity):
我遵循了简单的步骤,在mail.php中选择了gmail(为了匿名而添加了x):
'driver' => env('MAIL_DRIVER', 'smtp'),
'host' => env('MAIL_HOST', 'smtp.gmail.com'),
'port' => env('MAIL_PORT', 587),
'from' => ['address' => '[email protected]', 'name' => 'Diane Kaplan'],
'encryption' => env('MAIL_ENCRYPTION', 'tls'),
'username' => '[email protected]',
'password' => 'xxxxx',
'sendmail' => '/usr/sbin/sendmail -bs',
'pretend' => false,
.env has (x's added for anonymity)- the laracast doesn't have us use MAIL_USERNAME and MAIL_PASSWORD, but they're updated for good measure assuming I'll pull from there later:
.env 有(x 是为了匿名而添加的)-laracast 没有让我们使用 MAIL_USERNAME 和 MAIL_PASSWORD,但是假设我稍后会从那里拉出来,它们会被更新为很好的措施:
MAIL_DRIVER=smtp
MAIL_HOST=mailtrap.io
MAIL_PORT=2525
[email protected]
MAIL_PASSWORD=xxxxxx
MAIL_ENCRYPTION=null
But in the first little moment of truth trying to send a mail (3:30 mark), I get an authentication error: Swift_TransportException in AuthHandler.php line 181: Failed to authenticate on SMTP server with username "[email protected]" using 3 possible authenticators
但是在尝试发送邮件的第一个关键时刻(3:30 标记),我收到一个身份验证错误:Swift_TransportException in AuthHandler.php line 181: Failed to authentication on SMTP server with username "[email protected]" using 3 个可能的验证器
Based on a little stackoverflow reading, I tried turning on 'access to less secure apps' in my gmail settings, but no change in the error. (And the other posts about this issue had other factors that made a fancier problem than mine).
基于对 stackoverflow 的一些阅读,我尝试在我的 gmail 设置中打开“访问不太安全的应用程序”,但错误没有变化。(关于这个问题的其他帖子还有其他因素导致比我的问题更有趣)。
Nothing jumps out at me from laravel.log (below)- any ideas?
从laravel.log(下面)没有什么让我跳出来 - 有什么想法吗?
[2015-11-26 12:25:55] local.ERROR: exception 'Swift_TransportException' with message 'Failed to authenticate on SMTP server with username "[email protected]" using 3 possible authenticators' in /home/vagrant/Code/Family-laravel/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Transport/Esmtp/AuthHandler.php:181
Stack trace:
#0 /home/vagrant/Code/Family-laravel/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Transport/EsmtpTransport.php(307): Swift_Transport_Esmtp_AuthHandler->afterEhlo(Object(Swift_SmtpTransport))
#1 /home/vagrant/Code/Family-laravel/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Transport/AbstractSmtpTransport.php(118): Swift_Transport_EsmtpTransport->_doHeloCommand()
#2 /home/vagrant/Code/Family-laravel/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Mailer.php(79): Swift_Transport_AbstractSmtpTransport->start()
#3 /home/vagrant/Code/Family-laravel/vendor/laravel/framework/src/Illuminate/Mail/Mailer.php(395): Swift_Mailer->send(Object(Swift_Message), Array)
#4 /home/vagrant/Code/Family-laravel/vendor/laravel/framework/src/Illuminate/Mail/Mailer.php(181): Illuminate\Mail\Mailer->sendSwiftMessage(Object(Swift_Message))
#5 /home/vagrant/Code/Family-laravel/vendor/laravel/framework/src/Illuminate/Support/Facades/Facade.php(220): Illuminate\Mail\Mailer->send('emails.welcome', Array, Object(Closure))
#6 /home/vagrant/Code/Family-laravel/app/Http/routes.php(59): Illuminate\Support\Facades\Facade::__callStatic('send', Array)
#7 /home/vagrant/Code/Family-laravel/app/Http/routes.php(59): Illuminate\Support\Facades\Mail::send('emails.welcome', Array, Object(Closure))
#8 [internal function]: App\Providers\RouteServiceProvider->{closure}()
#9 /home/vagrant/Code/Family-laravel/vendor/laravel/framework/src/Illuminate/Routing/Route.php(155): call_user_func_array(Object(Closure), Array)
#10 /home/vagrant/Code/Family-laravel/vendor/laravel/framework/src/Illuminate/Routing/Route.php(130): Illuminate\Routing\Route->runCallable(Object(Illuminate\Http\Request))
#11 /home/vagrant/Code/Family-laravel/vendor/laravel/framework/src/Illuminate/Routing/Router.php(704): Illuminate\Routing\Route->run(Object(Illuminate\Http\Request))
#12 [internal function]: Illuminate\Routing\Router->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request))
#13 /home/vagrant/Code/Family-laravel/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(139): call_user_func(Object(Closure), Object(Illuminate\Http\Request))
#14 [internal function]: Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#15 /home/vagrant/Code/Family-laravel/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(103): call_user_func(Object(Closure), Object(Illuminate\Http\Request))
#16 /home/vagrant/Code/Family-laravel/vendor/laravel/framework/src/Illuminate/Routing/Router.php(706): Illuminate\Pipeline\Pipeline->then(Object(Closure))
#17 /home/vagrant/Code/Family-laravel/vendor/laravel/framework/src/Illuminate/Routing/Router.php(671): Illuminate\Routing\Router->runRouteWithinStack(Object(Illuminate\Routing\Route), Object(Illuminate\Http\Request))
#18 /home/vagrant/Code/Family-laravel/vendor/laravel/framework/src/Illuminate/Routing/Router.php(631): Illuminate\Routing\Router->dispatchToRoute(Object(Illuminate\Http\Request))
#19 /home/vagrant/Code/Family-laravel/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(236): Illuminate\Routing\Router->dispatch(Object(Illuminate\Http\Request))
#20 [internal function]: Illuminate\Foundation\Http\Kernel->Illuminate\Foundation\Http\{closure}(Object(Illuminate\Http\Request))
#21 /home/vagrant/Code/Family-laravel/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(139): call_user_func(Object(Closure), Object(Illuminate\Http\Request))
#22 /home/vagrant/Code/Family-laravel/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/VerifyCsrfToken.php(50): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#23 [internal function]: Illuminate\Foundation\Http\Middleware\VerifyCsrfToken->handle(Object(Illuminate\Http\Request), Object(Closure))
#24 /home/vagrant/Code/Family-laravel/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(124): call_user_func_array(Array, Array)
#25 /home/vagrant/Code/Family-laravel/vendor/laravel/framework/src/Illuminate/View/Middleware/ShareErrorsFromSession.php(49): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#26 [internal function]: Illuminate\View\Middleware\ShareErrorsFromSession->handle(Object(Illuminate\Http\Request), Object(Closure))
#27 /home/vagrant/Code/Family-laravel/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(124): call_user_func_array(Array, Array)
#28 /home/vagrant/Code/Family-laravel/vendor/laravel/framework/src/Illuminate/Session/Middleware/StartSession.php(62): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#29 [internal function]: Illuminate\Session\Middleware\StartSession->handle(Object(Illuminate\Http\Request), Object(Closure))
#30 /home/vagrant/Code/Family-laravel/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(124): call_user_func_array(Array, Array)
#31 /home/vagrant/Code/Family-laravel/vendor/laravel/framework/src/Illuminate/Cookie/Middleware/AddQueuedCookiesToResponse.php(37): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#32 [internal function]: Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse->handle(Object(Illuminate\Http\Request), Object(Closure))
#33 /home/vagrant/Code/Family-laravel/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(124): call_user_func_array(Array, Array)
#34 /home/vagrant/Code/Family-laravel/vendor/laravel/framework/src/Illuminate/Cookie/Middleware/EncryptCookies.php(59): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#35 [internal function]: Illuminate\Cookie\Middleware\EncryptCookies->handle(Object(Illuminate\Http\Request), Object(Closure))
#36 /home/vagrant/Code/Family-laravel/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(124): call_user_func_array(Array, Array)
#37 /home/vagrant/Code/Family-laravel/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/CheckForMaintenanceMode.php(42): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#38 [internal function]: Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode->handle(Object(Illuminate\Http\Request), Object(Closure))
#39 /home/vagrant/Code/Family-laravel/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(124): call_user_func_array(Array, Array)
#40 [internal function]: Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#41 /home/vagrant/Code/Family-laravel/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(103): call_user_func(Object(Closure), Object(Illuminate\Http\Request))
#42 /home/vagrant/Code/Family-laravel/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(122): Illuminate\Pipeline\Pipeline->then(Object(Closure))
#43 /home/vagrant/Code/Family-laravel/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(87): Illuminate\Foundation\Http\Kernel->sendRequestThroughRouter(Object(Illuminate\Http\Request))
#44 /home/vagrant/Code/Family-laravel/public/index.php(54): Illuminate\Foundation\Http\Kernel->handle(Object(Illuminate\Http\Request))
#45 {main}
回答by Milan Maharjan
Did you turn on the "Allow less secure apps" on? go to this link
您是否打开了“允许安全性较低的应用程序”?转到此链接
https://myaccount.google.com/security#connectedapps
https://myaccount.google.com/security#connectedapps
Take a look at the Sign-in & security -> Apps with account access menu.
查看登录和安全 -> 具有帐户访问权限的应用程序菜单。
You must turn the option "Allow less secure apps" ON.
您必须打开“允许安全性较低的应用程序”选项。
If is still doesn't work try one of these:
如果仍然不起作用,请尝试以下方法之一:
Go to https://accounts.google.com/UnlockCaptcha, and click continue and unlock your account for access through other media/sites.
Use double quote in your password: "your password"
转到https://accounts.google.com/UnlockCaptcha,然后单击继续并解锁您的帐户以通过其他媒体/网站进行访问。
在您的密码中使用双引号:“您的密码”
And change your .env file
并更改您的 .env 文件
MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
[email protected]
MAIL_PASSWORD=xxxxxx
MAIL_ENCRYPTION=tls
because the one's you have specified in the mail.php will only be used if the value is not available in the .env file.
因为只有当 .env 文件中的值不可用时,才会使用您在 mail.php 中指定的那个。
回答by benjolly1989
Nothing wrong with your method, it's a G-mail security issue.
你的方法没有问题,这是一个 G-mail 安全问题。
Login g-mail account settings.
Enable 2-step verification.
Use new-generated password in place of your real g-mail password.
登录 g-mail 帐户设置。
启用两步验证。
使用新生成的密码代替真实的 g-mail 密码。
Don't forget to clear cache.
不要忘记清除缓存。
php artisan config:cache.
php artisan config:clear.
MAIL_DRIVER=smtp
MAIL_HOST=mailtrap.io
MAIL_PORT=587
[email protected]
MAIL_PASSWORD=generatedAppPassword
MAIL_ENCRYPTION=tls
回答by L?c ??ng H?u
I had the same issue, but when I ran the following command, it was ok:
我遇到了同样的问题,但是当我运行以下命令时,一切正常:
php artisan config:cache
回答by Luis Mata B.
I had the same problem and I've already tried everything and nothing seemed to work until I just changed the 'host' value in config.php to:
我遇到了同样的问题,我已经尝试了所有方法,但似乎没有任何效果,直到我将 config.php 中的“host”值更改为:
'host' => env('smtp.mailtrap.io'),
When I changed that it worked nicely, somehow it was using the default host " smtp.mailtrap.org" and ignoring the .env variable I was setting.
当我更改它时它运行良好,不知何故它使用默认主机“smtp.mailtrap.org”并忽略我正在设置的 .env 变量。
After making some test I realize that if I placed the env variable in this order it would worked as it shoulded:
在进行了一些测试后,我意识到如果我按此顺序放置 env 变量,它将按预期工作:
MAIL_HOST=smtp.mailtrap.io
MAIL_HOST=smtp.mailtrap.io
?MAIL_DRIVER=smtp
?MAIL_DRIVER=smtp
?MAIL_PORT=2525?
?MAIL_PORT=2525?
MAIL_USERNAME=xxxx
MAIL_USERNAME=xxxx
?MAIL_PASSWORD=xxx
?MAIL_PASSWORD=xxx
?MAIL_ENCRYPTION=null
?MAIL_ENCRYPTION=空
回答by H45H
If you still get this error when sending email: "Failed to authenticate on SMTP server with username "[email protected]" using 3 possible authenticators"
如果您在发送电子邮件时仍然收到此错误:“无法使用 3 个可能的身份验证器使用用户名“[email protected]”在 SMTP 服务器上进行身份验证”
You may try one of these methods:
您可以尝试以下方法之一:
Go to https://accounts.google.com/UnlockCaptcha, click continue and unlock your account for access through other media/sites.
转到https://accounts.google.com/UnlockCaptcha,单击继续并解锁您的帐户以通过其他媒体/网站进行访问。
Using a double quote password: "your password". <-- this one also solved my problem.
使用双引号密码:“您的密码”。<--这也解决了我的问题。
回答by Sushil Timilsina
This is how I solved this issue:
我是这样解决这个问题的:
- Change the .env file as follow
- 更改 .env 文件如下
- Never forget to restart the server after you change the .env file
- 更改 .env 文件后永远不要忘记重新启动服务器