alphal
alphal

Reputation: 149

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=*******[email protected]
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.

Upvotes: 2

Views: 20574

Answers (3)

LeCarloslouch
LeCarloslouch

Reputation: 1

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

Upvotes: 0

Elisha Senoo
Elisha Senoo

Reputation: 3594

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.

Upvotes: 0

Camilo
Camilo

Reputation: 7204

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'),

Upvotes: 2

Related Questions