Laravel - Get email to address in a email view.
Asked Answered
P

1

6

In a blade email view is it possible to get the To address?

eg

Mail::to('[email protected]')->send(new ActivationEmail( $data ));

Accessing the to address in blade eg {{ $to }}

I know I can pass it into the $data array ['to' => '[email protected]'].

But not wanting to do that because would mean every single email call would require it and adding extra code when not required.

Im using the to email in my unsubscribe link in the layout template and seems stupid to have to pass the email via $data array to every email call just so the unsubscribe link can access it.

Phyl answered 26/5, 2018 at 10:1 Comment(2)
Did you figure this out?Unbearable
I need to do something like this too. Is this not possible?Floeter
E
0

We can get it from the magic $__data variable. In the view blade.php file, the following will populate the $to variable with the first to address. the getTo() call returns an array, so you can get multiple addresses if available.

<?php
/**@var $message \Illuminate\Mail\Message */    
$message = $__data['message'];
$to      = Arr::first($message->getTo())->toString();
?>
Erdei answered 3/11, 2022 at 5:11 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.