Add a toRecipient
method to allow sending mail notifications to a different email without overriding routeNotificationForMail method
#46661
-
I have a Laravel 10 project which allows a user to customise the email address that should receive alerts from my system. This, right now is done by overriding the I only really need to override the email that should receive alerts in my /**
* Get the mail representation of the notification.
*
* @param mixed $notifiable
*/
public function toMail($notifiable)
{
$domain = isset($this->emailData[0]['domain']) ? $this->emailData[0]['domain'] : '';
$domain = htmlspecialchars($domain);
$data = [
'is_subscribed' => $notifiable->is_subscribed,
'first_name' => $notifiable['first_name'],
'domains' => json_encode($this->emailData),
];
try {
$this->createHistoryEntry('mail', 'Domain Expiry', $data, $notifiable);
} catch (\Exception $e) {
}
return (new MailMessage)
->subject(isset($domain) && ! empty($domain) ? "Domain Expiry Alert: $domain" : 'Domain Expiry Alert')
->markdown('emails.domains.expiry', $data);
} And here's the method overrideen on the /**
* Route notifications for the mail channel.
*
* @return array|string
*/
public function routeNotificationForMail(Notification $notification)
{
return $this->notification_email;
} How do I customise the recipient without sending important alerts to this Is there a way to fetch the user model into the return (new MailMessage)
->subject('My subject')
->markdown('emails.domains.expiry', $data); Maybe there's a |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
You can return a full Mailable. See Using Mailables section. |
Beta Was this translation helpful? Give feedback.
You can return a full Mailable. See Using Mailables section.