bweston92/laravel-inline-css-mailer

This package is abandoned and no longer maintained. No replacement package was suggested.
There is no license information available for the latest version (v0.1) of this package.

Laravel CSS to Inline HTML.

v0.1 2015-02-19 14:20 UTC

This package is not auto-updated.

Last update: 2017-10-23 14:44:35 UTC


README

Installation

Just require the package and you're good to go! There is one core issue and that's Laravel doesn't allow sending plain HTML e-mails with-out it being a view, so you need to create a view file like below.

views/emails/raw.blade.php

{{ $content }}

Dependencies

This is just a wrapper for Laravel around the actual CSS inliner package found at https://github.com/tijsverkoyen/CssToInlineStyles

examples.php

class MyEmailSender {

    /**
     * @var \BW\L4CssInline\CssInlineMailer
     */
    protected $mailer;

    /**
     * @param \BW\L4CssInline\CssInlineMailer $mailer
     */
    public function __construct(CssInlineMailer $mailer)
    {
        $this->mailer = $mailer;
    }

    /**
     * This example assumes there is a style tag in the view.
     * 
     * @param NotificationInterface $notification
     */
    public function sendNotification(NotificationInterface $notification)
    {
        $this->mailer->send('emails.notification', compact('notification'), function($message) use ($notification)
        {
            $message->to($notification->getUser()->email);
        });
    }

    /**
     * This example is passing css into the mailer.
     * 
     * @param UserInterface $$user
     */
    public function sendWelcomeEmail(UserInterface $user)
    {
        $this->mailer->addCss(new \BW\L4CssInline\CssCapture\RawCapture('body {background: #000;}'));

        $this->mailer->send('emails.welcome-user', compact('user'), function($message) use ($user)
        {
            $message->to($user->email, $user->fullName);
        });
    }

}

Wait whats captures?

The CSS is found in multiple places, in code, local files, remote files over http, remote files ftp? This package comes with a raw capture and a file capture. Your own implementation for other methods will probably be better, just implement the capture interface.

  • Raw new \BW\L4CssInline\Capture\RawCapture('body {background: #000;}')
  • Local file new \BW\L4CssInline\Capture\FileCapture('/var/www/css/styles.css')

(All the CSS in style tags will be parsed aswell)

Contributing

Just stick to the standards which is the same as Laravel's code base.

License

This package open-sourced software licensed under the MIT license