内容へ移動
fl8 Wiki
ユーザ用ツール
ログイン
サイト用ツール
検索
ツール
文書の表示
以前のリビジョン
バックリンク
最近の変更
メディアマネージャー
サイトマップ
ログイン
>
最近の変更
メディアマネージャー
サイトマップ
現在位置:
Dokuwiki.fl8.jp
»
11_php
»
02_framework
»
01_laravel
»
30 Laravel Mail
トレース:
11_php:02_framework:01_laravel:30_laravel_mail
この文書は読取専用です。文書のソースを閲覧することは可能ですが、変更はできません。もし変更したい場合は管理者に連絡してください。
====== 30 Laravel Mail ====== Laravel でメール送信 ===== 1.設定ファイル.env ===== 設定はlaravel/config/mail.phpで行っていますが、実際の記述は.envファイルに記述する <code> MAIL_DRIVER=smtp MAIL_HOST=mail.hogehoge.net MAIL_PORT=25 MAIL_USERNAME=info@hogehoge.net MAIL_PASSWORD=hogepassword MAIL_ENCRYPTION=null </code> ===== 2.mailableクラスを生成 ===== php artisan make:mail MailSend 下記のファイルができる。 $ ll app/Mail/MailSend.php ===== 3.メール本文作成 ===== <code> $ cat resources/views/mail/MailSend.blade.php {{$content->name}} さんはじめまして。 テストメール </code> ===== 4.mailableクラスの変更 ===== <code|app/Mail/MailSend.php> <?php namespace App\Mail; use Illuminate\Bus\Queueable; use Illuminate\Mail\Mailable; use Illuminate\Queue\SerializesModels; use Illuminate\Contracts\Queue\ShouldQueue; class MailSend extends Mailable { use Queueable, SerializesModels; /** * Create a new message instance. * * @return void */ public function __construct($contact) { $this->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オプションでセットしたデータをテンプレートへ受け渡す } } </code> ===== 5.コントローラ設定 ===== <code> 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)); </code> {{tag>Laravel}}
11_php/02_framework/01_laravel/30_laravel_mail.txt
· 最終更新: 2022/01/14 09:34 by
matsui
ページ用ツール
文書の表示
以前のリビジョン
バックリンク
文書の先頭へ