Laravelで通知メールを送信するしくみとしてNotificationクラスがありますが、それでテキスト(平文)メールを送る方法です。
Notificationは非常に便利で、通知メールを送るための各機能が用意されています。
但し、基本的に送信するメールタイプはHTMLメールです。正しくは「HTMLメールが受け取れない環境の場合はテキストメールを送る」といった仕様のようでうすが、あまり理解できておりません。。
個人的には通知メールは確実に届けたいので、HTMLメールではなくテキストメールのみを送信するほうが良いと考えています。HTMLメールが崩れて読めない、メッセージが伝わらないでは困りますからね。
では、実際にテキストメールを送信する方法です。
例えば、新規Notificationクラス「SampleNotification」を作成する場合、artisanコマンドで作成することができます。
> php artisan make:notification SampleNotification
コマンドを実行すると、ファイル「…/app/Notifications/SampleNotification.php」が生成されます。デフォルトの内容は以下です。(コメントなど要点以外は省略しています)
namespace App\Notifications; use Illuminate\Bus\Queueable; use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Notifications\Messages\MailMessage; use Illuminate\Notifications\Notification; class SampleNotification extends Notification { use Queueable; public function via($notifiable) { return ['mail']; } public function toMail($notifiable) { return (new MailMessage) ->line('The introduction to the notification.') ->action('Notification Action', url('/')) ->line('Thank you for using our application!'); } }