How to send email by gmail in Laravel - 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

Related

Failed to send message from Laravel controller

I tried to send an email from a Laravel controller, but it's showing this error. I'm not using a two step verified Gmail account. Most tutorials use the "enable less secure app" settings, but I can't enable that option in my account.
this is my env file
MAIL_MAILER=smtp
MAIL_HOST=smtp.googlemail.com
MAIL_PORT=465
MAIL_USERNAME=******
MAIL_PASSWORD=******
MAIL_ENCRYPTION=ssl
MAIL_FROM_ADDRESS=********
MAIL_FROM_NAME="${APP_NAME}"
Please use your google app password in MAIL_PASSWORD

Error sending email using Gmail SMTP with 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.

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 mail with laravel through gmail smtp?

I want to make contact Us page in my website, i have successfully do it with mailtrap, but when i want to send with gmail smtp server , i receive nothing and i get no error.
this is my .env mail config :
MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=465
MAIL_USERNAME=myemail
MAIL_PASSWORD=my_app_password
MAIL_ENCRYPTION=ssl
and code i use to send email:
$obj=new \stdClass();
$obj->contenu=$request->input('contenu');
$obj->objet=$request->input('objet');
$obj->email=$request->input('email');
$data=array('contenu'=>$obj->contenu,'email'=>$obj->email);
Mail::send("front.contactUs",$data,function ($message) use ($obj){
$message->from($obj->email);
$message->to('salondesbelleslettres#gmail.com')
->subject($obj->objet);
});
if(count(Mail::failures())>0){
return redirect()->back()->with('error','Votre demande na pas ete soumise');
}else{
return redirect()->back()->with('success','Merci de Nous Avoir Contacté');
}
Thanks.
Need to change your .env file to 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
After completion of .env edit please enter this command in your terminal for clear cache:
php artisan config:cache
You need to generate app password, and you can use that app password in .env file.
How to generate an App password:
Go to your Google Account
On the left navigation panel, click Security.
On the Signing in to Google panel, click App passwords.
(Note: If you can't get to the page, 2-Step Verification is:
Not set up for your account,
Set up for security keys only)
At the bottom, click Select app and choose the app you’re using.
Click Select device and choose the device you’re using.
Click Generate
Follow the instructions to enter the App password (the 16 character code in the yellow bar) on your device.
Click Done.
Once you are finished, you won’t see that App password code again.
Note: You may not be able to create an App password for less secure apps.
These settings worked for me instead.
MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME=myemail#gmail.com
MAIL_PASSWORD=mypassword
MAIL_ENCRYPTION=tls
You should try this:
MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME=youremailaddress#gmail.com
MAIL_PASSWORD=gtxajikwsqmlaqcr // your app password
MAIL_ENCRYPTION=tls

forget password not working in laravel 5

I tried to click on link forget password and it says email has been sent but I didn't receive email
I am using gmail smpt in db config
I have already tried to change the setting in .env file but still nothing
This is mail config
MAIL_DRIVER=mail
MAIL_HOST=smtp.gmail.com
MAIL_PORT=465
MAIL_USERNAME=username#gmail.com
MAIL_PASSWORD=password
MAIL_ENCRYPTION=ssl
This isn't working it only says email has been sent but I didn't receive mail
I have also allowed in gmail to use Allow less secure apps: ON
so that app can directly send mail
You said you are using smpt driver. but in configuration you have set to mail.
So, you need to set MAIL_DRIVER from mail to smtp as given below:
'MAIL_DRIVER=smtp`.
Which password you are using ? Is that password which you are using to get login to gmail server ?
If yes then go to Myaccount of gmail then go to sign in and security and go to App password and generate password for Mail App and use that password.
May be that works for you. Same is working for me. Also change the following settings in your .env file.
MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_ENCRYPTION=tls
I changed the value of MAIL_DRIVER from mail to sendmail in the .env file
MAIL_DRIVER=sendmail
MAIL_HOST=smtp.gmail.com
MAIL_PORT=465
MAIL_USERNAME=email#gmail.com
MAIL_PASSWORD=password
MAIL_ENCRYPTION=ssl
In account setting of gmail allow unsecured app to send mail works for me

Resources