Laravel发送电子邮件,配置和发送脚本 [英] Laravel send email, configuration and send script

查看:112
本文介绍了Laravel发送电子邮件,配置和发送脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的Lailavel电子邮件客户端有问题。
我需要通过点击按钮发送电子邮件。



我的代码:
.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,启用两步验证





创建一个应用并生成密码





在.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

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