laravel 邮件

本文使用qq邮箱

env邮件配置:

MAIL_FROM_ADDRESS = 17******92@qq.com
MAIL_FROM_NAME = listen~

MAIL_DRIVER=smtp
MAIL_HOST=smtp.qq.com
MAIL_PORT=465
MAIL_USERNAME=17*******2@qq.com
MAIL_PASSWORD= ****** //这个是你的qq授权码
MAIL_ENCRYPTION=ssl
MAIL_ENCRYPTION=ssl

1.创建邮件类

php artisan make:mail welcomeToMiya

2.修改welcomeToMiya.php视图

public function build()
{
    return $this->view('email.welcome');
}

3.使用

//发送邮件
Route::get('/mail',function(){
    \Illuminate\Support\Facades\Mail::to('2861166132@qq.com')->send(new \App\Mail\welcomeToLaravist());
});

4.传参 修改 welcomeToMiya.php

public $user;

public function __construct(User $user)
{
    $this->user = $user;
}

5.传参 修改 web.php

//发送邮件
Route::get('/mail',function(){
    $user = \App\User::find(1);
    \Illuminate\Support\Facades\Mail::to('2861166132@qq.com')->send(new \App\Mail\welcomeToLaravist($user));
}); 
posted @ 2017-09-01 17:13  miyaye  阅读(171)  评论(0编辑  收藏  举报