Error sending email using Gmail SMTP with Laravel - laravel

I'm trying to send mails from my webserver using Laravel 6 like this:
Mail::send('feedback', ['email' => $email, 'text' => $text], function($message) use ($receiver)
{
$message->to($receiver, 'The receiver')->subject('New Feedback');
});
I added my login information into my .env file according to this page from google:
https://support.google.com/mail/answer/7126229?hl=de
my .env file:
MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME=xxxx#gmail.com
MAIL_PASSWORD=my_gmail_login_password
MAIL_ENCRYPTION=tls
but I keep getting this error message:
Expected response code 250 but got code "530", with message "530-5.7.0 Authentication Required. Learn more at
530 5.7.0 https://support.google.com/mail/?p=WantAuthError
It looks like I would have used wrong credentials but I'm able to login with these credentials in gmail.
I also enabled insecure apps in my gmail settings.
I also tried to solve it by creating an app password and using it instead of my gmail password.
Nothing worked.
Does someone have an idea what I'm doing wrong?

when you want to send email from gmail you have to change some settings in gmail account.
Step 1: Configure your Google Account
Login to your Google Email Account and click on Google Account Button. This button is display when you click on the profile picture in your Gmail Dashboard as shown
Once you are on My Account Page then click on Security and scroll down to the bottom and you will find ‘Less secure app access’ settings. Click on the radio button to set it ON.
I think this link is helpful to you
https://medium.com/#agavitalis/how-to-send-an-email-in-laravel-using-gmail-smtp-server-53d962f01a0c

I could solve it by changing
MAIL_DRIVER=smtp
to
MAIL_DRIVER=sendmail
now I don't get any errors logged and everything seems to be working fine, but the mails don't get delivered to the mail address where they should be.

Related

Gmail smtp not working with only one email

I am using gmail smtp in my laravel, It was working fine till yesterday but it suddenly stopped, I am getting this error
Failed to authenticate on SMTP server with username "email#gmail.com" using 3 possible authenticators. Authenticator LOGIN returned Expected response code 235 but got code "535", with message "535-5.7.8 Username and Password not accepted
Less secure apps was already on so i added 2 factor auth and created an app password but still not working, I created a test email and it worked fine, why is not working with my first email
This is my setting in env
MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME=email#gmail.com
MAIL_PASSWORD=password
MAIL_ENCRYPTION=tls
MAIL_EMAIL_ADDRESS=email#gmail.com
I also tried by adding double quotes, but still not wokring,
Can anyone please help
After the removal of less secure apps. You can no longer connect to googles smtp server using the actual password of the users gmail account.
YOu have two options.
enable 2fa on the google account and create an apps password. The apps password can then be used in place of the password in your code.
Switch to using Xoauth2.

"Failed to authenticate on SMTP server" after more than 100 emails

I'm trying to send about 500 emails with Laravel, my provider is Gmail.
The first 150 emails (more or less) are sent correctly, but after I receive this error:
"Failed to authenticate on SMTP server with username "XXXXXXX" using 3 possible authenticators. Authenticator LOGIN returned Expected response code 250 but got an empty response. Authenticator PLAIN returned Expected response code 250 but got an empty response. Authenticator XOAUTH2 returned Expected response code 250 but got an empty response."
My .env is
MAIL_MAILER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_ENCRYPTION=ssl
MAIL_USERNAME=...
MAIL_PASSWORD=...
I also tried to wait for about 5 seconds between each email, but it doesn't work.
Anyone knows how I can handle this?
Thank you
Try to use the next settings:
MAIL_PORT=465
MAIL_ENCRYPTION=ssl
Enable 2FA in your Google account and create an app password.
Use it in MAIL_PASSWORD
I had a similar problem, and here is how I solved it.
the Google mail service may have blocked emails from being sent from your app. Google surely viewed this as a security threat. you should definitely receive a security alert in your mailbox.
You just have to admit that it was you who tried to access the account or just change your gmail password. after that please change the info in the .env file and i think it will work.
try to change your password on gmail
and also in your .env file

Error On Setting Up SMTP On Ofiice365 On Laravel

