Laravel发送电子邮件,配置和发送脚本 [英] Laravel send email, configuration and send script
本文介绍了Laravel发送电子邮件,配置和发送脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要通过点击按钮发送电子邮件。
我的代码:
.env
MAIL_DRIVER = smtp
MAIL_HOST = mail.somedomain.com
MAIL_PORT = 587
MAIL_USERNAME=test@somedomain.com
MAIL_PASSWORD = 123456
MAIL_ENCRYPTION = null
我认为这是很好的配置,当然我使用我的域:)
下一个控制器我有这样的代码:
Mail :: send('home',array('firstname'=>fname),function($ message){
$ message-> to(testsend@somedomain.com) - > ;主题(欢迎来到Laravel);
});
网站正常开启,但电子邮件不发送
解决方案
在Gmail帐户中
我的帐户>登录和安全>登录到google,启用两步验证
- http:// i。 prntscr.com/7c849cb520e84f02b39216f3662590bc.png
- http:/ /i.prntscr.com/cc52e9b8e7c2472496f1e2d2ec8185f8.png
创建一个应用并生成密码
在.env文件中
MAIL_DRIVER = smtp
MAIL_HOST = smtp.gmail.com
MAIL_PORT = 587
MAIL_USERNAME=myemail@gmail.c om
MAIL_PASSWORD = apppassword //这是从gmail应用程序密码创建的
MAIL_ENCRYPTION = tls
然后运行 php artisan config:cache
I have a problem with my laravel email client. I need to send email by click button.
my code: .env
MAIL_DRIVER=smtp
MAIL_HOST=mail.somedomain.com
MAIL_PORT=587
MAIL_USERNAME=test@somedomain.com
MAIL_PASSWORD=123456
MAIL_ENCRYPTION=null
I think it is good configuration, of course i'm using my domain :)
next in controller I have code like this:
Mail::send('home', array('firstname' => "fname"), function($message){
$message->to("testsend@somedomain.com")->subject('Welcome to the Laravel');
});
Website is open normally but email not send
解决方案
In Gmail account
My account > Sign In And Security > Sign In to google, enable two step verification
- http://i.prntscr.com/7c849cb520e84f02b39216f3662590bc.png
- http://i.prntscr.com/cc52e9b8e7c2472496f1e2d2ec8185f8.png
Create One App and generate password
In your .env file
MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME=myemail@gmail.com
MAIL_PASSWORD=apppassword // this is created from gmail app password
MAIL_ENCRYPTION=tls
And Then run php artisan config:cache
这篇关于Laravel发送电子邮件,配置和发送脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文