PHPackages                             spatie/mjml-php - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Mail &amp; Notifications](/categories/mail)
4. /
5. spatie/mjml-php

ActiveLibrary[Mail &amp; Notifications](/categories/mail)

spatie/mjml-php
===============

Convert MJML to HTML using PHP

1.2.6(4mo ago)281936.1k↓23.8%158MITPHPPHP ^8.2CI passing

Since Aug 21Pushed 1w ago4 watchersCompare

[ Source](https://github.com/spatie/mjml-php)[ Packagist](https://packagist.org/packages/spatie/mjml-php)[ Docs](https://github.com/spatie/mjml-php)[ GitHub Sponsors](https://github.com/spatie)[ RSS](/packages/spatie-mjml-php/feed)WikiDiscussions main Synced 2d ago

READMEChangelog (10)Dependencies (4)Versions (20)Used By (8)

Convert MJML to HTML using PHP
==============================

[](#convert-mjml-to-html-using-php)

[![Latest Version on Packagist](https://camo.githubusercontent.com/00eca4e0a8a7ab253e9693fd2c3863c778753b611f6dafbb4eed50635a78640c/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f7370617469652f6d6a6d6c2d7068702e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/spatie/mjml-php)[![Tests](https://github.com/spatie/mjml-php/actions/workflows/run-tests.yml/badge.svg)](https://github.com/spatie/mjml-php/actions/workflows/run-tests.yml)[![Total Downloads](https://camo.githubusercontent.com/f96e84187faade4721e84cf64eca2294a426dce7f2feb8abb75c35261a48ab0b/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f7370617469652f6d6a6d6c2d7068702e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/spatie/mjml-php)

[MJML](https://mjml.io) is a markup language designed to reduce the pain of coding a responsive email. Our `mjml-php` package can convert MJML to HTML.

Here's an example of how to use our package:

```
use Spatie\Mjml\Mjml;

$mjml = minify()->toHtml($mjml);
```

These are all the methods you can call on the `Mjml` class:

- `minify()`: minify the HTML that is returned
- `beautify()`: beautify the HTML that is returned
- `hideComments()`: hide comments in the HTML that is returned
- `validationLevel(ValidationLevel $validationLevel)`: set the validation level to `strict`, `soft` or `skip`

Instead of using these dedicated methods, you could opt to pass an array with options as the second argument of the `toHtml` or `convert` method. You can use any of the options that are mentioned in the [MJML documentation for Node.js](https://github.com/mjmlio/mjml#inside-nodejs).

```
use Spatie\Mjml\Mjml;

// let's assume $mjml contains the MJML you want to convert
$minifiedHtml = Mjml::new()->minify()->toHtml($mjml, [
    'beautify' => true,
    'minify' => true,
]);
```

### Validating MJML

[](#validating-mjml)

You can make sure a piece of MJML is valid by using the `canConvert()` method.

```
use Spatie\Mjml\Mjml;

Mjml::new()->canConvert($mjml); // returns a boolean
```

If `true` is returned we'll be able to convert the given MJML to HTML. However, there may still be some errors while converting the MJML to HTML. These errors are not fatal and the MJML will still be converted to HTML. You can see these non-fatal errors when calling `errors()` on the `MjmlResult` instance that is returned when calling `convert`.

You can use `canConvertWithoutErrors` to make sure the MJML is both valid and that there are no non-fatal errors while converting it to HTML.

```
use Spatie\Mjml\Mjml;

Mjml::new()->canConvertWithoutErrors($mjml); // returns a boolean
```

### Specifying the path to nodejs executable

[](#specifying-the-path-to-nodejs-executable)

By default, the package itself will try to determine the path to the `node` executable. If the package can't find a path, you can specify a path in the environment variable `MJML_NODE_PATH`

```
MJML_NODE_PATH=/home/user/.nvm/versions/node/v20.11.0/bin
```

Sidecar
-------

[](#sidecar)

This package also supports running through [Sidecar](https://github.com/hammerstonedev/sidecar) in Laravel projects.

To use the `->sidecar()` method, a few extra steps are needed:

Install the Sidecar package:

```
composer require spatie/mjml-sidecar
```

Register the `MjmlFunction` in your `sidecar.php` config file.

```
/*
 * All of your function classes that you'd like to deploy go here.
 */
'functions' => [
    \Spatie\MjmlSidecar\MjmlFunction::class,
],
```

Deploy the Lambda function by running:

```
php artisan sidecar:deploy --activate
```

See the [Sidecar documentation](https://hammerstone.dev/sidecar/docs/main/functions/deploying) for details.

Testing
-------

[](#testing)

```
composer test
```

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](https://github.com/spatie/.github/blob/main/CONTRIBUTING.md) for details.

Security Vulnerabilities
------------------------

[](#security-vulnerabilities)

Please review [our security policy](../../security/policy) on how to report security vulnerabilities.

Credits
-------

[](#credits)

- [Freek Van der Herten](https://github.com/freekmurze)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

63

—

FairBetter than 99% of packages

Maintenance88

Actively maintained with recent releases

Popularity58

Moderate usage in the ecosystem

Community30

Small or concentrated contributor base

Maturity65

Established project with proven stability

 Bus Factor1

Top contributor holds 53.2% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~56 days

Recently: every ~97 days

Total

17

Last Release

144d ago

Major Versions

0.0.6 → 1.0.02023-08-25

PHP version history (2 changes)0.0.1PHP ^8.1

1.2.6PHP ^8.2

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/7535935?v=4)[Spatie](/maintainers/spatie)[@spatie](https://github.com/spatie)

---

Top Contributors

[![freekmurze](https://avatars.githubusercontent.com/u/483853?v=4)](https://github.com/freekmurze "freekmurze (82 commits)")[![riasvdv](https://avatars.githubusercontent.com/u/3626559?v=4)](https://github.com/riasvdv "riasvdv (28 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (18 commits)")[![github-actions[bot]](https://avatars.githubusercontent.com/in/15368?v=4)](https://github.com/github-actions[bot] "github-actions[bot] (9 commits)")[![Nielsvanpach](https://avatars.githubusercontent.com/u/10651054?v=4)](https://github.com/Nielsvanpach "Nielsvanpach (8 commits)")[![AlexVanderbist](https://avatars.githubusercontent.com/u/6287961?v=4)](https://github.com/AlexVanderbist "AlexVanderbist (2 commits)")[![Baspa](https://avatars.githubusercontent.com/u/10845460?v=4)](https://github.com/Baspa "Baspa (2 commits)")[![rrehbein](https://avatars.githubusercontent.com/u/140358?v=4)](https://github.com/rrehbein "rrehbein (2 commits)")[![stevebauman](https://avatars.githubusercontent.com/u/6421846?v=4)](https://github.com/stevebauman "stevebauman (1 commits)")[![thecaliskan](https://avatars.githubusercontent.com/u/13554944?v=4)](https://github.com/thecaliskan "thecaliskan (1 commits)")[![vladyslav-mikhieiev](https://avatars.githubusercontent.com/u/31040615?v=4)](https://github.com/vladyslav-mikhieiev "vladyslav-mikhieiev (1 commits)")

---

Tags

htmlmailmjmlphpspatiemjml-php

###  Code Quality

TestsPest

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/spatie-mjml-php/health.svg)

```
[![Health](https://phpackages.com/badges/spatie-mjml-php/health.svg)](https://phpackages.com/packages/spatie-mjml-php)
```

###  Alternatives

[matomo/matomo

Matomo is the leading Free/Libre open analytics platform

21.7k38.9k](/packages/matomo-matomo)[spatie/image

Manipulate images with an expressive API

1.4k60.7M188](/packages/spatie-image)[spatie/laravel-health

Monitor the health of a Laravel application

87512.0M164](/packages/spatie-laravel-health)[spatie/db-dumper

Dump databases

1.2k29.1M86](/packages/spatie-db-dumper)[spatie/flare-client-php

Send PHP errors to Flare

177161.5M23](/packages/spatie-flare-client-php)[tempest/framework

The PHP framework that gets out of your way.

2.2k34.4k15](/packages/tempest-framework)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
