27.1 C
Pakistan
Saturday, July 27, 2024

PHP converts MJML to HTML

Spatie created the MJML PHP package, which uses PHP to convert MJML to HTML. A markup language called MJML was created to make creating responsive email templates less difficult. Semantic markup is used in templates, which are even responsive in Outlook.

use Spatie\Mjml\Mjml;
 
$mjml = <<<'MJML'
    <mjml>
      <mj-body>
        <mj-section>
          <mj-column>
            <mj-text invalid-attribute>Hello World</mj-text>
          </mj-column>
        </mj-section>
      </mj-body>
    </mjml>
    MJML;
 
$html = Mjml::new()->toHtml($mjml);

MJML uses the node version of the package behind the scenes; it does not have a PHP implementation to convert to HTML.

You can even use the mjml-sidecar package to compile MJML to HTML using Sidecar. 

With this package, all HTML conversions will take place in AWS Lambda, so you won’t need to have Node available on your server. Before using this package, you should become acquainted with the Documentation for MJML. You can find the documentation and MJML PHP package on GitHub at  spatie/mjml-php.

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest Articles