spatie/mjml-php
Convert MJML email markup to responsive HTML from PHP. Spatie’s mjml-php wraps the Node mjml compiler (Node 16+ required) and provides a simple API like Mjml::new()->toHtml($mjml) to render production-ready email HTML.
EmailService) or mailable classes (Laravel’s Mailable trait). Can abstract MJML-to-HTML conversion behind a facade or service provider.Mailable classes) via custom render() methods.SendEmailJob) for async processing.Str::limit() for long text, or CSS inlining for email clients like Gmail).Spatie\Mjml\Mjml as a singleton or context-bound instance.Mailable class with a renderMjml() method:
public function render(): string
{
return Mjml::new()->toHtml($this->mjmlTemplate);
}
Mail::macro('mjml', function ($mjml) {
return Mjml::new()->toHtml($mjml);
});
.mjml → .html assets).laravel-notification-channels).composer require spatie/mjml-php.php artisan vendor:publish.resources/views/emails/partials/header.mjml).spatie/mjml-php for breaking changes (MIT license allows forks if needed).<mj-button>, <mj-image>).Cache::remember()) for static MJML templates.SendEmailJob).| Failure Scenario | Mitigation | Detection |
|---|---|---|
| MJML parsing errors | Fallback to raw HTML or cached version. | Laravel exception logging. |
| Email client rendering issues | Maintain a fallback HTML version for critical emails. | Monitor open rates + user feedback. |
| High MJML processing latency | Implement caching and queue workers. | New Relic/Blackfire profiling. |
| MJML spec breaking changes | Pin package version or fork if needed. | GitHub watch for major releases. |
| Developer adoption resistance | Provide migration scripts (HTML → MJML) and incentives (e.g., faster turnaround). | Survey team feedback. |
How can I help you explore Laravel packages today?