@@ -1410,91 +1410,89 @@ Mailer Events
1410
1410
MessageEvent
1411
1411
~~~~~~~~~~~~
1412
1412
1413
+ **Event Class **: :class: `Symfony\\ Component\\ Mailer\\ Event\\ MessageEvent `
1414
+
1413
1415
``MessageEvent `` allows to change the Message and the Envelope before the email
1414
1416
is sent::
1415
1417
1416
1418
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
1417
1419
use Symfony\Component\Mailer\Event\MessageEvent;
1418
1420
use Symfony\Component\Mime\Email;
1419
1421
1420
- class MailerSubscriber implements EventSubscriberInterface
1422
+ public function onMessage(MessageEvent $event): void
1421
1423
{
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;
1427
1427
}
1428
+ // do something with the message
1429
+ }
1428
1430
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:
1435
1433
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"
1439
1437
1440
1438
SentMessageEvent
1441
1439
~~~~~~~~~~~~
1442
1440
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::
1444
1446
1445
1447
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
1446
1448
use Symfony\Component\Mailer\Event\SentMessageEvent;
1447
1449
use Symfony\Component\Mailer\SentMessage;
1448
1450
1449
- class MailerSubscriber implements EventSubscriberInterface
1451
+ public function onMessage(SentMessageEvent $event): void
1450
1452
{
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;
1456
1456
}
1457
1457
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
1467
1459
}
1468
1460
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
+
1469
1468
FailedMessageEvent
1470
1469
~~~~~~~~~~~~
1471
1470
1471
+ **Event Class **: :class: `Symfony\\ Component\\ Mailer\\ Event\\ FailedMessageEvent `
1472
+
1472
1473
``FailedMessageEvent `` it allows acting on the the initial message in case of a failure::
1473
1474
1474
1475
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
1475
1476
use Symfony\Component\Mailer\Event\FailedMessageEvent;
1476
1477
1477
- class MailerSubscriber implements EventSubscriberInterface
1478
+ public function onMessage(FailedMessageEvent $event): void
1478
1479
{
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
+ }
1485
1485
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:
1490
1488
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"
1494
1492
1495
1493
.. versionadded :: 6.2
1496
1494
1497
- ``SentMessageEvent `` and ``FailedMessageEvent `` was introduced in Symfony 6.2.
1495
+ ``SentMessageEvent `` and ``FailedMessageEvent `` were introduced in Symfony 6.2.
1498
1496
1499
1497
Development & Debugging
1500
1498
-----------------------
0 commit comments