When I am trying to set up SMTP mail account which my client gave there is an error where i could resolve ,
Can someone help
MAIL_DRIVER=smtp
MAIL_HOST=smtp.office365.com
MAIL_PORT=587
MAIL_USERNAME=xxxxxx
MAIL_PASSWORD=xxxx
MAIL_ENCRYPTION=tls used STARTTLS & ssl
This is the error that i get
Swift_TransportException
Failed to authenticate on SMTP server with username "appointments#test.org" using 2 possible authenticators. Authenticator LOGIN returned Expected response code 235 but got code "535", with message "535 5.7.139 Authentication unsuccessful, SmtpClientAuthentication is disabled for the Tenant. Visit aka.ms/smtp_auth_disabled for more info. [SG2PR04CA0177.apcprd04.prod.outlook.com] ". Authenticator XOAUTH2 returned Expected response code 235 but got code "451", with message "451 4.7.0 Temporary server error. Please try again later. PRX4 [SG2PR04CA0177.apcprd04.prod.outlook.com] ".
Can someone help
Thank you
https://wordpress.org/support/topic/5-7-139-authentication-unsuccessful-error-suddenly/
Someone disabled SMTP for the box you have a link with an explanation
in the error you posted.
One way to try:
Use the Microsoft 365 admin center to enable or disable SMTP AUTH on
specific mailboxes Open the Microsoft 365 admin center and go to Users
Active users.
Select the user, and in the flyout that appears, click Mail.
In the Email apps section, click Manage email apps.
Verify the Authenticated SMTP setting: unchecked = disabled, checked =
enabled.
When you're finished, click Save changes.

laravel "error when sending email fwrite(): send of 18 bytes failed with errno=10054"

I am using laravel I got this error when I send emails
fwrite(): send of 18 bytes failed with errno=10054 An existing connection was forcibly closed by the remote host.
it was working normally
this is my configuration
MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME=givkom#gmail.com
MAIL_PASSWORD=123456789
MAIL_ENCRYPTION=tls
Mail::to($request->email)->send(new DonorMail());
change .env file like this:
MAIL_DRIVER=smtp
MAIL_HOST=smtp.googlemail.com
MAIL_PORT=465
MAIL_USERNAME=ENTER_YOUR_EMAIL_ADDRESS(GMAIL)
MAIL_PASSWORD=ENTER_YOUR_GMAIL_PASSWORD
MAIL_ENCRYPTION=ssl
The MAIL_USERNAME and PASSWORD should be replaced with your Gmail Email address and Password respectively.
Since we are using Gmail SMTP, we need to change some security settings on our Google account, to give access to less secured applications.
Configure your Google Account
Login to your Google Email Account and click on Google Account Button.
Once you are on My Account Page then click on Security and scroll down to the bottom and you will find ‘Less secure app access’ settings. Click on the radio button to set it ON.

How to send email by gmail in Laravel

MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME=semhnh#gmail.com
MAIL_PASSWORD=********
MAIL_ENCRYPTION=tls
MAIL_FROM_ADDRESS=semhnh#gmail.com
MAIL_FROM_NAME="${APP_NAME}"
MY ERROR-->
Swift_TransportException
Expected response code 250 but got code "530", with message "530 5.7.1 Authentication required
how to send gmail email in larave, im very tired in this error, please help me
this is my .env file
my env file
this is may error image
email error
Gmail SMTP Settings
MAIL_DRIVER=smtp
MAIL_HOST=smtp.googlemail.com
MAIL_PORT=465
MAIL_USERNAME=ENTER_YOUR_EMAIL_ADDRESS(GMAIL)
MAIL_PASSWORD=ENTER_YOUR_GMAIL_PASSWORD
MAIL_ENCRYPTION=ssl
You must configure your Google Account
Login to your Google Email Account and click on Google Account Button.
This button is display when you click on the profile picture in your
Gmail Dashboard as shown.
Once you are on My Account Page then click on Security and scroll down
to the bottom and you will find ‘Less secure app access’ settings.
Click on the radio button to set it ON.
Complete reading here

Resources