stayallive / laravel-mail-css-inliner
Inline the CSS of your Laravel HTML emails.
Fund package maintenance!
stayallive
Installs: 70 430
Dependents: 0
Suggesters: 0
Security: 0
Stars: 5
Watchers: 3
Forks: 115
Open Issues: 0
Requires
- php: ^8.0.2
- ext-dom: *
- laravel/framework: ^9||^10||^11.0
- tijsverkoyen/css-to-inline-styles: ^2.2
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.14
- phpunit/phpunit: ^9||^10
- symfony/mailer: ^6.0||^7.0
README
Why?
Most email clients won't render CSS (on a <link>
or a <style>
). The solution is inline your CSS directly on the HTML.
Doing this by hand easily turns into unmaintainable templates. The goal of this package is to automate the process of inlining that CSS before sending the emails.
How?
Using a wonderful CSS inliner package wrapped in a SwiftMailer plugin and served as a Service Provider it just works without any configuration. Since this is a SwiftMailer plugin, it will automatically inline your css when parsing an email template. You don't have to do anything!
Turns style tag:
<html> <head> <style> h1 { font-size: 24px; color: #000; } </style> </head> <body> <h1>Hey you</h1> </body> </html>
Or the link tag:
<html> <head> <link rel="stylesheet" type="text/css" href="./tests/css/test.css"> </head> <body> <h1>Hey you</h1> </body> </html>
Into this:
<html> <head> <style> h1 { font-size: 24px; color: #000; } </style> </head> <body> <h1 style="font-size: 24px; color: #000;">Hey you</h1> </body> </html>
Installation
This package requires at least Laravel 9
and PHP 8
.
Begin by installing this package through composer. Require it directly from the CLI to take the last stable version:
composer require stayallive/laravel-mail-css-inliner
At this point the inliner should be already working with the default options. If you want to fine-tune these options, you can do so by publishing the configuration file:
$ php artisan vendor:publish --provider='Stayallive\LaravelMailCssInliner\ServiceProvider'
and changing the settings on the generated config/mail-css-inliner.php
file.
Testing
composer test
Found a bug?
Please, let me know! Send a pull request or a patch. Questions? Ask! I will respond to all filed issues.
Contributing
Please see CONTRIBUTING for details.
Security
If you discover any security related issues, please email me@alexbouma.me instead of using the issue tracker.
Credits
This is a fork from fedeisas/laravel-mail-css-inliner.
The forked package is greatly inspired, and mostly copied, from SwiftMailer CSS Inliner.
License
The MIT License (MIT). Please see License File for more information.