Skip to main content
Mail Notifications · Revision #1

How do I add attachments to a mailable?

How do I add attachments to a mailable?

You can attach files to a mailable by using the whenSendingAsMail callback:

\Aero\Cart\Events\OrderConfirmation::whenSendingAsMail(function (\Aero\Events\Actions\Mailable $mailable, \Aero\Cart\Events\OrderConfirmation $event) {
    $pdf = \Aerocargo\PdfInvoices\Invoice::forOrder($event->order, 'invoice');

    $mailable->attachData(
        $pdf->output(),
        "{$event->order->reference}-invoice.pdf",
        [
            'mime' => 'application/pdf',
        ]
    );
});

This example uses the aerocargo/pdf-invoice module to generate a PDF Invoice for the order.