- Can I use Nette/Mail to replace Laravel’s default SwiftMailer without breaking existing email logic?
- Yes, Nette/Mail is a drop-in replacement. Bind it in `MailServiceProvider` and Laravel’s `Mail::send()` methods will work unchanged. The `Message` class mimics SwiftMailer’s API, so only transport-specific code (e.g., SMTP config) needs updates.
- How does Nette/Mail’s DKIM signing compare to Laravel’s built-in DKIM support?
- Nette/Mail’s `DkimSigner` offers finer control (custom selectors, passphrases) and integrates directly with Laravel’s `config/mail.php`. Test with `testMode` in config before production to avoid misconfigurations. For most users, it’s more reliable than SwiftMailer’s DKIM.
- Will Nette/Mail’s CSS inlining break my existing email templates?
- Unlikely, but test complex CSS (e.g., `@media` queries, nested selectors) in Outlook. The `CssInliner` component uses optimized regex for PHP 8.2+, but avoid inline styles in Blade templates—let Nette handle it. Start with a subset of templates to validate compatibility.
- How do I configure SMTP fallbacks if my primary server fails?
- Use Nette’s `FallbackMailer` to chain transports (e.g., SMTP → Sendmail). In Laravel, extend the `Mailer` class to wrap `FallbackMailer` with priority logic. Example: `new FallbackMailer([new SmtpMailer($config), new SendmailMailer()])`.
- Is Nette/Mail compatible with Laravel 10 and PHP 8.2+?
- Yes, use **v4.x** for PHP 8.2+ (Laravel 10+). For older PHP (7.4–8.1), use **v3.x**. The package drops PHP 7.1 in v4.0 but adds PHPDoc types and static return hints for modern tooling like PHPStan.
- How do I test email sending in Laravel’s unit tests with Nette/Mail?
- Use Laravel’s `MailFake` facade as usual. Nette/Mail’s `Message` class integrates with it seamlessly. Example: `Mail::fake(); Mail::raw($message)->to('user@example.com'); Mail::assertSent()`. No additional setup is needed.
- Can I use Blade templates with Nette/Mail, and how do I prevent XSS?
- Yes, pass Blade output via `setHtmlBody(view('email.template'))`. To prevent XSS, **always use `{{ }}` (escaped) for dynamic content**—never `{{!! !!}}`. For user-generated HTML, sanitize with `htmlspecialchars()` before rendering.
- What’s the performance impact of CSS inlining for bulk emails (e.g., newsletters)?
- Benchmark against SwiftMailer: `CssInliner` uses single-pass regex (optimized for PHP 8.2+) and adds ~5–10ms per email. For high volume, pre-inline CSS in templates or use a queue (e.g., Laravel Horizon) to distribute load.
- Are there alternatives to Nette/Mail for Laravel, and why choose this one?
- Alternatives include SwiftMailer (default), PHPMailer, or Symfony Mailer. Nette/Mail stands out for its **DKIM integration**, **CSS inlining**, and **fallback logic**—all without third-party dependencies. It’s also ~30% lighter than SwiftMailer and aligns with Laravel’s modular design.
- How do I handle attachments with Nette/Mail, especially for large files?
- Use `addAttachment()` with file paths or streams. For large files, validate `Content-Disposition` headers and consider chunked uploads via `setRawBody()`. Example: `$message->addAttachment($filePath, ['contentType' => 'application/pdf'])`.