juaniquillo / mjml-backend-components
Backend components for MJML
Package info
github.com/juaniquillo/mjml-backend-components
pkg:composer/juaniquillo/mjml-backend-components
Requires
- php: ^8.3
- illuminate/support: ^12.0|^13.0
- juaniquillo/laravel-backend-component: ^0.9.1||^0.10.0
- symfony/process: ^7.0|^8.0
Requires (Dev)
- laravel/pint: ^1.0
- orchestra/testbench: ^10.0|^11.0
- pestphp/pest: ^3.0
- phpstan/phpstan: ^2.0
- rector/rector: ^2.0
Suggests
- ext-v8js: Allows hyper-fast, in-memory MJML rendering directly inside the PHP process without spawning Node shell commands.
Provides
None
Conflicts
None
Replaces
None
This package is auto-updated.
Last update: 2026-10-23 15:46:41 UTC
README
Build responsive HTML emails from PHP. Compose MJML layouts in backend code, compile them via a JavaScript pipeline, and render standard production-ready HTML email output.
Requirements
- PHP ^8.3
- Laravel 12 or 13
- Node.js plus the MJML CLI (
npm install -g mjml) for the defaultnodedriver ext-v8jsonly if you opt into thev8jsdriver (suggested, not required)
Installation
Install the package via Composer:
composer require juaniquillo/mjml-backend-components
Publish the configuration file using:
php artisan vendor:publish --tag=mjml-backend-components-config
Tip
Laravel Boost Skill
If you use Laravel Boost, install the AI skill:
php artisan boost:add-skill https://github.com/juaniquillo/mjml-backend-components
Usage
Assemble components with the fluent builder, inspect the intermediate MJML with toHtml(), and compile to responsive HTML with renderHtml():
use Juaniquillo\MjmlBackendComponents\Builders\MjmlComponentBuilder; use Juaniquillo\MjmlBackendComponents\Enums\MjmlComponentEnum; $email = MjmlComponentBuilder::document([ MjmlComponentBuilder::head([ MjmlComponentBuilder::preview('Your weekly digest'), ]), MjmlComponentBuilder::make(MjmlComponentEnum::BODY)->setContents([ MjmlComponentBuilder::section( [MjmlComponentBuilder::text('Hello!', ['color' => '#333'])], ['background-color' => '#ffffff'] ), ]), ]); $mjml = $email->toHtml(); // raw MJML markup $html = $email->renderHtml(); // production HTML email
The builder has shorthands for common elements (document, head, preview, font, attributes, style, section, text). Any other MjmlComponentEnum case (e.g. BODY, COLUMN, IMAGE, BUTTON) is built through the generic MjmlComponentBuilder::make() path with setContents(), setContent(), setAttributes(), and setAttribute().
Compiler drivers
config/mjml-backend-components.php selects the driver via MJML_COMPILER (default node):
| Driver | Config key | Environment |
|---|---|---|
node |
drivers.node |
MJML_NODE_BINARY (default npx), runs mjml -s as an isolated process |
v8js |
drivers.v8js |
MJML_JS_PATH (path to a bundled mjml.js), in-memory compilation via ext-v8js |
| custom | any key | point class at your own CompilesMjml implementation |
Testing
composer test:unit # Pest suite composer analyse # PHPStan composer lint:check # Pint (check mode) composer rector:check # Rector (dry run) composer qa # all of the above
Contributing
Please read CONTRIBUTING.md before submitting a pull request.
License
MIT. See LICENSE.md.