简体   繁体   English

Laravel发送电子邮件,配置和发送脚本

[英]Laravel send email, configuration and send script

I have a problem with my laravel email client. 我的laravel电子邮件客户端有问题。 I need to send email by click button. 我需要通过单击按钮发送电子邮件。

my code: .env 我的代码:.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 在Gmail帐户中

My account > Sign In And Security > Sign In to google, enable two step verification 我的帐户>登录和安全>登录到Google,启用两步验证

Create One App and generate password 创建一个应用程序并生成密码

In your .env file 在您的.env文件中

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 然后运行php artisan config:cache

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM