1. Go to this page and download the library: Download maize-tech/laravel-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/ */
maize-tech / laravel-mjml example snippets
use Maize\Mjml\Actions\APIConvert;
use Maize\Mjml\Actions\NodeConvert;
use Maize\Mjml\ConversionMode;
return [
/*
|--------------------------------------------------------------------------
| Conversion mode
|--------------------------------------------------------------------------
|
| Here you may specify the conversion mode you may wish to use.
| Available options are:
| - Maize\Mjml\ConversionMode::Node
| - Maize\Mjml\ConversionMode::API
| - Maize\Mjml\ConversionMode::Custom
|
| By default, the value is Maize\Mjml\ConversionMode::Node
|
*/
'mode' => ConversionMode::Node,
'node' => [
/*
|--------------------------------------------------------------------------
| Conversion action
|--------------------------------------------------------------------------
|
| Here you may specify the fully qualified class name of the conversion action.
| By default, the value is Maize\Mjml\Actions\ConvertMjml::class
|
*/
'action' => NodeConvert::class,
/*
|--------------------------------------------------------------------------
| Node options
|--------------------------------------------------------------------------
|
| Here you may specify the options to use when converting MJML to HTML.
| See available options at https://github.com/mjmlio/mjml#inside-nodejs
|
*/
'options' => [
'keepComments' => true,
'ignoreIncludes' => false,
'beautify' => false,
'minify' => false,
],
],
'api' => [
/*
|--------------------------------------------------------------------------
| Conversion action
|--------------------------------------------------------------------------
|
| Here you may specify the fully qualified class name of the conversion action.
| By default, the value is Maize\Mjml\Actions\ApiConvert::class
|
*/
'action' => APIConvert::class,
/*
|--------------------------------------------------------------------------
| API Authentication credentials
|--------------------------------------------------------------------------
|
| Here you may specify the basic auth credentials to use the MJML API.
|
*/
'auth_user' => env('MJML_API_AUTH_USER'),
'auth_password' => env('MJML_API_AUTH_PASSWORD'),
],
'custom' => [
/*
|--------------------------------------------------------------------------
| Conversion action
|--------------------------------------------------------------------------
|
| Here you may specify the fully qualified class name of the conversion action.
|
*/
'action' => null,
],
];
namespace App\Actions;
class MyConvert
{
public function __invoke(string $value): string
{
// convert $value (MJML) into HTML and return it
}
}
use Illuminate\Notifications\Notification;
use Maize\Mjml\MailMessage;
class OrderShipped extends Notification
{
public function via(object $notifiable): array
{
return ['mail'];
}
public function toMail(object $notifiable): MailMessage
{
return (new MailMessage)
->subject('Your order has shipped')
->greeting('Hello!')
->line('Your order is on its way.')
->action('Track your order', url('/orders/123'))
->line('Thank you for shopping with us!');
}
}
use Illuminate\Mail\Mailable;
class WelcomeMail extends Mailable
{
public function __construct(public string $name)
{
}
public function build(): self
{
return $this->view('emails.welcome', [
'name' => $this->name,
]);
}
}