Core\Mail\ReportRecipient::Action
What the mail server did with a message for one recipient of a delivery report.
A bounce is a message from a mail server that says your mail could not be delivered. A delivery report is the standard part of a bounce that lists each recipient and what happened.
Core\Mail\ReportRecipient::action() returns one of the five cases. Failed means the message could not be delivered. Delayed means the message is late, and the server still tries to deliver it. Delivered means the server put the message in the mailbox. Relayed means the message was passed to another server, which sends no report. So you do not learn whether the mail arrived. Expanded means the message was sent on to the members of a mailing list.
Good to know: a message is a bounce when at least one recipient is Failed. It is a delay when no recipient failed and at least one is Delayed.
Examples
Each action in one report
<?nvs// Shows the five actions a delivery report can give, one for each recipient.
use Core\Mail\Message;use Core\Mail\ReportRecipient;
class Action{ public static function meaning(ReportRecipient::Action $action): string { return match ($action) { ReportRecipient::Action::Failed => 'Failed: the message was not delivered', ReportRecipient::Action::Delayed => 'Delayed: the server still tries', ReportRecipient::Action::Delivered => 'Delivered: the message is in the mailbox', ReportRecipient::Action::Relayed => 'Relayed: passed to a server that sends no report', ReportRecipient::Action::Expanded => 'Expanded: sent on to the members of a list', }; }}
// One recipient for each action. The address names the action.array<string> $words = ['failed', 'delayed', 'delivered', 'relayed', 'expanded'];string $groups = '';foreach ($words as string $word) { $groups = $groups . "\nFinal-Recipient: rfc822; " . $word . "@example.org\nAction: " . $word . "\n";}
Message $report = Message::parse( "From: mailer-daemon@mx.example.net\n" . "Content-Type: multipart/report; report-type=delivery-status; boundary=\"b\"\n\n" . "--b\nContent-Type: message/delivery-status\n\n" . "Reporting-MTA: dns; mx.example.net\n" . $groups . "--b--\n",);
foreach ($report->report()?->recipients() ?? [] as ReportRecipient $recipient) { echo $recipient->address(), ' -> ', Action::meaning($recipient->action()), "\n";}
// One recipient is `Failed`, so the whole message is a bounce.echo 'bounce: ', $report->kind() == Message::Kind::Bounce ? 'yes' : 'no', "\n";failed@example.org -> Failed: the message was not delivereddelayed@example.org -> Delayed: the server still triesdelivered@example.org -> Delivered: the message is in the mailboxrelayed@example.org -> Relayed: passed to a server that sends no reportexpanded@example.org -> Expanded: sent on to the members of a listbounce: yesChangelog
| Version | Change |
|---|---|
0.0.6 | Core\Mail\Message::report reads the delivery report in a bounce or a delay. For each recipient, it gives the address, what happened, the status code such as 5.1.1, and whether the failure is permanent. |
