Laravel 10 Mailable Email Template Components Tutorial

Reading Time: 7 minutes

Inside this article we will see the concept i.e Laravel 10 Mailable Email Template Components Tutorial. Article contains the classified information i.e How to Customizable Markdown email templates.

Markdown Mailable Email Template Components are pre-built HTML components that can be used to create visually appealing and responsive email templates in Laravel using Markdown syntax.

Read More: Step-by-Step Guide to Change Email Subject in Laravel 10

Let’s get started.

Laravel Installation

Open terminal and run this command to create a laravel project.

composer create-project laravel/laravel myblog

It will create a project folder with name myblog inside your local system.

To start the development server of laravel –

php artisan serve


Assuming laravel already installed inside your system.

What are Markdown Mailable Email Template Components?

Markdown Mailable Email Template Components are pre-built HTML components that can be used to create visually appealing and responsive email templates in Laravel using Markdown syntax.

These components offer a collection of preconfigured elements, including buttons, headers, footers, and more, that can be easily added to your email design. These elements provide a quick and easy approach to build emails that seem professional, allowing you to save time and effort while creating and coding email templates.

These Laravel components can be readily modified to meet your unique requirements because they are created using the Blade syntax. To further streamline the process of generating and delivering emails, you can also create your own unique components and use them in your email templates.

Read More: How To Send Email in Laravel 10 Using Gmail SMTP Tutorial

Default Markdown Mailable Template File

We can create custom email template file to send emails. But Laravel has a default behaviour to generate markdown mailable template and it’s components.

Open project into terminal and run this artisan command.

$ php artisan make:mail TestMail --markdown=emails.sample-email

This command will create two files –

  • Mail class TestMail.php file inside /app/Http/Mail folder.
  • Markdown template sample-email.blade.php file inside /resources/views/emails folder.

Open sample-email.blade.php

# Introduction

The body of your message.

@component('mail::button', ['url' => ''])
Button Text

{{ config('') }}

This email template is used when we send any email via markdown. It contains a logo, a email header, a footer, a button etc. These components of markdown mailable email template makes more powerful feature for template customization.

Markdown Mailable Components

Laravel 10 mailable template system contains several components like Button, Panel, Table, etc. These components we can use in mail templates to create html layout for mail layout.

Read More: How To Create a Custom 404 Page in Laravel 10 Tutorial

Button Component

The button component renders a centered button link. It contains the view for a button i.e an anchor tag. To include a button simply write this component code.

@component('mail::button', ['url' => $url, 'color' => 'info']) 
     View Product 

Panel Component

The panel component renders the given block of text in a panel. Here is the simple which gives a panel view.

  This is a panel of Online Web Tutor

Table Component

The table component allows you to transform a Markdown table into an HTML table.. Simple code to create table component –

| Author           | Playlist         | Video Count  | 
| ---------------- |:----------------:| ------------:| 
| Sanjay           | Laravel          | 90           |  
| Online Web tutor | CodeIgniter 4    | 35           | 

Inside this pre defined mailable template we have only component based structure. Only we have to change the message within defined components.

But in case if we want to do more customization within components, in simple way not available. But we can do this in a different way.

Laravel provides the hidden components structure in format of code as well.

Publish Markdown Mailables Template Files

Export all of the Markdown mail components to application for customization,  use the vendor:publish artisan command.

Open project into terminal and run this artisan command.

$ php artisan vendor:publish --tag=laravel-mail

This command will publish the Markdown mail components to /resources/views/vendor/mail.

The mail directory will contain an html and a text directory, each containing their respective representations of every available component.

Now, we are free to customize these components however we like.

We need to customize this files only which automatically controls the ui of components.

Read More: Laravel 10 Eloquent Has One Through Relationship Tutorial

Logo Customization

Open header.blade.php from /resources/views/vendor/mail/html folder.

Add your own custom logo path into it. Have a look this image.

We hope this article helped you to learn about Laravel 10 Mailable Email Template Components Tutorial in a very detailed way.

Online Web Tutor invites you to try Skillshike! Learn CakePHP, Laravel, CodeIgniter, Node Js, MySQL, Authentication, RESTful Web Services, etc into a depth level. Master the Coding Skills to Become an Expert in PHP Web Development. So, Search your favourite course and enroll now.

If you liked this article, then please subscribe to our YouTube Channel for PHP & it’s framework, WordPress, Node Js video tutorials. You can also find us on Twitter and Facebook.