Laravel,无法使用 3 个可能的身份验证器使用用户名“”在 SMTP 服务器上进行身份验证

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/53194262/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 18:09:23  来源:igfitidea点击:

Laravel, Failed to authenticate on SMTP server with username "" using 3 possible authenticators

phplaravel

提问by alphal

I am trying to find out why this happens.

我试图找出为什么会发生这种情况。

.env

.env

MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME=*******[email protected]
MAIL_PASSWORD=******
MAIL_ENCRYPTION=tls

mail.php

邮件.php

<?php
return [

    'driver' => env('MAIL_DRIVER', 'smtp'),

    'host' => env('MAIL_HOST', 'smtp.gmail.com'),

    'port' => env('MAIL_PORT', 587),

    'from' => ['address' =>  '******@gmail.com', 'name' => 'Project'],

    'encryption' => env('MAIL_ENCRYPTION', 'tls'),

    'username' => env('******@gmail.com'),

    'password' => env('******'),

    'sendmail' => '/usr/sbin/sendmail -bs',

    'pretend' => false,
    'stream' => [
        'ssl' => [
            'allow_self_signed' => true,
            'verify_peer' => false,
            'verify_peer_name' => false,
        ],
    ],
];

This is the error

这是错误

Failed to authenticate on SMTP server with username "" using 3 possible authenticators. Authenticator LOGIN returned Swift_TransportExce ?
534-5.7.14 GVHg3-rU8SDpVLdwnIPviBCjKNnBRcxuU2N3-pcUWd0TeMbM_vULrHhQcVNXjhoewjrquW\r\n
534-5.7.14 Jttd6jNXfnledZiAMv-rjMvpnd01nas-2J2BYU_Krd4kzT-YmTR_HW9uW3S6Ts2jUxDaC8\r\n
534-5.7.14 XmT_TV9QqYXHXkTMcrX3OG9D4QyF4E6w7fwnu2bYZT36rZXTU-HqJwlWzJBv8-MC2P9xrN\r\n
534-5.7.14 cUd4-BirG0rfAjlDxy5bkbon3S_bIFSZQVd0-5wskctUR4do7F> Please log in via\r\n
534-5.7.14 your web browser and then try again.\r\n
534-5.7.14  Learn more at\r\n
534 5.7.14  https://support.google.com/mail/answer/78754 l5-v6sm1366079wrv.84 - gsmtp\r\n
" in C:\xampp\htdocs\wer\walrer\vendor\swiftmailer\swiftmailer\lib\classes\Swift\Transport\AbstractSmtpTransport.php:457\n
Stack trace:\n

I checked email credentials and they are the same. In this project I have used authentication , but can't find a solution to this one.

我检查了电子邮件凭据,它们是相同的。在这个项目中,我使用了 authentication ,但找不到解决方案。

回答by Camilo

I think there is something wrong with your mail.phpfile.

我认为您的mail.php文件有问题。

You should be passing the variable names to the env()function for usernameand password.

您应该将变量名称传递给env()函数 for usernameand password

So this:

所以这:

'username' => env('******@gmail.com'),

'password' => env('******'),

Becomes this:

变成这样:

'username' => env('MAIL_USERNAME'),

'password' => env('MAIL_PASSWORD'),

回答by Elisha Senoo

Your .envfile looks good.

你的.env文件看起来不错。

You mail.phpfile should look like this:

您的mail.php文件应如下所示:

<?php
return [

    'driver' => env('MAIL_DRIVER', 'smtp'),

    'host' => env('MAIL_HOST', 'smtp.gmail.com'),

    'port' => env('MAIL_PORT', 587),

    'from' => ['address' =>  '******@gmail.com', 'name' => 'Project'],

    'encryption' => env('MAIL_ENCRYPTION', 'tls'),

    'username' => env('MAIL_USERNAME', '******@gmail.com'),

    'password' => env('MAIL_PASSWORD', '******'),

    'sendmail' => '/usr/sbin/sendmail -bs',

    'pretend' => false,
    'stream' => [
        'ssl' => [
            'allow_self_signed' => true,
            'verify_peer' => false,
            'verify_peer_name' => false,
        ],
    ],
];

The value in the second parameter for the env()function, gets used if the .envkey specified in the first parameter is not found.

env()如果.env未找到第一个参数中指定的键,则使用该函数的第二个参数中的值。

回答by LeCarloslouch

You need to enable less secure apps access at your google account for this to work

您需要在您的谷歌帐户中启用安全性较低的应用程序访问才能使其正常工作