laravel 郵件

本文使用qq郵箱php

env郵件配置:web

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.建立郵件類ui

php artisan make:mail welcomeToMiya

2.修改welcomeToMiya.php視圖this

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

3.使用code

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

4.傳參 修改 welcomeToMiya.phpssl

public $user;

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

5.傳參 修改 web.phpget

//發送郵件
Route::get('/mail',function(){
    $user = \App\User::find(1);
    \Illuminate\Support\Facades\Mail::to('2861166132@qq.com')->send(new \App\Mail\welcomeToLaravist($user));
});
相關文章
相關標籤/搜索