Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Mjml Php Laravel Package

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.

View on GitHub
Deep Wiki
Context7

Convert MJML to HTML using PHP

Frequently asked questions about Mjml Php
How do I install spatie/mjml-php in a Laravel project?
Run `composer require spatie/mjml-php` to install the PHP package. You’ll also need Node.js 16+ and the `mjml` npm package installed (`npm install mjml` or `yarn add mjml`). Ensure Node is available globally or in your project’s environment.
What Laravel versions does spatie/mjml-php support?
The package is compatible with Laravel 10 and 11, as it requires PHP 8.2+. Always check the package’s [release notes](https://github.com/spatie/mjml-php/releases) for updates, especially if upgrading Laravel or PHP versions.
Can I use MJML templates with Laravel’s Mailable classes?
Yes. Override the `render()` method in your Mailable class to return `Mjml::new()->toHtml($mjmlString)`. Alternatively, use a mail macro to auto-convert MJML in templates, like `Mail::macro('mjml', fn($mjml) => Mjml::new()->toHtml($mjml));`.
How do I handle invalid MJML markup or errors during conversion?
The package throws exceptions for invalid MJML. Catch these exceptions and return a fallback HTML string or log the error for debugging. For graceful degradation, validate MJML templates in CI or use a pre-flight check before sending emails.
Is there a performance impact when converting MJML to HTML in bulk?
Converting MJML to HTML involves Node.js execution, which can be slow for high-volume emails. Cache the compiled HTML (e.g., using Laravel’s cache) or process conversions asynchronously with queueable jobs to mitigate performance issues.
Can I integrate MJML Live Preview with Laravel Mix or Vite?
Yes. Use Laravel Mix or Vite to compile MJML files during build time (e.g., `.mjml` → `.html` assets). This allows frontend developers to preview MJML templates locally before they’re processed in PHP. Configure this in your `webpack.mix.js` or `vite.config.js`.
Are there alternatives to spatie/mjml-php for Laravel email templating?
Alternatives include using Blade templates directly for HTML emails or packages like `laravel-mailables` for reusable email components. However, MJML is uniquely optimized for responsive emails, reducing manual CSS/HTML work. For Node.js-based solutions, consider `mjml` CLI directly or `nodemailer` with MJML.
How do I test MJML-to-HTML conversion in Laravel’s test suite?
Use Pest or PHPUnit to assert the output of `Mjml::new()->toHtml($mjml)` matches expected HTML. Compare snapshots or validate against known-good MJML examples. The package includes tests, so review them for patterns (e.g., `tests/Feature/MjmlTest.php`).
Does spatie/mjml-php support dynamic MJML templates (e.g., variables, loops)?
Yes, but dynamic logic must be handled in PHP before passing MJML to the converter. Use Blade or string interpolation to inject dynamic content into MJML strings. For complex cases, consider pre-processing MJML with a custom parser or template engine.
How do I handle email client-specific quirks (e.g., Outlook, Gmail) with MJML?
MJML generates widely compatible HTML, but some clients (like Outlook) may need adjustments. Post-process the HTML with Laravel’s `Str::limit()` or inline CSS tools like `juice` or `premailer`. Test rendered emails in Litmus or Email on Acid for client-specific fixes.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
milesj/emojibase
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport