MailCollector
API reference › Yii3 Debug › Collector › MailCollector
Captures every message yiisoft/mailer sends during the request for the Mail panel.
Each message is recorded in the capture shape the Yii2 collector produces, so a capture written by either host
renders through the same MailPanel, and is stored as an .eml file through
MailFileStore. yiisoft/mailer dispatches AfterSend only once the transport accepted the message, so
every captured message is reported as sent.
Methods
Section titled “Methods”| Method | Description | Defined by |
|---|---|---|
__construct() | Creates a mail collector that stores message files and reports conversion failures. | MailCollector |
capture() | Encodes the captured messages into the Mail panel payload. | MailCollector |
collect() | Records a message the mailer sent and stores it as an .eml file. | MailCollector |
id() | Returns the stable identifier of this collector. | MailCollector |
mailFiles() | Returns the names of the .eml files stored for the captured messages. | MailCollector |
reconcileFiles() | Deletes aged .eml files no retained capture refers to. | MailCollector |
removeFiles() | Deletes the .eml files of a capture that was evicted from history or never committed. | MailCollector |
shutdown() | Stops capturing and clears the messages accumulated for the request. | MailCollector |
startup() | Starts capturing, discarding anything left from a previous request. | MailCollector |
Method details
Section titled “Method details”__construct()
Section titled “__construct() ”public function __construct(Yii3\Debug\Mail\MailFileStore $files, Closure(Yiisoft\Mailer\MessageInterface): Symfony\Component\Mime\Email|null $emailFactory = null, Psr\Log\LoggerInterface|null $logger = null)Creates a mail collector that stores message files and reports conversion failures.
Parameters
| Parameter | Type | Description |
|---|---|---|
$files | Yii3\ | Store the .eml files are written to and removed from. |
$emailFactory | Closure(Yiisoft\ | Converter building the Symfony email the yiisoft/mailer-symfony adapter sends, or null when the adapter is not installed and the message accessors are read instead. |
$logger | Psr\ | Logger receiving a warning when the conversion fails, or null to fall back to the message accessors without reporting it. |
capture()
Section titled “capture() ”public function capture(): array<string, mixed>|nullEncodes the captured messages into the Mail panel payload.
Returns
array<string, mixed>|null: Encoded Mail panel payload; null when the collector never started.
collect()
Section titled “collect() ”public function collect(Yiisoft\Mailer\Event\AfterSend $event): voidRecords a message the mailer sent and stores it as an .eml file.
With the Symfony email the body, charset, headers, time, and file are read exactly as the Yii2 collector reads them from its Symfony message; without it they come from the message accessors. The file holds the RFC 5322 source, or the message string representation when there is no Symfony email or Symfony refuses to serialize one that lacks a sender or recipient.
Parameters
| Parameter | Type | Description |
|---|---|---|
$event | AfterSend | Event the mailer dispatched after the transport accepted the message. |
public function id(): stringReturns the stable identifier of this collector.
Returns
string: Stable ID pairing this collector with its panel.
mailFiles()
Section titled “mailFiles() ”public function mailFiles(): list<string>Returns the names of the .eml files stored for the captured messages.
The request summary records them, so evicting the capture from history also removes its files.
Returns
list<string>: File names in send order; messages whose file could not be written are skipped.
reconcileFiles()
Section titled “reconcileFiles() ”public function reconcileFiles(iterable<string> $referencedFiles): voidDeletes aged .eml files no retained capture refers to.
Parameters
| Parameter | Type | Description |
|---|---|---|
$referencedFiles | iterable<string> | File names referenced by the committed manifest. |
removeFiles()
Section titled “removeFiles() ”public function removeFiles(iterable<string> $files): voidDeletes the .eml files of a capture that was evicted from history or never committed.
Parameters
| Parameter | Type | Description |
|---|---|---|
$files | iterable<string> | File names recorded by the capture. |
shutdown()
Section titled “shutdown() ”public function shutdown(): voidStops capturing and clears the messages accumulated for the request.
startup()
Section titled “startup() ”public function startup(): voidStarts capturing, discarding anything left from a previous request.