====== 30 Laravel Mail ====== Laravel でメール送信 ===== 1.設定ファイル.env ===== 設定はlaravel/config/mail.phpで行っていますが、実際の記述は.envファイルに記述する MAIL_DRIVER=smtp MAIL_HOST=mail.hogehoge.net MAIL_PORT=25 MAIL_USERNAME=info@hogehoge.net MAIL_PASSWORD=hogepassword MAIL_ENCRYPTION=null ===== 2.mailableクラスを生成 ===== php artisan make:mail MailSend 下記のファイルができる。 $ ll app/Mail/MailSend.php ===== 3.メール本文作成 ===== $ cat resources/views/mail/MailSend.blade.php {{$content->name}} さんはじめまして。 テストメール ===== 4.mailableクラスの変更 ===== contact = $contact; } /** * Build the message. * * @return $this */ public function build() { return $this->from('info@hogehoge.com') // 送信元 ->subject('メールたいとる') // メールタイトル ->text('mail.MailSend') // どのテンプレートを呼び出すか ->with(['contact' => $this->contact]); // withオプションでセットしたデータをテンプレートへ受け渡す } } ===== 5.コントローラ設定 ===== use App\Mail\MailSend; use Illuminate\Support\Facades\Mail; $contents->name = $request->get('name'); Mail::to('to@hogehoge.net') ->bcc('bcc@hogehoge.net') ->send(new VpsDiskusageMail($contents)); {{tag>Laravel}}