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(3mo ago)272668.4k—5.9%16[1 PRs](https://github.com/spatie/mjml-php/pulls)8MITPHPPHP ^8.2CI passing

Since Aug 21Pushed 1mo 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 1mo 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://camo.githubusercontent.com/8bd3dba9775904854da362259e4592ddbcec79a8caed99c5ef97059f2f7f1d81/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f7370617469652f6d6a6d6c2d7068702f72756e2d74657374732e796d6c3f6272616e63683d6d61696e266c6162656c3d7465737473267374796c653d666c61742d737175617265)](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

62

—

FairBetter than 99% of packages

Maintenance86

Actively maintained with recent releases

Popularity57

Moderate usage in the ecosystem

Community30

Small or concentrated contributor base

Maturity64

Established project with proven stability

 Bus Factor1

Top contributor holds 54.1% 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

98d 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 (80 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] (15 commits)")[![Nielsvanpach](https://avatars.githubusercontent.com/u/10651054?v=4)](https://github.com/Nielsvanpach "Nielsvanpach (8 commits)")[![github-actions[bot]](https://avatars.githubusercontent.com/in/15368?v=4)](https://github.com/github-actions[bot] "github-actions[bot] (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

[spatie/laravel-failed-job-monitor

Get notified when a queued job fails

1.0k2.6M4](/packages/spatie-laravel-failed-job-monitor)[spatie/url-signer

Generate a url with an expiration date and signature to prevent unauthorized access

4422.3M16](/packages/spatie-url-signer)[spatie/laravel-url-signer

Laravel implementation of spatie/signed-url

717784.1k3](/packages/spatie-laravel-url-signer)[spatie/laravel-database-mail-templates

Render Laravel mailables using a template stored in the database.

446762.6k7](/packages/spatie-laravel-database-mail-templates)[spatie/laravel-slack-slash-command

Make a Laravel app respond to a slash command from Slack

254601.2k2](/packages/spatie-laravel-slack-slash-command)[spatie/laravel-notification-log

Log notifications sent by your Laravel app

207902.8k](/packages/spatie-laravel-notification-log)

PHPackages © 2026

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