@@ -1410,91 +1410,89 @@ Mailer Events
14101410MessageEvent
14111411~~~~~~~~~~~~
14121412
1413+ **Event Class **: :class: `Symfony\\ Component\\ Mailer\\ Event\\ MessageEvent `
1414+
14131415``MessageEvent `` allows to change the Message and the Envelope before the email
14141416is sent::
14151417
14161418 use Symfony\Component\EventDispatcher\EventSubscriberInterface;
14171419 use Symfony\Component\Mailer\Event\MessageEvent;
14181420 use Symfony\Component\Mime\Email;
14191421
1420- class MailerSubscriber implements EventSubscriberInterface
1422+ public function onMessage(MessageEvent $event): void
14211423 {
1422- public static function getSubscribedEvents(): array
1423- {
1424- return [
1425- MessageEvent::class => 'onMessage',
1426- ];
1424+ $message = $event->getMessage();
1425+ if (!$message instanceof Email) {
1426+ return;
14271427 }
1428+ // do something with the message
1429+ }
14281430
1429- public function onMessage(MessageEvent $event): void
1430- {
1431- $message = $event->getMessage();
1432- if (!$message instanceof Email) {
1433- return;
1434- }
1431+ Execute this command to find out which listeners are registered for this event and
1432+ their priorities:
14351433
1436- // do something with the message
1437- }
1438- }
1434+ .. code-block :: terminal
1435+
1436+ $ php bin/console debug:event-dispatcher "Symfony\Component\Mailer\Event\MessageEvent"
14391437
14401438 SentMessageEvent
14411439~~~~~~~~~~~~
14421440
1443- ``SentMessageEvent `` it allows acting on the :class: `Symfony\\ Component\\ Mailer\\ SentMessage `::
1441+ **Event Class **: :class: `Symfony\\ Component\\ Mailer\\ Event\\ SentMessageEvent `
1442+
1443+ ``SentMessageEvent `` it allows you to act on the :class: `Symfony\\ Component\\\M ailer\\\S entMessage ` to access the original
1444+ message (getOriginalMessage()) and some debugging information (getDebug()) such as
1445+ the HTTP calls made by the HTTP transports, which is useful for debugging errors::
14441446
14451447 use Symfony\Component\EventDispatcher\EventSubscriberInterface;
14461448 use Symfony\Component\Mailer\Event\SentMessageEvent;
14471449 use Symfony\Component\Mailer\SentMessage;
14481450
1449- class MailerSubscriber implements EventSubscriberInterface
1451+ public function onMessage(SentMessageEvent $event): void
14501452 {
1451- public static function getSubscribedEvents(): array
1452- {
1453- return [
1454- SentMessageEvent::class => 'onMessage',
1455- ];
1453+ $message = $event->getMessage();
1454+ if (!$message instanceof SentMessage) {
1455+ return;
14561456 }
14571457
1458- public function onMessage(SentMessageEvent $event): void
1459- {
1460- $message = $event->getMessage();
1461- if (!$message instanceof SentMessage) {
1462- return;
1463- }
1464-
1465- // do something with the message
1466- }
1458+ // do something with the message
14671459 }
14681460
1461+ Execute this command to find out which listeners are registered for this event and
1462+ their priorities:
1463+
1464+ .. code-block :: terminal
1465+
1466+ $ php bin/console debug:event-dispatcher "Symfony\Component\Mailer\Event\SentMessageEvent"
1467+
14691468 FailedMessageEvent
14701469~~~~~~~~~~~~
14711470
1471+ **Event Class **: :class: `Symfony\\ Component\\ Mailer\\ Event\\ FailedMessageEvent `
1472+
14721473``FailedMessageEvent `` it allows acting on the the initial message in case of a failure::
14731474
14741475 use Symfony\Component\EventDispatcher\EventSubscriberInterface;
14751476 use Symfony\Component\Mailer\Event\FailedMessageEvent;
14761477
1477- class MailerSubscriber implements EventSubscriberInterface
1478+ public function onMessage(FailedMessageEvent $event): void
14781479 {
1479- public static function getSubscribedEvents(): array
1480- {
1481- return [
1482- FailedMessageEvent::class => 'onMessage',
1483- ];
1484- }
1480+ // e.g you can get more information on this error when sending an email.
1481+ $event->getError();
1482+
1483+ // do something with the message
1484+ }
14851485
1486- public function onMessage(FailedMessageEvent $event): void
1487- {
1488- // e.g you can get more information on this error when sending an email.
1489- $event->getError();
1486+ Execute this command to find out which listeners are registered for this event and
1487+ their priorities:
14901488
1491- // do something with the message
1492- }
1493- }
1489+ .. code-block :: terminal
1490+
1491+ $ php bin/console debug:event-dispatcher "Symfony\Component\Mailer\Event\FailedMessageEvent"
14941492
14951493 .. versionadded :: 6.2
14961494
1497- ``SentMessageEvent `` and ``FailedMessageEvent `` was introduced in Symfony 6.2.
1495+ ``SentMessageEvent `` and ``FailedMessageEvent `` were introduced in Symfony 6.2.
14981496
14991497Development & Debugging
15001498-----------------------
0 commit comments