illuminate/mail
Illuminate Mail is Laravel’s email component for composing and sending messages via drivers like SMTP, Mailgun, Postmark, and SES. Supports templated views, attachments, queues, markdown mailables, and configurable transports for reliable delivery.
Install the package with Composer: composer require illuminate/mail. Though technically standalone, this package is designed for use within Laravel applications—standalone usage requires manual bootstrapping of service providers, config loading, and container setup. First, create a mailable class via php artisan make:mail WelcomeUser, define content in build(), and send it using Mail::to($user)->send(new WelcomeUser()). Start with the default log mailer in .env (MAIL_MAILER=log) for safe local testing—emails are written to storage/logs/laravel.log instead of actually sending.
$order, $token).--markdown flag (php artisan make:mail --markdown=emails.orders.shipped) for responsive emails. Leverage Blade’s @component('mail::message'), @slot, and @endslot for consistent layouts and auto-inlined CSS.ShouldQueue to mailables or use Mail::queue() to avoid blocking requests. Ensure models passed to mailables are serializable (e.g., pass order_id, not Order instance)..env: use ses, smtp, or mailgun for production, log for local dev, and array for testing (emails discarded but trackable via Mail::spy()).Mail::fake(), trigger the action, then assert expectations: Mail::assertSent(OrderShipped::class, fn ($mail) => $mail->order->id === $orderId).build() (e.g., Order::findOrFail($this->orderId))—serialized models may be outdated by job execution time.view() vs markdown(): Using view() bypasses Laravel’s email layout engine and CSS inlining—always use markdown() for Markdown mailables to ensure responsiveness and consistent styling.storage_path('app/reports/' . $filename)) or closures that resolve at send time. Avoid relative paths—they’ll fail in queued jobs where the working directory may differ.config/mail.php Outside Laravel: Standalone usage requires manually publishing/configuring mail.php and registering Illuminate\Mail\MailServiceProvider with a resolved container.symfony/mailer ≥7.4.0 compatibility—some driver options (e.g., SES config keys like region) changed between v6 and v7. Check composer show symfony/mailer if emails fail silently.How can I help you explore Laravel packages today?