Reputation: 56
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('[email protected]')
->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.
Upvotes: 2
Views: 8358
Reputation: 10111
Need to change your .env
file to something like this:
MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
[email protected]
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.
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.
Upvotes: 6
Reputation:
You should try this:
MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
[email protected]
MAIL_PASSWORD=gtxajikwsqmlaqcr // your app password
MAIL_ENCRYPTION=tls
Upvotes: 1
Reputation: 8750
These settings worked for me instead.
MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
[email protected]
MAIL_PASSWORD=mypassword
MAIL_ENCRYPTION=tls
Upvotes: 1