Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[Mailer] add new events#17181

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
Merged
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 70 additions & 13 deletionsmailer.rst
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -1410,33 +1410,90 @@ Mailer Events
MessageEvent
~~~~~~~~~~~~

**Event Class**: :class:`Symfony\\Component\\Mailer\\Event\\MessageEvent`

``MessageEvent`` allows to change the Message and the Envelope before the email
is sent::

use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\Mailer\Event\MessageEvent;
use Symfony\Component\Mime\Email;

class MailerSubscriber implements EventSubscriberInterface
public function onMessage(MessageEvent $event): void
{
public static function getSubscribedEvents()
{
return [
MessageEvent::class => 'onMessage',
];
$message = $event->getMessage();
if (!$message instanceof Email) {
return;
}
// do something with the message
}

public function onMessage(MessageEvent $event): void
{
$message = $event->getMessage();
if (!$message instanceof Email) {
return;
}
Execute this command to find out which listeners are registered for this event and
their priorities:

.. code-block:: terminal

$ php bin/console debug:event-dispatcher "Symfony\Component\Mailer\Event\MessageEvent"

SentMessageEvent
~~~~~~~~~~~~

**Event Class**: :class:`Symfony\\Component\\Mailer\\Event\\SentMessageEvent`

``SentMessageEvent`` it allows you to act on the :class:`Symfony\\Component\\\Mailer\\\SentMessage` to access the original
message (getOriginalMessage()) and some debugging information (getDebug()) such as
the HTTP calls made by the HTTP transports, which is useful for debugging errors::

use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\Mailer\Event\SentMessageEvent;
use Symfony\Component\Mailer\SentMessage;

// do something with the message
public function onMessage(SentMessageEvent $event): void
{
$message = $event->getMessage();
if (!$message instanceof SentMessage) {
return;
}

// do something with the message
}

Execute this command to find out which listeners are registered for this event and
their priorities:

.. code-block:: terminal

$ php bin/console debug:event-dispatcher "Symfony\Component\Mailer\Event\SentMessageEvent"

FailedMessageEvent
~~~~~~~~~~~~

**Event Class**: :class:`Symfony\\Component\\Mailer\\Event\\FailedMessageEvent`

``FailedMessageEvent`` it allows acting on the the initial message in case of a failure::

use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\Mailer\Event\FailedMessageEvent;

public function onMessage(FailedMessageEvent $event): void
{
// e.g you can get more information on this error when sending an email.
$event->getError();

// do something with the message
}

Execute this command to find out which listeners are registered for this event and
their priorities:

.. code-block:: terminal

$ php bin/console debug:event-dispatcher "Symfony\Component\Mailer\Event\FailedMessageEvent"

.. versionadded:: 6.2

``SentMessageEvent`` and ``FailedMessageEvent`` were introduced in Symfony 6.2.

Development & Debugging
-----------------------

Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp