can you guys help me with this issue! I want to email notification as a confirmation of service. The email is working via localhost email google. This is working fine. However, when I host on the server (Centos Server) it is not working. I have already set "on" the "Less secure app access" also.

Please help

.env file

MAIL_MAILER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
[email protected]
MAIL_FROM_NAME="Test System"
MAIL_PASSWORD=yourpassword@123
MAIL_ENCRYPTION=tls

config/mail.php

<?php

return [

/*
|--------------------------------------------------------------------------
| Default Mailer
|--------------------------------------------------------------------------
|
| This option controls the default mailer that is used to send any email
| messages sent by your application. Alternative mailers may be setup
| and used as needed; however, this mailer will be used by default.
|
*/

'default' => env('MAIL_MAILER', 'smtp'),

/*
|--------------------------------------------------------------------------
| Mailer Configurations
|--------------------------------------------------------------------------
|
| Here you may configure all of the mailers used by your application plus
| their respective settings. Several examples have been configured for
| you and you are free to add your own as your application requires.
|
| Laravel supports a variety of mail "transport" drivers to be used while
| sending an e-mail. You will specify which one you are using for your
| mailers below. You are free to add additional mailers as required.
|
| Supported: "smtp", "sendmail", "mailgun", "ses",
|            "postmark", "log", "array"
|
*/

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

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

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

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

    'sendmail' => [
        'transport' => 'sendmail',
        'path' => '/usr/sbin/sendmail -bs',
    ],

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

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

/*
|--------------------------------------------------------------------------
| 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', '[email protected]'),
    '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'),
    ],
],

];

Error popup in server

Failed to authenticate on SMTP server with username "[email protected]" using 3 possible authenticators. Authenticator LOGIN returned Expected response code 235 but got code "534", with message "534-5.7.14 <https://accounts.google.com/signin/continue?sarp=1&scc=1&plt=AKgnsbv\r\n534-5.7.14 6QwiGpAN3JU8gappy5A_Cl9KLH2CIjz98b5ufHVlyZK-VAesyRaqeQrx5RLudEYe6S9zR\r\n534-5.7.14 j5MPM-5qY6oL3dc6Fcvu5omIkkEus6rK_Wz8pAYdVSQo6tO3FEea26ujojWqiO5L>\r\n534-5.7.14 Please log in via your web browser and then try again.\r\n534-5.7.14 Learn more at\r\n534 5.7.14 https://support.google.com/mail/answer/78754 h13-20020a056a00230d00b004f427ffd485sm16382266pfh.143 - gsmtp\r\n". Authenticator PLAIN returned Expected response code 235 but got code "534", with message "534-5.7.14 <https://accounts.google.com/signin/continue?sarp=1&scc=1&plt=AKgnsbs\r\n534-5.7.14 M7gUR-WFJS5p6fdwdulgY_ECc3U6v49WszVBavDfPpGRm_qGZD-pRnZqVELJel_QbhfC6\r\n534-5.7.14 tfFapza74BulVzQiOQBRNVudGg-XdjDE-WVQB0xDmiXh0pJ1lFYIlN3braZrpj87>\r\n534-5.7.14 Please log in via your web browser and then try again.\r\n534-5.7.14 Learn more at\r\n534 5.7.14 https://support.google.com/mail/answer/78754 h13-20020a056a00230d00b004f427ffd485sm16382266pfh.143 - gsmtp\r\n". Authenticator XOAUTH2 returned Expected response code 250 but got code "535", with message "535-5.7.8 Username and Password not accepted. Learn more at\r\n535 5.7.8 https://support.google.com/mail/?p=BadCredentials h13-20020a056a00230d00b004f427ffd485sm16382266pfh.143 - gsmtp\r\n".

Gmail

2

There are 2 best solutions below

2
On BEST ANSWER

In the responses you can see ...Please log in via your web browser and then try again.... This indicates that you got into the OAuth flow. In the localhost scenario it probably works because you already approved the Gmail OAuth Dialog before. You have to register / authorize your app in the google console.

Have a look here: https://developers.google.com/gmail/api/auth/about-auth

0
On

If someone having trouble with this in 2023. Try this way. Google changed its security policy. Now "Allow less secure apps" option is not available under Sign-in & security.
That's why you have to go first (Manage Your Google Account) and then search (App Passwords) and go App Password option.

-> After that, you see an input box where you have to put the app name to create a password.

-> You will find your App Name from Swift_TransportException error message. Its something like this (535-5.7.8)

-> View this image to better understand.

enter image description here

-> Then create a password by this app name. -> Then you will get a password from Google and put this password in the .env file MAIL_PASSWORD options. Hope it will work.