laravel发送邮件

我们知道用`python`可以很方便的发送邮件,那么在`laravel`中该如何发送邮件呢

首先在`.env`中设置

>MAIL_DRIVER=smtp
MAIL_HOST=smtp.163.com
MAIL_PORT=25
MAIL_FROM_ADDRESS=test115@163.com
MAIL_FROM_NAME=ZM
MAIL_USERNAME=test115@163.com
MAIL_PASSWORD=MARVIMBVQRFLBXTLQC
MAIL_ENCRYPTION=null

然后在controller中

>use Illuminate\Support\Facades\Mail;
$url = 'http://www.yuanchengzhushou.cn';
$title = '测试邮件';
$to = 'yansiyu@163.com';
$flag = Mail::send('emails.test', ['name' => 'siyu', 'url' => $url], function ($message) use ($to, $title) {
// 发送
$message->to($to)->subject('【亲爱的程序猿】' . $title);
});

创建`resources`模板

    A+
发布日期:2020年11月02日  所属分类:未分类

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: