Failed to authenticate on SMTP server in Laravel 6 - php

I am trying to use smtp email functionality in my Laravel 6 Application.
This is my .env file code :
MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME=******#gmail.com
MAIL_PASSWORD=******
MAIL_ENCRYPTION=tls
Here it is the funny part :
It is working fine in my local host
It is also working in my server (without http)
It stopped working when I applied https in my server.
It gives me below error :
Failed to authenticate on SMTP server with username "*********#gmail.com" using 3 possible authenticators. Authenticator LOGIN returned Expected response code 235 but got code "534", with message "534-5.7.14
534-5.7.14 Please log in via your web browser and then try again.
534-5.7.14 Learn more at
534 5.7.14 https://support.google.com/mail/answer/78754 g6sm37628450pja.2 - gsmtp
". Authenticator PLAIN returned Expected response code 235 but got code "534", with message "534-5.7.14
534-5.7.14 Please log in via your web browser and then try again.
534-5.7.14 Learn more at
534 5.7.14 https://support.google.com/mail/answer/78754 g6sm37628450pja.2 - gsmtp
". 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
535 5.7.8 https://support.google.com/mail/?p=BadCredentials g6sm37628450pja.2 - gsmtp
".
Note :
Allow less secure logged is enabled
This same email is not used in three application for the SMTP email functionality.

the email is working in localhost, the less secure account account verification is correct
But you can't use your email in more than 3 projects, so you should stop using this email on other accounts.

Check if your gmail password has the $ character, if so change it.
it worked for me

Related

Laravel - How to fix "failed to authenticate on SMTP server" in Laravel 8 and Office365?

In one of my Laravel 8 based applications, I want to switch from Mailgun to Office365 as a service change. Here is the information I have to integrate:
SMTP hostname: smtp.office365.com
Port: 587
Encryption method: STARTTLS
SSL Protocol: OFF
TLS Protocol: ON
SMTP Username: smtp_user_email
SMTP Password: smtp_password
So I write the following code in my .env file:
MAIL_MAILER=smtp
MAIL_DRIVER=smtp
MAIL_HOST=smtp.office365.com
MAIL_PORT=587
MAIL_USERNAME=smtp_user_email
MAIL_PASSWORD=smtp_password
MAIL_ENCRYPTION=tls
MAIL_FROM_ADDRESS=smtp_user_email
MAIL_FROM_NAME="${APP_NAME}"
Then test the default Forget Password form of Laravel (so there should be no issue related to that form as it is the standard form of Laravel). But I receive the following response:
Swift_TransportException
Failed to authenticate on SMTP server with username "smtp_user_email" using 2 possible authenticators. Authenticator LOGIN returned Expected response code 235 but got code "535", with message "535 5.7.139 Authentication unsuccessful, the user credentials were incorrect. [SI2PR02CA0047.apcprd02.prod.outlook.com] ". Authenticator XOAUTH2 returned Expected response code 235 but got code "535", with message "535 5.7.3 Authentication unsuccessful [SI2PR02CA0047.apcprd02.prod.outlook.com] ".
I check the username and password, which is OK but I have no idea why it returns authenticationon related error!
Does anyone why actually I missing that returns the error?
Thanks

How send email with laravel ... i need send to gmail

I need send email with laravel to gmail but it's showing the below error:
Error:
Expected response code 250 but got code "530", with message "530 5.7.0
Must issue a STARTTLS command first. 127sm105612220wmm.45 - gsmtp "
First login to your Gmail account and under My account > Sign In And Security > Sign In to google, enable two step verification, then you can generate app password, and you can use that app password in .env file.
Your .env a file will then look something like this:
MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME=myemail#gmail.com
MAIL_PASSWORD=apppassword
MAIL_ENCRYPTION=tls
Don't forget to run php artisan config:cache after you make changes in your .env file.
Response code 530 indicates that you have not allowed Less Secure Apps to use your Gmail account.
You will need to enable this in your Google settings. Here's a link.
After you have allowed this, the email should go through.
If you're just testing, I would recommend using an SMTP testing server, such as Mailtrap. It's free and will avoid the security risk that comes with allowing less secure apps to use your Gmail account.
Please turn on Less secure app access for your SMTP email account.
From the following url go to: Google Account

response code 250 but got code "535", with message "535-5.7.8 Username and Password not accepted. Learn more at 535 5.7.8

I am using laravel 5.4.
While sending verification email, i got the aforementioned error.
I don't know what i am doing wrong this is my env file:
MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME=shahzadshah5741#gmail.com
MAIL_PASSWORD=hussain57421
MAIL_ENCRYPTION=tls
Two ways:
Go to your Google Account Management page
Under the Security options, click Edit link of Authorising applications & sites
Under gmail settings, you need to access https://www.google.com/settings/security/lesssecureapps
and set 'Access for less secure apps' to "Enabled"

Error when sending email via Laravel 5.1

When I try to send an e-mail through my website running Laravel 5, I get this exception:
Expected response code 250 but got code "535", with message "535-5.7.8 Username and Password not accepted. Learn more at
535 5.7.8 https://support.google.com/mail/answer/14257 l140sm14142372oig.11 - gsmtp
Here is my env configuration
MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME=example#gmail.com
MAIL_PASSWORD=example
MAIL_ENCRYPTION=tls
Code works on local and other website but not work on my new website on new hosting. I allow access from less-secure apps. What can be problem?
It's possible that G-Mail doesn't like the 3rd party application that's connecting to it.
If you are sure the credentials are correct, then visit this link to check if you need to approve the application

smtp gmail server php mailer not working

I know this question has been asked many a times before. But the solutions didn't seem to help me . So hereby I am posting my code:
<?php
require("class.phpmailer.php");
require("class.smtp.php");
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->Host="smtp.gmail.com";
$mail->SMTPDebug=1;
$mail->SMTPAuth=true;
$mail->SMTPSecure="ssl";
$mail->Port=465;
$mail->Username ="me#gmail.com";
$mail->Password="mypassword";
$mail->AddAddress("to#yahoo.co.in");
$mail->SetFrom("me#gmail.com", "myname");
$mail->AddReplyTo("someone#gmail.com","someone");
$mail->Subject="Greetings from ME";
$mail->Body="Greeting !! I am glad you received this message";
$mail->WordWrap=50;
if($mail->send())
{
echo "Mail sent successfully";
}
else
{
echo "Sorry mail could not be sent because of error ".$mail->ErrorInfo;
}
?>
The SMTP Debug is:
CLIENT -> SERVER: EHLO messengerclick.byethost3.com 2015-07-26 12:49:42 CLIENT -> SERVER: AUTH LOGIN 2015-07-26 12:49:42
CLIENT -> SERVER: Y2hlcm9ja3oxOUBnbWFpbC5jb20= 2015-07-26 12:49:42
CLIENT -> SERVER: Y2hldGFucm9ja3MxOQ== 2015-07-26 12:49:43
SMTP ERROR: Password command failed: 534-5.7.14 Please log in via your web browser and 534-5.7.14 then try again. 534-5.7.14 Learn more at 534 5.7.14 https://support.google.com/mail/answer/78754 sc16sm22415466wjb.28 - gsmtp 2015-07-26 12:49:43
SMTP Error: Could not authenticate. 2015-07-26 12:49:43
CLIENT -> SERVER: QUIT 2015-07-26 12:49:43 SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting Sorry mail could not be sent because of error SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
I have enabled access for unknown apps on my gmail account.
I have also clicked on continue on this link
http://www.google.com/accounts/DisplayUnlockCaptcha
after signing in.
I am running this from my byethost account. It is working fine for smtp.mail.yahoo.com
Please help me know what I am doing wrong.
If you’re sure your password is correct, you can try these troubleshooting tips:
If you've turned on 2-Step Verification for your account, you might need to enter an App password.
Sign in to your account from the web version of Gmail at https://mail.google.com. Afterwards try accessing your messages in
your mail app again.
If you're still having problems, visit http://www.google.com/accounts/DisplayUnlockCaptcha and sign in with
your Gmail username and password. If necessary, enter the letters in
the distorted picture.
Your mail app might not support the latest security standards. Learn how to allow less secure apps access to your account.
Make sure your mail app isn't set to check for new email too frequently. If your mail app checks for new messages more than once
every 10 minutes, the app’s access to your account could be blocked.
Try changing your password according to our tips on creating a strong password.
Source.
Here, you can allow less secure apps. Click on Turn On to allow less secure apps having your username and password.
If you are facing similar issue
Try this out:
If you had your password last modified before 2014 change your password to stronger one.
It worked for me

Categories