简体   繁体   English

Laravel 无法使用用户名在 SMTP 服务器上进行身份验证

[英]Laravel Failed to authenticate on SMTP server with username

Am trying to send email by Laravel.我正在尝试通过 Laravel 发送电子邮件。 But It's getting error.但它越来越错误。

.env file Configuration below: .env 文件配置如下:

MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME=myemailID@gmail.com
MAIL_PASSWORD=******
MAIL_ENCRYPTION=tls

Controller Code Below:控制器代码如下:

 $data = array('name'=>"Ripon Uddin", "body" => "Test mail");

    Mail::send('email', $data, function($message) {
        $message->to('ToEmailID@yahoo.com','To My Yahoo')->subject('Laravel Test Email');
        $message->from('ToFromID@gmail.com','Ripon Uddin (Laravel Lover)');
    });

Error gettings:错误获取:

Failed to authenticate on SMTP server with username "myEmailID@gmail.com" using 3 possible authenticators.无法使用 3 个可能的身份验证器在用户名为“myEmailID@gmail.com”的 SMTP 服务器上进行身份验证。 Authenticator LOGIN returned Swift_TransportException: 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 r18-v6sm7406256pgv.17 - gsmtp " in身份验证器登录返回 Swift_TransportException:预期响应代码 235 但收到代码“535”,消息“535-5.7.8 用户名和密码未被接受。了解更多信息,请访问 535 5.7.8 https://support.google.com/mail/? p=BadCredentials r18-v6sm7406256pgv.17 - gsmtp“在

you don't need to have GSuite to do this... I have done this integration alot of times with Laravel & GMail.你不需要 GSuite 来做这件事......我已经用 Laravel 和 GMail 做了很多次这种集成。 Just go to your Google Account > Security > Less secure app access and Click on "Turn on access (not recommneded)" See image for more info只需转到您的 Google 帐户 > 安全 > 不太安全的应用访问,然后点击“启用访问(不推荐)”查看图片了解更多信息

Go to this link or app password page of gmail then select 'mail' as "app" and custome name as "device".转到此链接或 gmail 的应用程序密码页面,然后选择“邮件”为“应用程序”,将客户名称选择为“设备”。 Then you will get app password.然后您将获得应用程序密码。 Just go to your laravel mai.php under config folder in production or env file in dev mode.只需转到生产模式下的 config 文件夹下的 laravel mai.php 或开发模式下的 env 文件。 Paste the generated code on password section 'password' => 'generated code', After all run: php artisan config:cache将生成的代码粘贴到密码部分'password' => 'generated code',运行: php artisan config:cache

Google changed its security policy.谷歌改变了它的安全政策。 Now "Allow less secure apps" option is not available under Sign-in & security.现在,“允许安全性较低的应用程序”选项在登录和安全下不可用。

The idea is that Gmail does not allow any application to access a user's Gmail account, even with its real username and password.这个想法是 Gmail 不允许任何应用程序访问用户的 Gmail 帐户,即使使用其真实的用户名和密码也是如此。 That's why people are getting the error.这就是人们收到错误的原因。 The new mechanism is you should create an application in your Google account and Google will generate a password for that application.新机制是您应该在您的 Google 帐户中创建一个应用程序,Google 将为该应用程序生成一个密码。 Gmail will allow access with that Password and real username/Gmail ID. Gmail 将允许使用该密码和真实用户名/Gmail ID 进行访问。

The solution is解决办法是

Step 1: sign-in to your Gmail account and to "Manage Your Account" as seen in the image below第 1 步:登录您的 Gmail 帐户并“管理您的帐户”,如下图所示

在此处输入图像描述

Step 2: Click on the Security Tab in the left sidebar,第 2 步:单击左侧边栏中的安全选项卡,

在此处输入图像描述

Step 3: Enable 2-step verification first for SMTP access.第 3 步:首先为 SMTP 访问启用两步验证。

在此处输入图像描述

You will not see "App Password" option until you enable 2-step verification.在启用两步验证之前,您不会看到“应用程序密码”选项。 After enabling 2-step verification click on "App Password".启用两步验证后,单击“应用程序密码”。 You will see like this你会看到这样

在此处输入图像描述

Click on the first dropdown and select "Other (Custom Name)".单击第一个下拉菜单并选择“其他(自定义名称)”。 In the new window write your application name and git the Generate button.在新窗口中写下您的应用程序名称和 git Generate 按钮。 Copy the password that showed up.复制显示的密码。

Use this password, instead of your real Gmail password.使用此密码,而不是您的真实 Gmail 密码。 SMTP configuration should look like SMTP 配置应该是这样的

在此处输入图像描述

This config works on Gmail if you "Allow less secure apps" setting enabled in your gmail settings:如果您在Gmail设置中启用了“允许安全性较低的应用”设置,则此配置适用于Gmail

mailer_transport: smtp
mailer_host: smtp.gmail.com
mailer_port: 465
mailer_encryption: ssl
mailer_auth_mode: login
mailer_user: xxxx@xxxxxxx.com
mailer_password: "xxxx"

This one works on Gmail Suite if you white list the ip of your server in your gmail settings (see https://support.google.com/a/answer/2956491 ):如果您在 Gmail 设置中将服务器的 ip 列入白名单(请参阅https://support.google.com/a/answer/2956491 ),则此方法适用于Gmail 套件

mailer_transport: smtp
mailer_host: smtp-relay.gmail.com
mailer_port: 587
mailer_encryption: tls
mailer_auth_mode: login
mailer_user: xxx@xxxxxxx.com
mailer_password: "xxxx"

Make sure your user credentials are right in .env file.确保您的用户凭据在 .env 文件中正确。

Try putting your passwords in quotes.尝试将您的密码放在引号中。 eg: MAIL_PASSWORD="mypassword"例如:MAIL_PASSWORD="我的密码"

To apply your changes Run应用您的更改运行

php artisan config:cache php工匠配置:缓存

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.您必须打开“允许安全性较低的应用程序”选项。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Laravel,无法使用 3 个可能的身份验证器使用用户名“”在 SMTP 服务器上进行身份验证 - Laravel, Failed to authenticate on SMTP server with username "" using 3 possible authenticators 使用 Laravel Jetstream 使用用户名在 SMTP 服务器上进行身份验证失败 - Failed to authenticate on SMTP server with username using Laravel Jetstream Laravel:无法使用 2 个可能的身份验证器在 SMTP 服务器上使用用户名进行身份验证 - Laravel :Failed to authenticate on SMTP server with username using 2 possible authenticators 无法在 SMTP 服务器上进行身份验证 Laravel 6 - Failed to authenticate on SMTP server in Laravel 6 使用 2 个可能的身份验证器在用户名“***”的 SMTP 服务器上进行身份验证失败 - Failed to authenticate on SMTP server with username “***” using 2 possible authenticators 无法使用2个可能的身份验证器在SMTP服务器上使用用户名进行身份验证 - Failed to authenticate on SMTP server with username using 2 possible authenticators Swift_TransportException无法使用用户名在SMTP服务器上进行身份验证 - Swift_TransportException Failed to authenticate on SMTP server with username Laravel ZOHO SMTP Email 认证失败 - Laravel ZOHO SMTP Email failed to authenticate google app smtp无法验证laravel 5.2 - google app smtp Failed to authenticate laravel 5.2 PHP SwiftMailer 无法在 SMTP 服务器上进行身份验证 - PHP SwiftMailer Failed to authenticate on SMTP server
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM