Mailer
The Mailer package gives Quantum a shared mail-sending entry point with one SMTP transport and several API transports.
Use it when you want to build an email with mailer(), choose a configured delivery adapter, and send either a raw HTML body or a PHP template.
When to use it
Reach for Mailer when you need to:
- send application emails through the configured default provider
- switch between SMTP and provider APIs without changing the calling code
- render email bodies from a PHP template file
- save outgoing messages to the local mail trap instead of sending them
If you only need to inspect saved .eml files, use MailTrap directly. The Mailer package is the sending layer.
Package shape
The package is built from a few small parts:
Quantum\Mailer\Maileris the proxy object returned bymailer()Quantum\Mailer\Factories\MailerFactoryresolves and caches one mailer per adapter name- adapters implement
Quantum\Mailer\Contracts\MailerInterface Quantum\Mailer\Traits\MailerTraitprovides the shared message-building and reset behaviorQuantum\Mailer\MailTrapsaves and parses local.emlfiles when mail trapping is enabled
Supported adapters
Mailer supports these adapter names:
smtpmailgunmandrillsendgridsendinblueresend
The factory resolves the requested adapter or mailer.default when you do not pass one.
Common message flow
All adapters share the same base flow:
- set the sender with
setFrom() - add one or more recipients with
setAddress() - optionally set a subject
- provide either
setBody()orsetTemplate()with message data - call
send()
After send() finishes, the package clears the sender, recipients, subject, body, and template from the adapter instance.
Important constraints
MailerFactorycaches oneMailerinstance per adapter name inside the shared factory service.- Adapter-specific methods are available only when the underlying adapter implements them.
- Only the SMTP adapter supports reply-to, CC, BCC, and attachments.
- Template paths are stored without the
.phpsuffix. The package always requires<template>.php. send()returnsfalseon transport failure and logs transport errors to the debugger mails tab throughwarning(...).- Message IDs can be reused across sends in long-running processes, so do not assume every send gets a fresh generated message ID automatically.
- When
mailer.mail_trapis enabled, the package saves a local.emlfile instead of contacting the transport.