https://github.com/alekitto/mjml-php
PHP extension to render MJML emails
https://github.com/alekitto/mjml-php
email mjml mjml-to-html php php-ext php-extension
Last synced: 8 months ago
JSON representation
PHP extension to render MJML emails
- Host: GitHub
- URL: https://github.com/alekitto/mjml-php
- Owner: alekitto
- License: mit
- Created: 2024-12-04T23:31:34.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2025-05-29T22:22:17.000Z (9 months ago)
- Last Synced: 2025-06-09T22:07:05.176Z (8 months ago)
- Topics: email, mjml, mjml-to-html, php, php-ext, php-extension
- Language: Rust
- Homepage:
- Size: 71.3 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# mjml-php
PHP wrapper for [MRML](https://github.com/jdrouet/mrml), the [MJML](https://mjml.io) implementation in Rust.
Rust needs to be available to build this extension from source.
## Building, extending PHP
```sh
$ phpize
$ ./configure
$ make
$ make install
# in php.ini set extension=mjml.so or:
$ php -dextension=path-to-project/target/release/mjml.so
```
# PHP
```php
render('Hello world!');
echo $rendered; // Email-friendly HTML
```
## Classes and Methods
The extension exposes a `Mjml\Mjml` class to parse and render mjml into HTML. You can use the following methods:
- `public function render(string $mjml): Mjml\Email`: render a mjml string into HTML
- `public function renderFile(string $path): Mjml\Email`: read the specified file and render the mjml content into HTML (stream wrappers are supported).
- `public static function defaultFonts(): array`: returns a hashmap with the default fonts
`render` and `renderFile` methods return a `Mjml\Email` object which exposes the following methods:
- `public function getTitle(): string|null`: returns the content of the `` tag, if set
- `public function getPreview(): string|null`: returns the content of the `` tag, if present
- `public function getBody(): string`: returns the HTML email body
## Options
While constructing the Mjml object, you can pass an array with the following options:
| Option | Description | Default |
|--------------------|-----------------------------------------------------|-----------------------------------------------------------|
| disable_comments | If true, do not include comments in the HTML output | false |
| social_icon_origin | Base URL for mj-social-element images | https://www.mailjet.com/images/theme/v1/icons/ico-social/ |
| fonts | Key-value array of fonts used in the email body | See [default fonts](#default-fonts) |
### Default fonts
By default, this library uses the following fonts:
| Font name | URL |
|------------|--------------------------------------------------------------------|
| Open Sans | https://fonts.googleapis.com/css?family=Open+Sans:300,400,500,700 |
| Droid Sans | https://fonts.googleapis.com/css?family=Droid+Sans:300,400,500,700 |
| Lato | https://fonts.googleapis.com/css?family=Lato:300,400,500,700 |
| Roboto | https://fonts.googleapis.com/css?family=Roboto:300,400,500,700 |
| Ubuntu | https://fonts.googleapis.com/css?family=Ubuntu:300,400,500,700 |