Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

kanak09's avatar

Send Notification mail+database using different default email field

Hello,

THE CONTEXT : When a user changes his email in my app, I need to put the new email as pending while it's not validated. During this action i want to send a notification to the user (mail + database).

The database notification works like a charm, the problem is for the mail notification because by default laravel takes the "email" field. But in this particular case, it's "pending_email" fiield.

WHAT I TRIED :

  • I know I can change the method routeNotificationForMail, but it doesn't fit my needs because I don't want to change the route for all the notifications.

  • I tried to call the mail notification with Notification::route('mail', $this->getPendingEmail())->notify(new VerifyNewEmailNotify); but the notifiable object is not my user anymore, so I need to adapt my VerifyNewEmailNotify to pass the user in the constructor instead of using the notifiable... it's not super nice because I prefer using the notifiable object.

  • I tried to create a new User object with same properties as my user, then replace the email by the pending_email and calls notify on this new User like : $temporaryUser = User::find($this->getKey()); $temporaryUser->email = $this->getPendingEmail(); $temporaryUser->notify(new VerifyNewEmailNotify);

but it doesn't work and nothing happens. When debugging I noticed the $notifiables is empty in the ChannelManager class, method SendNow();

Why there is not a method in the Notification class to change the email ? In my MailMessage i can set the from, cc, replyTo, but unable to set the TO.

Thanks for help

0 likes
3 replies

Please or to participate in this conversation.