Bearer's avatar

Sending HTML mail?

Hello guys, someone know how to send email with html style? I have read this question But i dont want to send a simple string.

0 likes
2 replies
JillzTom's avatar
JillzTom
Best Answer
Level 10

You can do something like the following:

from your controller:

$user = User::where('username', 'john')->first();
Mail::to($user->email)->send(new Welcome($user));

and now:


namespace App\Mail;

use App\User;
use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;

class Welcome extends Mailable
{
    use Queueable, SerializesModels;

    public $user;

    public function __construct(User $user)
    {
        $this->user = $user;
    }

    public function build()
    {
        return $this->view('emails.welcome')
                    ->subject('Welcome to My App')
                    ->with(['name'=>$this->user->name]);
    }
}

and you can create a blade template for your html template in resources/views/emails/welcome.blade.php

Please or to participate in this conversation.