Authenticator "LOGIN" returned "Expected response code "235" but got code "535", with message "535 Authentication failed"."

Viewed 1362

i got an error when trying to send an email using laravel auth.

this is my .env file

MAIL_MAILER=smtp
MAIL_HOST=smtp.mailgun.org
MAIL_PORT=465
MAIL_USERNAME=myEmail@gmail.com
MAIL_PASSWORD=myPassword
MAIL_ENCRYPTION=tls
MAIL_FROM_ADDRESS=hello@example.com
MAIL_FROM_NAME=Example

and this is my mail.php file

    'mailers' => [
        'smtp' => [
            'transport' => 'smtp',
            'host' => env('MAIL_HOST', 'smtp.mailgun.org'),
            'port' => env('MAIL_PORT', 465),
            'encryption' => env('MAIL_ENCRYPTION', 'tls'),
            'username' => env('MAIL_USERNAME'),
            'password' => env('MAIL_PASSWORD'),
            'timeout' => null,
        ],

        'ses' => [
            'transport' => 'ses',
        ],

        'mailgun' => [
            'transport' => 'mailgun',
        ],

        'postmark' => [
            'transport' => 'postmark',
        ],

        'sendmail' => [
            'transport' => 'sendmail',
            'path' => env('MAIL_SENDMAIL_PATH', '/usr/sbin/sendmail -bs -i'),
        ],

        'log' => [
            'transport' => 'log',
            'channel' => env('MAIL_LOG_CHANNEL'),
        ],

        'array' => [
            'transport' => 'array',
        ],

        'failover' => [
            'transport' => 'failover',
            'mailers' => [
                'smtp',
                'log',
            ],
        ],
    ],

    /*
    |--------------------------------------------------------------------------
    | Global "From" Address
    |--------------------------------------------------------------------------
    |
    | You may wish for all e-mails sent by your application to be sent from
    | the same address. Here, you may specify a name and address that is
    | used globally for all e-mails that are sent by your application.
    |
    */

    'from' => [
        'address' => env('MAIL_FROM_ADDRESS', 'hello@example.com'),
        'name' => env('MAIL_FROM_NAME', 'Example'),
    ],

    /*
    |--------------------------------------------------------------------------
    | Markdown Mail Settings
    |--------------------------------------------------------------------------
    |
    | If you are using Markdown based email rendering, you may configure your
    | theme and component paths here, allowing you to customize the design
    | of the emails. Or, you may simply stick with the Laravel defaults!
    |
    */

    'markdown' => [
        'theme' => 'default',

        'paths' => [
            resource_path('views/vendor/mail'),
        ],
    ],

];

I've tried changing the value of MAIL_MAILER, MAIL_HOST,MAIL_PORT, MAIL_ENCRYPTION, MAIL_FROM_ADDRESS, and MAIL_FROM_NAME in .env file according to the information in the mail.php file. but it's still didn't work.Can someone please help me to resolve this, thank you.

1 Answers

.env file.

MAIL_MAILER=smtp
MAIL_HOST=smtp.mailgun.org
MAIL_PORT=465
MAIL_USERNAME=myEmail@gmail.com  \\  Gmail mail iD
MAIL_PASSWORD=myPassword \\ Gmail App generated password
MAIL_ENCRYPTION=tls
MAIL_FROM_ADDRESS=hello@example.com
MAIL_FROM_NAME=Example

Below link to generating an app password. https://support.google.com/mail/answer/185833?hl=en

OR

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

Localhost system MAIL_DRIVER=smtp was working fine, when you uploaded your project on cpanel then getting this error. So simple change in .env file

MAIL_DRIVER from smtp to sendmail.

More help also read: The connection could not be established with host smtp.gmail.com?

How to Send Email in Laravel with Example?

Related