Search by

juaniquillo / mjml-backend-components

juaniquillo

Backend components for MJML

Package info

github.com/juaniquillo/mjml-backend-components

pkg:composer/juaniquillo/mjml-backend-components

Statistics

Installs: 6

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

v0.1.1 2026-10-23 15:45 UTC

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 default node driver
  • ext-v8js only if you opt into the v8js driver (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.