1. Go to this page and download the library: Download kachar/zend-mjml 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/ */
$service = $this->getServiceLocator()->get('Service\Mjml');
$mjml = '
<mj-body>
<mj-section>
<mj-column>
<mj-image width="100" src="https://mjml.io/assets/img/logo-small.png"></mj-image>
<mj-divider border-color="#F45E43"></mj-divider>
<mj-text font-size="20px" color="#F45E43" font-family="helvetica">Hello {{ name }}</mj-text>
</mj-column>
</mj-section>
</mj-body>
';
// This is the final html to be sent to the recipients
$body = $service->renderMjml($mjml);
// You can replace simple variables inside the final output
$body = $service->renderMjml($mjml, [
'name' => 'direct example',
]);
// Sending the email
$email = $service->composeEmail($body);
$email->setTo('[email protected]');
$email->setSubject('Sample responsive MJML email');
$service->sendEmail($email);
// or
echo $body;
$service = $this->getServiceLocator()->get('Service\Mjml');
$view = new ViewModel();
$view->name = 'John Doe';
$view->setTemplate('mjml/plain.mjml');
// This is the final html to be sent to the recipients
$body = $service->renderView($view);
// Sending the email
$email = $service->composeEmail($body);
$email->setTo('[email protected]');
$email->setSubject('Sample responsive MJML email using ViewModel');
$service->sendEmail($email);
$view = new ViewModel();
// This will be replaced using str_replace in the final template
$view->name = 'PHP MJML Template';
// This will be replaced using php in the initial mjml template
$view->products = [
[
'name' => 'Ham',
'price' => '1.50',
'quantity' => 5,
],
[
'name' => 'Cheese',
'price' => '3.75',
'quantity' => 3,
],
[
'name' => 'Bread',
'price' => '5.00',
'quantity' => 10,
],
];
$view->setTemplate('mjml/php-mjml.pmjml');
// This is the final html to be sent to the recipients
$body = $service->renderView($view);
// Sending the email
$email = $service->composeEmail($body);
$email->setTo('[email protected]');
$email->setSubject('Sample responsive MJML email using PhpRenderer');
$service->sendEmail($email);
bash
$ php composer.phar update
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.