fedeisas/laravel-mail-css-inliner
Mailable class lifecycle. It leverages Laravel’s event system (MailableSending) to intercept and modify emails before dispatch, making it a non-intrusive addition to existing email workflows.league/html-to-markup library under the hood, which is a battle-tested solution for HTML/CSS manipulation. This reduces custom risk while ensuring compatibility with modern email clients (e.g., Gmail, Outlook).config/app.php) is standard.MailableSending), which are stable and widely adopted.| Risk Area | Assessment | Mitigation Strategy |
|---|---|---|
| CSS Inlining Accuracy | Edge cases (e.g., dynamic CSS, media queries) may not inline perfectly. | Test with real email clients; use config['exclude'] to whitelist critical styles. |
| Performance Overhead | Inlining CSS adds CPU/memory overhead during email dispatch. | Benchmark with production-like loads; consider caching inlined templates. |
| Email Client Quirks | Some clients (e.g., Outlook) have idiosyncratic rendering. | Validate output with Email on Acid or Litmus. |
| Breaking Changes | Laravel 9+ dependency may block legacy projects. | Use v4.x for older stacks (PHP 7.4/Laravel 8) if needed. |
| Template Bloat | Inlined CSS increases HTML size, potentially triggering spam filters. | Monitor deliverability metrics; optimize templates pre-inlining. |
Mailable classes and Laravel’s event system. No need for middleware or custom routes.league/html-to-markup, which are widely supported.Mailable classes for CSS dependencies.MAIL_INLINE_CSS_ENABLED) to toggle inlining during rollout.| Component | Compatibility Notes |
|---|---|
| Laravel Versions | Tested on Laravel 9+; use v4.x for Laravel 8/PHP 7.4. |
| Email Libraries | Works with SwiftMailer (Laravel’s default) and custom mailers. |
| Template Engines | Supports Blade, Markdown, and raw HTML. |
| Queue Systems | Compatible with database queues, Redis, and SQS. |
| CSS Preprocessors | Assumes CSS is pre-compiled (e.g., via Laravel Mix/Vite). |
composer require fedeisas/laravel-mail-css-inliner
Publish config:
php artisan vendor:publish --provider="Fedeisas\MailCssInliner\MailCssInlinerServiceProvider"
MAIL_INLINE_CSS_ENABLED = true in .env.exclude rules in config/mail-css-inliner.php (e.g., exclude no-inline classes).config/mail-css-inliner.php.MailableSending event listeners.Mailable classes.Illuminate\Support\Facades\Cache).| Failure Scenario | Impact | Mitigation |
|---|---|---|
| Malformed HTML | Email fails to send. | Add validation in Mailable::build() or use a fallback template. |
| CSS Inlining Corruption | Styles render incorrectly. | Test with Litmus and roll back if needed. |
| Queue Worker Crash | Emails stuck in queue. | Implement retry logic with exponential backoff. |
| Configuration Missteps | Unintended CSS exclusion. | Use feature flags to toggle inlining per environment. |
How can I help you explore Laravel packages today?