spatie/laravel-mailable-test
Adds an Artisan command to quickly send any Laravel Mailable to a chosen email address for preview and debugging, without filling out forms or running full app flows. Constructor parameters are detected and passed automatically.
Pros:
Cons:
log, array, or mail) to be configured in .env for testing.spatie/laravel-mailable-test).mail:send-test).MAIL_DRIVER=log for in-memory testing).Mailable classes extending Illuminate\Mail\Mailable)..env for testing (e.g., MAIL_DRIVER=log to avoid real SMTP calls).Carbon) might behave differently in tests vs. production..env be configured for testing? Will teams need to maintain separate testing configurations?Mail::fake() for more controlled testing? Or is the CLI approach preferred?Mailable class for emails.mail:send-test where applicable.php artisan mail:send-test OrderConfirmation user@example.com).composer.json constraints).MAIL_DRIVER=log or array in .env.testing to avoid real SMTP calls.MAIL_DRIVER=mail (if testing local SMTP setups).Illuminate\Mail\Mailable..env configuration for mail (even if just MAIL_DRIVER=log).composer require spatie/laravel-mailable-test --dev
php artisan vendor:publish --provider="Spatie\MailableTest\MailableTestServiceProvider"
php artisan mail:send-test OrderConfirmation user@example.com --param=value
phpunit.xml or custom scripts:
<env name="MAIL_DRIVER" value="log"/>
<env name="MAIL_MAILER" value="array"/>
storage/logs/laravel.log) or use Mail::assertSent() in tests..env setups for testing vs. production.MAIL_DRIVER for testing, causing real emails to be sent.--param=value).MAIL_DRIVER and logs.MAIL_DRIVER=array + Mail::pretend() for in-memory testing.telescope (if installed) to inspect sent mailables.MAIL_DRIVER=log).| Failure Scenario | Impact | Mitigation |
|---|---|---|
| Mailable class not found | Command fails silently | Add validation in CI/CD or use --dry-run. |
| Invalid constructor parameters | Email sent with incorrect data | Document required params; use --help. |
MAIL_DRIVER misconfigured |
Real emails sent to recipients | Enforce MAIL_DRIVER=log in CI/CD. |
| Network issues (SMTP) | Tests flaky in CI/CD | Use MAIL_DRIVER=array or mock dependencies. |
| Package conflicts (Laravel version) | Breaking changes in future updates | Pin version in composer.json. |
MAILABLE_TESTING.md with:
.env configuration snippetsHow can I help you explore Laravel packages today?