asahasrabuddhe/laravel-mjml

A package that enables using MJML with Laravel Mailables.
557,030 129
Install
composer require asahasrabuddhe/laravel-mjml
Latest Version:0.9.0
License:MIT
Last Updated:Apr 8, 2025
Links: GitHub  ·  Packagist
Maintainer: asahasrabuddhe

Laravel MJML

Build responsive e-mails easily using MJML and Laravel Mailables.

MJML

MJML is an awesome tool from MailJet that allows us to create responsive emails very easily. For more information on how to use it, head to their documentation here

Installation

To install this package, require this package using composer as follows:

composer require asahasrabuddhe/laravel-mjml

After composer installs the packages and all the dependencies, publish the package configuration using artisan command:

php artisan vendor:publish

Select the laravel-mjml in the list. You will also need to install the MJML CLI:

npm install --save mjml

Getting Started

  1. Create a view containing MJML in your resources/views directory.

  2. Create a mailable class using artisan command: php artisan make:mail MJMLEmail

  3. In the mailable class, replace

    use Illuminate\Mail\Mailable;

    with

    use Asahasrabuddhe\LaravelMJML\Mail\Mailable;

  4. For Laravel 8 and below, in the build method, use:

    public function build()
    {
        return $this->mjml('view.name')
    }
    

    For Laravel 9, in the content method:, use:

    public function content()
    {
        return new Content(
            view: $this->mjml('view.name')->buildMjmlView()['html'],
        );
    }
    

Configuration

By default, the package will automatically detect the path of the MJML CLI installed locally in the project. In case this does not happen or the MJML CLI is installed globally, please update the configuration file likewise.

That's it! You have successfully installed and configured the MJML package for use. Just create new views and use them in the mailables class.

Related Packages

doctrine/dbal

Powerful PHP database abstraction layer (DBAL) with many features for database s...

644,549,754 9,698
laravel/framework

The Laravel Framework.

598,760,099 34,966
laravel/tinker

Powerful REPL for the Laravel framework.

507,193,856 7,441
laravel/serializable-closure

Laravel Serializable Closure provides an easy and secure way to serialize closur...

423,477,751 607
nunomaduro/collision

Cli error handling for console/command-line PHP applications.

403,217,078 4,664

Version History

Version Released License
0.9.0 MIT
0.8.0 MIT
0.7.0
0.6.0
0.5.0