function MessageEventTestSubscriber::setCustomFrom

Sets a custom from header.

Parameters

\Symfony\Component\Mailer\Event\MessageEvent $event: The message event.

File

core/modules/mailer/tests/modules/mailer_event_subscriber_test/src/EventSubscriber/MessageEventTestSubscriber.php, line 35

Class

MessageEventTestSubscriber
A message event test subscriber.

Namespace

Drupal\mailer_event_subscriber_test\EventSubscriber

Code

public function setCustomFrom(MessageEvent $event) : void {
  $customFrom = $this->state
    ->get('mailer_event_subscriber_test.set_custom_from');
  $message = $event->getMessage();
  if (!empty($customFrom) && $message instanceof Email) {
    $message->from(Address::create($customFrom));
  }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.