PHP code example of spatie / mjml-php

1. Go to this page and download the library: Download spatie/mjml-php library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

spatie / mjml-php example snippets


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);

use Spatie\Mjml\Mjml;

// let's assume $mjml contains the MJML you want to convert

$html = Mjml::new()->toHtml($mjml);

use Spatie\Mjml\Mjml;

// let's assume $mjml contains the MJML you want to convert

$result = Mjml::new()->convert($mjml); // returns an instance of Spatie\Mjml\MjmlResult

use Spatie\Mjml\Mjml;

// let's assume $mjml contains the MJML you want to convert
$minifiedHtml = Mjml::new()->minify()->toHtml($mjml);

use Spatie\Mjml\Mjml;

// let's assume $mjml contains the MJML you want to convert
$minifiedHtml = Mjml::new()->minify()->toHtml($mjml, [
    'beautify' => true,
    'minify' => true,
]);

use Spatie\Mjml\Mjml;

Mjml::new()->canConvert($mjml); // returns a boolean

use Spatie\Mjml\Mjml;

Mjml::new()->canConvertWithoutErrors($mjml); // returns a boolean

/*
 * All of your function classes that you'd like to deploy go here.
 */
'functions' => [
    \Spatie\MjmlSidecar\MjmlFunction::class,
],
bash
composer 
shell
php artisan sidecar:deploy --activate