This library is based on the open source Musimal responsive HTML email design and uses Fluent for PHP to elegantly construct an responsive email body with code instead of HTML markup.
Below is a sample of the Musimal email design and the various UI components
composer require fivesqrd/fluent-musimal fivesqrd/fluent-client
Certain aspects of the look can be customised by presetting some config parameters:
$options = array(
'logo' => 'My App', //Plain text or publicly available URL. Image not wider than 200px
'color' => '#ff6600', //Primary colour
'footer' => 'My test generated by Musimal for PHP', //Text at bottom of all messages
);
Create a responsive HTML message body:
/* Construct a message body using the Fluent Client */
$body = (new Fluent\Body())
->title('My little pony')
->paragraph('Lorem ipsum dolor sit amet, consectetur adipiscing elit.')
->number(['caption' => 'Today', value => date('j M Y')])
->button('http://www.mypony.com', 'Like my pony')
->paragraph('Pellentesque habitant morbi tristique senectus et netus et malesuada fames.');
/* Render the body to an HTML document */
$html = (new Fluent\Layout($options))->render($body);
Delivering the the message with Fluent for PHP. Rendering will be done server side, so the body object can be passed as is:
$body = (new Fluent\Body())
->title('My little pony')
->paragraph('Lorem ipsum dolor sit amet, consectetur adipiscing elit.')
->number(['caption' => 'Today', value => date('j M Y')])
->button('http://www.mypony.com', 'Like my pony')
->paragraph('Pellentesque habitant morbi tristique senectus et netus et malesuada fames.');
$messageId = (new Fluent\Delivery($config))->create()
->content($body)
->subject('Testing it')
->from('[email protected]', 'My App')
->to('[email protected]')
->send();
Sending the message in PHP
$body = (new Fluent\Body())
->title('My little pony')
->paragraph('Lorem ipsum dolor sit amet, consectetur adipiscing elit.')
->number(['caption' => 'Today', value => date('j M Y')])
->button('http://www.mypony.com', 'Like my pony')
->paragraph('Pellentesque habitant morbi tristique senectus et netus et malesuada fames.');
/* Render the body to an HTML document */
$html = (new Fluent\Layout($options))->render($body);
$headers = [
'MIME-Version: 1.0',
'Content-type: text/html; charset=iso-8859-1'
];
mail($to, $subject, $html, implode("\r\n", $headers));