Download the PHP package shyim/mjml-php without Composer
On this page you can find all versions of the php package shyim/mjml-php. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download shyim/mjml-php
More information about shyim/mjml-php
Files in shyim/mjml-php
Package mjml-php
Short Description Native PHP port of MJML - the email template engine
License MIT
Informations about the package mjml-php
MJML-PHP
Native PHP port of MJML — the markup language for responsive HTML emails.
MJML-PHP converts MJML markup into responsive HTML that works across all major email clients, including Outlook. No Node.js dependency required.
Requirements
- PHP 8.2+
ext-domext-libxml
Installation
Usage
Basic
With Options
Custom Components
CLI
A small dependency-free CLI is exposed as Composer bin mjml-php:
Useful options:
Run vendor/bin/mjml-php --help for all options.
Supported Components
Structure
mj-body— Email body containermj-section— Horizontal section with background image/color support and Outlook VMLmj-column— Responsive column with auto-width distributionmj-group— Non-responsive column groupingmj-wrapper— Section wrapper with gap support
Content
mj-text— Styled text blockmj-image— Responsive image with srcset/sizes and fluid-on-mobilemj-button— Call-to-action buttonmj-divider— Horizontal rulemj-spacer— Vertical spacingmj-table— HTML table passthroughmj-raw— Raw HTML passthrough
Interactive
mj-accordion— Expandable/collapsible sections (CSS-only, no JavaScript)mj-carousel— Image carousel (CSS radio-button technique)mj-navbar— Navigation bar with responsive hamburger menumj-hero— Full-width hero section with VML background for Outlookmj-social— Social media icons (17 built-in networks)
Head
mj-title— Email titlemj-preview— Preview textmj-attributes— Default attribute values andmj-classdefinitionsmj-font— Web font importsmj-style— Custom CSS (inline or in<style>tag)mj-breakpoint— Mobile responsive breakpointmj-html-attributes— Custom HTML attributes via CSS selectors
Validation
MJML-PHP validates your markup and throws a ValidationException on errors:
- Strict (default) — Validate and throw
ValidationExceptionon errors - Soft — Validate but do not throw; errors are exposed via
$result->errors - Skip — No validation
Exception Model
All library exceptions extend MjmlPHP\MjmlException, so you can catch them with a single catch:
MjmlException extends \RuntimeException, so existing catch (\RuntimeException $e) blocks still work.
Security
Input is trusted. MJML markup is treated as a template authored by you, not as end-user input. Do not concatenate untrusted strings into MJML markup — attribute values flow into the rendered HTML without HTML-escaping, the same as the official JS MJML.
Defensive measures the renderer already applies:
- URL attributes (
href,src,background,action,formaction,poster) pass through a scheme allowlist.javascript:,vbscript:,file:, and similar are rewritten to#. Onlyhttp,https,mailto,tel,sms,ftp,cid, anchor fragments, protocol-relative URLs, and relative paths pass through.data:image/*is allowed for inline images. mj-fontURLs that are nothttp/https/protocol-relative are dropped instead of being emitted into<link>/@import.mj-includeis disabled by default (unlike the JS MJML CLI). When enabled (ignoreIncludes: false), included paths are jailed under the current file's directory plus any explicitincludePathroots, withrealpathresolution, null-byte / URL-encoded-traversal rejection, and circular-include detection.- libxml is invoked with
LIBXML_NONET(no network access). Under PHP 8 / libxml ≥ 2.9, external entities are not resolved by default, so this parser is not vulnerable to XXE.
If you must interpolate user data into MJML, escape it yourself before passing it to the renderer (htmlspecialchars for text content; URL-encode parameters you put into href query strings).
MJML Compatibility
This is a native PHP port aligned with MJML 5.2.1. The HTML output is tested against the original JavaScript implementation using snapshot tests to ensure identical rendering. A CI job re-renders the snapshot fixtures with [email protected] and fails on drift, so if the upstream JS package publishes a patch you may see CI failures — open an issue and regenerate the fixtures.
Limitations
- CSS
@importinlining: The CSS inliner does not resolve@importdirectives found in inline style blocks. This matches the behavior of the JS MJML reference implementation for email-safe output. - CSS shorthand parsing: Only
padding,margin, andbordershorthands are fully supported for width calculation. More exotic shorthand properties (e.g.,border-radiuswith/syntax) are passed through as-is.
Development
Fixture Tests
Small render and validation cases can be added as .test files under tests/Fixtures/.
Use labeled sections:
For simple render fixtures, the legacy shorthand is also supported:
Regenerating Snapshot References
The snapshot test fixtures compare PHP output against reference HTML generated by the JS MJML CLI. To regenerate:
License
MIT
All versions of mjml-php with dependencies
ext-dom Version *
ext-libxml Version *
tijsverkoyen/css-to-inline-styles Version ^2.2