简体   繁体   中英

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

I am trying to find out why this happens.

.env

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

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('******@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.

I think there is something wrong with your mail.php file.

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

So this:

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

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

Becomes this:

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

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

Your .env file looks good.

You mail.php file should look like this:

<?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 .env key specified in the first parameter is not found.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM