[Laravel Sail]メール送信備忘録

ファイル作成

sail artisan make:mail UserRegistered

 
Mail\UserRegistered.php
追記

public $user;

 
変更

public function content(): Content
{
    return new Content(
        view: 'mail.user_registered',
    );
}

 
resources\views\mail\user_registered.blade.php

<!DOCTYPE html>
<html lang="ja">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>ユーザー登録通知</title>
</head>
<body>
    {{ $user->name }}さんが登録しました。<br>
    <a href="{{route('dashboard')}}">dashboard</a>
 
</body>
</html>

 
app\Http\Controllers\Auth\RegisteredUserController.php
追記

use App\Mail\UserRegistered;
use Illuminate\Support\Facades\Mail;

変更storeメソッドのeventメソッド後に追記

Mail::to('送信先メアド')->send(new UserRegistered($user));