- Can I replace Laravel’s SwiftMailer with Nette Mail without breaking existing Mailable classes?
- Yes, but you’ll need to adapt your code. Nette Mail doesn’t integrate natively with Laravel’s Mail facade, so you’d either wrap its `Message` objects in a custom facade or extend Laravel’s `Mailable` class to use Nette’s `Mailer` under the hood. Start by replacing `SwiftMailer` in `composer.json` and binding Nette’s `SmtpMailer` to Laravel’s container.
- How do I handle HTML emails with inline CSS in Laravel using Nette Mail?
- Nette Mail includes `CssInliner`, which automatically inlines CSS for better email client compatibility (like Outlook). Use it by calling `$message->setHtml($html)->inlineCss()`. For Blade templates, inline CSS before passing the HTML to Nette Mail. Test with tools like Litmus or Email on Acid to catch edge cases.
- Does Nette Mail support attachments and embedded images in Laravel?
- Absolutely. Attach files with `$message->addAttachment($filePath, $mimeType, $disposition)` and embed images via CID (Content-ID) using `$message->addEmbeddedImage()`. This works seamlessly with Laravel’s `Mailable` classes if you bridge them to Nette’s `Message` object. For Blade templates, ensure embedded images use the correct `cid:` syntax.
- What Laravel versions and PHP versions does Nette Mail support?
- Nette Mail v4.x requires **PHP 8.2+**, which aligns with Laravel 10/11. For older Laravel (8/9) on PHP 8.0/8.1, use **v3.x**. Check the [Nette Mail docs](https://github.com/nette/mail) for version-specific migration guides. If you’re stuck on PHP 7.1–8.0, v3.x is your only option, but it lacks CSS inlining and some modern features.
- How do I configure DKIM signing with Nette Mail in a Laravel app?
- Nette Mail supports DKIM via the `DkimSigner` class. Configure it by setting the selector, private key, and domain in your `Mailer` instance. For Laravel, bind the signed mailer to the container and inject it where needed. Example: `$mailer = new SmtpMailer($transport, new DkimSigner($selector, $privateKey, $domain));` Test DKIM with tools like [DKIM Core](https://dkimcore.org/).
- Is Nette Mail faster than SwiftMailer for high-volume Laravel email campaigns?
- Performance depends on your use case. Nette Mail’s `CssInliner` uses regex and DOM parsing, which can add ~5–10ms per email for complex HTML. Benchmark against SwiftMailer in staging, especially if sending thousands of emails. For pure SMTP delivery, Nette Mail is comparable—its overhead comes from MIME composition and CSS processing. Optimize by caching inlined CSS.
- Can I use Nette Mail alongside Laravel’s Mail facade for hybrid email sending?
- Yes, use a decorator pattern. Create a custom `Mailer` that delegates to both Nette Mail (for complex emails) and Laravel’s `SwiftMailer` (for simple cases). For example, inject a `FallbackMailer` that checks email complexity before choosing the transport. This avoids full replacement while leveraging Nette’s strengths for HTML/attachments.
- How do I test email templates (Blade + HTML) for compatibility with Nette Mail?
- Render Blade templates to HTML first, then validate with Nette Mail’s `CssInliner` and `Message` object. Use PHPUnit to mock the `Mailer` and assert attachments, embedded images, and headers. Tools like [MailHog](https://github.com/mailhog/MailHog) or [Mailtrap](https://mailtrap.io/) can preview emails before sending. Test edge cases like Outlook’s VML fallback manually.
- What are the alternatives to Nette Mail for Laravel, and when should I choose one over the other?
- Laravel’s default is **SwiftMailer**, which integrates natively but lacks CSS inlining and modern PHP features. For simpler needs, consider **PHPMailer** (more verbose but widely used). If you need **transactional emails at scale**, try **Mailgun’s or SendGrid’s PHP SDKs**. Choose Nette Mail if you prioritize **MIME compliance, CSS inlining, or PHP 8.2+ features** and are willing to handle integration manually.
- How do I handle SMTP fallbacks (e.g., Sendmail if SMTP fails) with Nette Mail in Laravel?
- Nette Mail’s `FallbackMailer` supports multiple transports. Configure it with an array of `Mailer` instances (e.g., `SmtpMailer`, `SendmailMailer`) in order of priority. In Laravel, bind this to the container and inject it where needed. Example: `$fallbackMailer = new FallbackMailer([$smtpMailer, $sendmailMailer]);` Log failures to monitor reliability.