> For the complete documentation index, see [llms.txt](https://quantumphp.gitbook.io/docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://quantumphp.gitbook.io/docs/packages/mailer/overview.md).

# Overview

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\Mailer` is the proxy object returned by `mailer()`
* `Quantum\Mailer\Factories\MailerFactory` resolves and caches one mailer per adapter name
* adapters implement `Quantum\Mailer\Contracts\MailerInterface`
* `Quantum\Mailer\Traits\MailerTrait` provides the shared message-building and reset behavior
* `Quantum\Mailer\MailTrap` saves and parses local `.eml` files when mail trapping is enabled

## Supported adapters

Mailer supports these adapter names:

* `smtp`
* `mailgun`
* `mandrill`
* `sendgrid`
* `sendinblue`
* `resend`

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:

1. set the sender with `setFrom()`
2. add one or more recipients with `setAddress()`
3. optionally set a subject
4. provide either `setBody()` or `setTemplate()` with message data
5. call `send()`

After `send()` finishes, the package clears the sender, recipients, subject, body, and template from the adapter instance.

## Important constraints

* `MailerFactory` caches one `Mailer` instance 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 `.php` suffix. The package always requires `<template>.php`.
* `send()` returns `false` on transport failure and logs transport errors to the debugger mails tab through `warning(...)`.
* 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_trap` is enabled, the package saves a local `.eml` file instead of contacting the transport.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://quantumphp.gitbook.io/docs/packages/mailer/overview.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
