Customize email
and name
used to send email with Mail::to()
#52981
-
I would like to send email with |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Being able to set the receipient but not the sender is something that probably confuses a lot of Laravel developers that have the opposite user case of the one who initially implemented it. If using the global If you use mailables, you can use an envelope to achieve that: use Illuminate\Mail\Mailables\Address;
use Illuminate\Mail\Mailables\Envelope;
/**
* Get the message envelope.
*/
public function envelope(): Envelope
{
return new Envelope(
from: new Address('[email protected]', 'Jeffrey Way'),
subject: 'Order Shipped',
);
} If you use notifications, you can customize the /**
* Get the mail representation of the notification.
*/
public function toMail(object $notifiable): MailMessage
{
return (new MailMessage)
->from('[email protected]', 'Barrett Blair')
->line('...');
} |
Beta Was this translation helpful? Give feedback.
Thanks, I was probably not clear enough with my question. My goal was to fetch recipient address bases on User Model attributes, not per Mailable, but I could not use
name
oremail
on the User Model.In short you can't do that with
Mail
, so instead you can useNotification
withrouteNotificationForMail()
on User model.