Download the PHP package kcs/mjml without Composer
On this page you can find all versions of the php package kcs/mjml. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package mjml
mjml-php
PHP extension that embeds MRML, the MJML rendering engine written in Rust, so that you can render MJML templates directly from PHP without shelling out to a CLI tool.
Documentation
The full documentation lives under troubleshooting.
To preview the site locally install MkDocs and run:
This command proxies to mkdocs serve using the navigation defined in mkdocs.yml.
Overview
- Native MJML rendering – compile templates into responsive HTML emails through a thin PHP wrapper around the Rust engine.
- File and stream support – render inline strings or files (including stream wrappers) through
renderandrenderFile. - Configurable output – control comments, custom fonts, and social icon URLs via constructor options.
- Exceptions-first API – failed renders surface as
Mjml\Exception\RenderException, enabling straightforward error handling.
Requirements
- PHP 8.0 or newer with the development headers (
php-dev,php-devel, or similar). - Rust toolchain with Cargo available in
PATH(the build usescargo build). - Build dependencies required by MRML, for example
build-essential,gcc,make,libclang-dev,openssl,libssl-dev, andgit. phpizeandphp-configfrom your PHP installation.
Note: On Alpine Linux install
php-dev,cargo,clang-dev,openssl-dev, andbuild-base. On Debian/Ubuntu useapt install php-dev rustc cargo build-essential libclang-dev libssl-dev.
Installation
Build from source
After installation, enable the extension in your php.ini (see Configuration). During development you can load the module from the build tree instead of running make install:
Composer / packaged distribution
The project is published as a Composer package (kcs/mjml). You can pull the extension into your project with:
PIE will place the extension artefact under the PHP extension directory (and enable it, if possible).
Configuration
Add one of the following lines to your PHP configuration:
When using PHP-FPM or Apache, restart the service so the new module is loaded.
Usage
render and renderFile both return an instance of Mjml\Email, exposing:
getTitle(): string|nullgetPreview(): string|nullgetBody(): string
Constructor options
Pass an associative array to new Mjml($options) to tweak the renderer:
| Option | Type | Default | Notes |
|---|---|---|---|
disable_comments |
bool |
false |
Non-boolean values raise a TypeError. When true, HTML comments emitted by MRML are stripped. |
social_icon_origin |
string |
https://www.mailjet.com/images/theme/v1/icons/ico-social/ |
Must be a non-empty string. Controls the base URL used by <mj-social-element> icons. |
fonts |
array<string, string> |
Mjml::defaultFonts() |
Keys are font names and values the font URL. Passing anything other than string keys/values triggers a validation error. |
Default fonts
Outputs an associative array similar to:
Troubleshooting
configure: error: cargo command missing– install Rust and ensurecargois in yourPATH.phpizenot found – install PHP development tools (apt install php-dev,dnf install php-devel, etc.).- Missing includes during rendering – check that the
mj-includepaths exist and that PHP has permission to read them (seetests/0001-include.phptfor an example layout). - Segmentation faults or crashes – rebuild in debug mode (
./configure --enable-cargo-debug && make clean && make) and open an issue with the failing template.
License
Licensed under the MIT License.
Contributing
- Fork the repository and create a feature branch.
- Build the extension locally (see Build from source).
-
Run the PHPT test suite before submitting a pull request:
Integration scenarios live under
tests/integration/. - Follow the existing coding style and commit conventions, then open a pull request.