phplaravelemaileventsswiftmailer

How to retrieve the recipients email address from Laravel's Mail MessageSending event?


As you may know, Laravel fires the MessageSending event when it's about to send an email message. I have added a Listener which listens for this specific event.

Unfortunately I'm unable to determine the recipient email address inside the Listener's handle method. The only argument I can get is the Swift Mailer message.

Do you know a way I could retrieve the recipients email address inside the Listener's handle method?


Solution

  • You can call getTo() on the Swift_Message object to get a list of addresses the message will be sent to:

    $message = $event->message;
    $addresses = $message->getTo();