Tuesday, May 1, 2018

Get plaintext email from event - development

Get plaintext email from event

I’m logging all emails that are sent from my application. I’m looking for a better way to grab the plaintext version of a SwiftMailer mail if it exists. Currently I’m using the following code in my event listener:

$plainText = optional(
    optional(
        $event->message->getChildren()
    )[0]
)->getBody();

$body = $plainText === null ? $event->message->getBody() : $plainText;

Is there a cleaner way to perform this process if I ever need to repeat this in the future?



from Laravel Questions and Answers https://laravelquestions.com/laravel/get-plaintext-email-from-event/
via Lzo Media

No comments:

Post a Comment