wai/emails

Email Templates for Laravel 5.5+

1.2.5 2020-06-18 09:07 UTC

This package is auto-updated.

Last update: 2024-10-29 05:10:49 UTC


README

A package for the Laravel Framework for creating blade emails.

Basic Example
  $email = \Wai\Emails\Email::create('emails.default')->setTheme('default')->strict();

  $email->emailBackgroundColor = '#000';
  
  $email->returnView($context);

Installation

Install the package via composer

composer require wai/emails

If using Laravel 5.1 to 5.4, Register the ServiceProvider and (optionally) the Facade

// config/app.php

'providers' => [
    ...
    Wai\Emails\EmailServiceProvider::class

];

Next, publish the config file with the following artisan command.

php artisan vendor:publish --provider="Wai\Emails\EmailServiceProvider"

or if using Laravel 5.5

php artisan vendor:publish

Views

After publishing the blade files from the package to your project. You should have a default email blade that includes various email building blocks. These building blocks are used to create your own custom email that is supported on most email clients.

Building blocks include:

  • Full width image
  • Background Image with Text/Button Overlay
  • Image with text/button
  • Text only
  • Three column layout with image/text/button
  • Two column layout with image/text/button
  • Left/Right thumbnail layout with image/text/button
  • Full bleed sections on top and/or bottom of email
  • Footer and header
  • Multiple inline images
  • Spacer

So if you want to create a custom email, just copy the default email blade, and start adding/removing building blocks.

Theme

This package also allows you to customize email elements like background colors, text font size and colors, etc.

To customize any of these values, you can either manually override the default value in the blade or set the value in the context passed to the blade.

For example:

In Controller:

$email = \Wai\Emails\Email::create('emails.default')->setTheme('default')->strict();

$email->emailBackgroundColor = '#000'; // Will change the email background color to Black

return $email->returnView($context);

List of changeable properties:

  • h1Color
  • h1FontSize
  • h1FontWeight
  • h1Margin
  • h1TextAlign
  • h2Color
  • h2FontSize
  • h2FontWeight
  • h2Margin
  • h3TextAlign
  • h3Color
  • h3FontSize
  • h3FontWeight
  • h3Margin
  • h3TextAlign
  • h4Color
  • h4FontSize
  • h4FontWeight
  • h4Margin
  • h4TextAlign
  • h5Color
  • h5FontSize
  • h5FontWeight
  • h5Margin
  • h5TextAlign
  • h6Color
  • h6FontSize
  • h6FontWeight
  • h6Margin
  • h6TextAlign
  • pColor
  • pFontSize
  • pFontWeight
  • pMargin
  • pTextAlign
  • buttonColor
  • buttonHoverColor
  • buttonTextColor
  • buttonFontSize
  • buttonBorderRadius
  • emailBackGroundColor
  • emailBodyBackgroundColor
  • emailElementBackgroundColor
  • webfontUrl
  • webfontName
  • fullBleedTopShow
  • fullBleedTopBackgroundColor
  • fullBleedTopText
  • fullBleedTopTextColor
  • fullBleedTopTextFontSize
  • fullBleedTopTextPadding
  • fullBleedTopTextAlign
  • fullBleedTopImgFullWidth
  • fullBleedTopImgUrl
  • fullBleedTopImgHref
  • fullBleedTopImgWidth
  • fullBleedTopImgHeight
  • fullBleedTopImgPadding
  • fullBleedTopImgAlt
  • fullBleedTopImgAltBackgroundColor
  • fullBleedTopImgAltColor
  • fullBleedBottomShow
  • fullBleedBottomBackgroundColor
  • fullBleedBottomText
  • fullBleedBottomTextColor
  • fullBleedBottomTextFontSize
  • fullBleedBottomTextPadding
  • fullBleedBottomTextAlign
  • fullBleedBottomImgFullWidth
  • fullBleedBottomImgUrl
  • fullBleedBottomImgHref
  • fullBleedBottomImgWidth
  • fullBleedBottomImgHeight
  • fullBleedBottomImgPadding
  • fullBleedBottomImgAlt
  • fullBleedBottomImgAltBackgroundColor
  • fullBleedBottomImgAltColor
  • headerShow
  • headerImgFullWidth
  • headerImgAlign
  • headerImgUrl
  • headerImgHref
  • headerImgWidth
  • headerImgHeight
  • headerImgPadding
  • headerImgTopSpacerHeight
  • headerImgBottomSpacerHeight
  • headerImgElementBackgroundColor
  • headerImgAlt
  • headerImgAltBackgroundColor
  • headerImgAltColor
  • footerShow
  • footerBackgroundColor
  • footerViewAsWebPageUrl
  • footerViewAsWebPageColor
  • footerViewAsWebPageTextDecoration
  • footerViewAsWebPageText
  • footerUnsubscribeUrl
  • footerUnsubscribeColor
  • footerUnsubscribeTextDecoration
  • footerUnsubscribeText
  • footerCustomText
  • footerTextPadding
  • footerTextFontSize
  • footerTextAlign
  • footerTextColor

In Blade:

@include('emails.sections.text_block', [
    'background' => $settings->email->elementBackgroundColor,
    'text' => 'Maecenas sed ante pellentesque, posuere leo id, eleifend dolor. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Praesent laoreet malesuada cursus. Maecenas scelerisque congue eros eu posuere. Praesent in felis ut velit pretium lobortis rhoncus ut erat.',
    'textPadding' => '40px',
    'textColor' => $settings->p->color,
    'textAlign' => 'left',
    'textFontSize' => $settings->p->fontSize
])

Finally to send the email you just pass the blade to Laravel Mail:

$email = \Wai\Emails\Email::create('emails.default')->setTheme('default')->strict();

$subject = 'Testing Blade Emails';
$to = 'Example';

$settings->send($context, function ($m) use ($subject, $to) {
    $m->to('info@example.com', $to);
    $m->subject($subject);
});

License

The MIT License (MIT). Please see License File for more information.