Mailable:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
<?php namespace App\Mail; use Illuminate\Bus\Queueable; use Illuminate\Mail\Mailable; use Illuminate\Queue\SerializesModels; use Illuminate\Contracts\Queue\ShouldQueue; use App\Models\Emails; class RegMail extends Mailable { use Queueable, SerializesModels; protected $user = null; protected $reg_email_id = 1; protected $mail_data = null; /** * Create a new message instance. * * @return void */ public function __construct($user) { // $this->user = $user; $this->mail_data = Emails::find($this->reg_email_id); } /** * Build the message. * * @return $this */ public function build() { $data = [ 'subject' => $this->mail_data->subject, 'msg' => $this->mail_data->msg, 'user' => $this->user ]; return $this->subject($data['subject']) ->view('reg_email') ->with($data); } } |
Controller:
1 2 3 4 5 6 7 8 9 10 |
use Illuminate\Support\Facades\Mail; use App\Mail\RegMail; public function test_email(){ $user = new \stdClass(); $user->name = 'Rex'; $user->email = 'xxx@gmail.com'; $result = Mail::to($user)->send(new RegMail($user)); } |