Laravel Swiftmailer Example

Mailable:

<?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:

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

    public function test_email(){
        $user = new \stdClass();
        $user->name = 'Rex';
        $user->email = '[email protected]';

        $result = Mail::to($user)->send(new RegMail($user));
    }