use Illuminate\Mail\Mailables\Envelope;public function envelope(): Envelope{ return new Envelope( subject: 'Welcome to Our Platform', tags: ['onboarding'], );}
One tag per message. Tags can contain letters, numbers, hyphens, underscores, and spaces (max 255 characters).
See Tags documentation for more details.
5. Metadata
Attach custom data for tracking and webhook payloads.
Using the metadata() Method
Code
Mail::to('customer@example.com') ->send( (new OrderConfirmation($order)) ->metadata('order_id', $order->id) ->metadata('customer_id', $order->customer_id) );
In Mailable Envelope
Code
use Illuminate\Mail\Mailables\Envelope;public function envelope(): Envelope{ return new Envelope( subject: 'Order Confirmation', metadata: [ 'order_id' => $this->order->id, 'customer_id' => $this->order->customer_id, 'order_total' => $this->order->total, ], );}
Metadata is included in webhook payloads but not sent to recipients.
6. Multiple Routes
Configure separate mailers for different email types (transactional, marketing, etc.):
use Illuminate\Mail\Mailables\Headers;public function headers(): Headers{ return new Headers( text: [ 'Idempotency-Key' => "welcome-{$this->user->id}", ], );}
Set idempotency_window to 86400 or higher for permanent deduplication within API retention.
8. Webhooks
The driver automatically registers a webhook endpoint and dispatches Laravel events.