May Sale! All accounts are 40% off this week.

Nikki's avatar
Level 1

Failed to authenticate on SMTP server with username

I'm getting this error when I hit submit on my contact form

Failed to authenticate on SMTP server with username "[email protected]" using 2 possible authenticators. 
Authenticator LOGIN returned Expected response code 235 but got code "535", with message "535 Incorrect authentication data ". 
Authenticator PLAIN returned Expected response code 235 but got code "535", with message "535 Incorrect authentication data ".

As far as I know all my details is corrected and my cpanel php is 7.3.

On my live site the contact form works correctly, but on my localhost I'm getting the above mentioned error. I used mailtrap to test out my contact form and that worked as well.

I can't understand why I'm getting this error when those details is working fine on my live site.

this is my .env

MAIL_DRIVER=smtp
MAIL_HOST=mail.domain.com
MAIL_PORT=587
[email protected]
MAIL_PASSWORD=password
MAIL_ENCRYPTION=null
0 likes
24 replies
bobbybouwmann's avatar

In general you need an SMTP server to send emails through SMTP. Your local environment doesn't have this default. You can use alternative tools like mailhog to catch the SMTP calls and watch the email in there.

So locally using SMTP is always an issue :P

Snapey's avatar
Snapey
Best Answer
Level 122

If your mail server password contains a # then you should quote the environment string since everything after # will be taken as comment (starting in Laravel 5.8)

13 likes
TURKEY's avatar

I loooooooooooooove you, 4hours i was trying to fix, get headache of that. thanks dear

Gemley's avatar

@Snapey But my own password doesn't even contain # so what is the issue when all the smtp credentials are correct and it still throws in this error

Muthinicharlie's avatar

@Snapey Thanks, faced the same error now, I had a # in my mail server password, I had to quote it and solve the error

1 like
Nikki's avatar
Level 1

@SNAPEY - Thank you so much. That worked I did have a # in my password

Phuthao's avatar

Could you please show me where to find the # mentioned in this thread? thank you so much! I am an amateur!

Snapey's avatar

@phuthao you might not have one. It is saying that if your secrets in .env contain # then you must quote the string eg;

MAIL_PASSWORD = r39304#d^fd

The # marks the start of a comment, so the password ends up being 'r39304'

The solution;

MAIL_PASSWORD = "r39304#d^fd"
2 likes
cd4success's avatar

@snapey I'm so glad I came across this solution. My password actually started with #. Thank you soooo much.

Bhuvii's avatar

I am facing issue with mail and trying to solve issue for past three days

MAIL_DRIVER=smtp MAIL_HOST=smtp.gmail.com MAIL_PORT=587 MAIL_USERNAME=bhupendratiwari675@gmail.com MAIL_PASSWORD="appPassword" # Generated from google app Password MAIL_ENCRYPTION=tls

MAIL_FROM_ADDRESS=bhupendratiwari675@gmail.com

Please help

292marxist's avatar

{ "exception": "[object] (Symfony\Component\Mailer\Exception\TransportException(code: 535): Failed to authenticate on SMTP server with username "[email protected]" using the following authenticators: "LOGIN", "PLAIN", "XOAUTH2". Authenticator "LOGIN" returned "Expected response code "235" but got code "454", with message "454-4.7.0 Too many login attempts, please try again later. For more information,

454-4.7.0 go to

454 4.7.0 ". Authenticator "PLAIN" returned "Expected response code "235" but got empty code.". Authenticator "XOAUTH2" returned "Expected response code "235" but got empty code.". at /var/www/html/pedms/vendor/symfony/mailer/Transport/Smtp/EsmtpTransport.php:212) I am getting this error and i am using gmail smtp for sending mails

292marxist's avatar

@Snapey Is that needed to be done for this issue because this issue is only occurring sometimes in my system not all the time

Snapey's avatar

@292marxist why dont you start your own question and put the correct information in it?

heliahaghighi's avatar

@snapey Hey... any idea what's wrong here?

'smtp' => [

        'transport' => 'smtp',
        'driver' => 'smtp',
        'host' => 'smtp.gmail.com',
        'port' => 465,
        'encryption' => 'ssl',
        'username' => <username>,
        'password' => <pass>,
        'timeout' => null,
        'auth_mode' => null,
        'verify_peer' => false,
        'verify_peer_name' => false,
        'allow_self_signed' => true,
        'options' => [
            'ssl' => [
                'verify_peer' => false,
                'verify_peer_name' => false,
                'allow_self_signed' => true,
                'security_level' => 0,
                'peer_name' => 'smtp.gmail.com'
            ]
        ],

MAIL_MAILER=smtp

MAIL_HOST=smtp.gmail.com

MAIL_PORT=465

MAIL_USERNAME=

MAIL_PASSWORD=

MAIL_ENCRYPTION=ssl

running these on cPanel terminal:

$ php artisan tinker

Psy Shell v0.12.7 (PHP 8.2.25 — cli) by Justin Hileman

Mail::raw('Test email', function($message) { $message->to('[email protected]')->subject('Test'); });

Symfony\Component\Mailer\Exception\TransportException Failed to authenticate on SMTP server with username "[email protected]" using the following authenticators: "LOGIN", "PLAIN". Authenticator "LOGIN" returned "Expected response code "235" but got code "535", with message "535 Incorrect authentication data".". Authenticator "PLAIN" returned "Expected response code "235" but got code "535", with message "535 Incorrect authentication data".".

Note: I've got the 16-digit app password for the email address and use it without any spaces in the config>mail file

P.S. excuse the messy format...

lara_dev_1970's avatar

@heliahaghighi

  1. Have two-step authentication enabled in google account settings.
  2. Go to https://security.google.com/settings/security/apppasswords
  3. Create a new password.
  4. Use that password in quotation marks
  5. MAIL_ENCRYPTION=plain
MAIL_MAILER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
[email protected]
MAIL_PASSWORD="your gmail pass here"
MAIL_ENCRYPTION=plain #"Be careful here, make sure to put plain"
MAIL_FROM_ADDRESS="[email protected]"
MAIL_FROM_NAME="${APP_NAME}"
Abid4s's avatar

Failed to authenticate on SMTP server with username [email protected] using the following authenticators: LOGIN , PLAIN . Authenticator LOGIN returned Expected response code 235 but got code 535 , with message 535 5.7.8 Error: authentication failed: (reason unavailable) . . Authenticator PLAIN returned Expected response code 235 but got code 535 , with message 535 5.7.8 Error: authentication failed: (reason unavailable) . .

Gemley's avatar

none of these works for me. I think laravel should improve on this. There seems to be no consistency with this error and a clear explanation on what the cause is.

JussiMannisto's avatar

@Gemley If you're having SMTP connection issues, it probably has nothing to do with Laravel. You should make a separate thread and explain your issues there (with full error messages).

This thread is 5 years old and marked as solved.

Please or to participate in this conversation.