Skip to content
PHP Ecosystem
Explore

MailCollector

API reference › Yii3 Debug › Collector › MailCollector

final classYii3\Debug\Collector\MailCollector
ImplementsCollectorInterface
Sourcesrc/Collector/MailCollector.php

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.

MethodDescriptionDefined 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
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

ParameterTypeDescription
$filesYii3\Debug\Mail\MailFileStoreStore the .eml files are written to and removed from.
$emailFactoryClosure(Yiisoft\Mailer\MessageInterface): Symfony\Component\Mime\Email|nullConverter 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.
$loggerPsr\Log\LoggerInterface|nullLogger receiving a warning when the conversion fails, or null to fall back to the message accessors without reporting it.
public function capture(): array<string, mixed>|null

Encodes the captured messages into the Mail panel payload.

Returns

array<string, mixed>|null: Encoded Mail panel payload; null when the collector never started.

public function collect(Yiisoft\Mailer\Event\AfterSend $event): void

Records 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

ParameterTypeDescription
$eventAfterSendEvent the mailer dispatched after the transport accepted the message.
public function id(): string

Returns the stable identifier of this collector.

Returns

string: Stable ID pairing this collector with its panel.

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.

public function reconcileFiles(iterable<string> $referencedFiles): void

Deletes aged .eml files no retained capture refers to.

Parameters

ParameterTypeDescription
$referencedFilesiterable<string>File names referenced by the committed manifest.
public function removeFiles(iterable<string> $files): void

Deletes the .eml files of a capture that was evicted from history or never committed.

Parameters

ParameterTypeDescription
$filesiterable<string>File names recorded by the capture.
public function shutdown(): void

Stops capturing and clears the messages accumulated for the request.

public function startup(): void

Starts capturing, discarding anything left from a previous request.