我想在我的网站上与我们联系页面,我已经成功地通过mailtrap进行了操作,但是当我想通过gmail smtp服务器发送邮件时,我什么也没收到,也没有收到任何错误. 这是我的.env邮件配置:
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 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') ->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é'); }谢谢.
推荐答案需要将您的.env文件更改为以下内容:
Need to change your .env file to something like this:
MAIL_DRIVER=smtp MAIL_HOST=smtp.gmail MAIL_PORT=587 MAIL_USERNAME=myemail@gmail MAIL_PASSWORD=apppassword MAIL_ENCRYPTION=tls完成.env编辑后,请在您的终端中输入以下命令以清除缓存:
After completion of .env edit please enter this command in your terminal for clear cache:
php artisan config:cache您需要生成应用密码,并且可以在.env文件中使用该应用密码.
You need to generate app password, and you can use that app password in .env file.
如何生成应用密码:
转到您的 Google帐户
在左侧导航面板上,单击安全性.
On the left navigation panel, click Security.
在登录到 Google 面板上,单击应用密码. (注意:如果您无法进入页面,则两步验证为: 未设置您的帐户, 仅设置安全密钥)
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.
更多推荐
如何通过gmail smtp与laravel发送邮件?
发布评论