Skip to content

[13.x] Populate mailable recipients in mail notifications#60259

Draft
LucasCavalheri wants to merge 1 commit into
laravel:13.xfrom
LucasCavalheri:fix-mail-channel-populate-mailable-recipients
Draft

[13.x] Populate mailable recipients in mail notifications#60259
LucasCavalheri wants to merge 1 commit into
laravel:13.xfrom
LucasCavalheri:fix-mail-channel-populate-mailable-recipients

Conversation

@LucasCavalheri
Copy link
Copy Markdown
Contributor

Summary

When a notification toMail() method returns a Mailable instance without recipients, the MailChannel currently sends the message without automatically using the notifiable mail route.

This differs from the existing MailMessage behavior, where recipients are automatically resolved from the notifiable.

This PR aligns both behaviors by automatically populating recipients for Mailable notifications only when no recipients were explicitly defined.

Changes

  • Populate recipients from the notifiable mail route when:

    • the returned Mailable has no to recipients
    • and the Mailable envelope() does not define recipients
  • Preserve existing behavior when:

    • recipients were explicitly defined using ->to()
    • recipients were defined via envelope()->to
  • Remove the unused $message parameter from getRecipients()

Motivation

MailMessage notifications already resolve recipients automatically from the notifiable.

Returning a Mailable from toMail() should behave consistently and avoid requiring users to manually duplicate recipient resolution logic for the most common notification flow.

This also improves developer experience and reduces subtle delivery mistakes when converting notifications from MailMessage to Mailable.

Backward Compatibility

This change is fully backward compatible.

Existing applications that already define recipients explicitly on the Mailable are unaffected because the channel only populates recipients when none are present.

Tests

Added tests/Notifications/MailChannelTest.php covering:

  • populates recipients from the notifiable
  • does not override explicit ->to()
  • respects envelope()->to
  • supports multiple addresses returned by routeNotificationForMail()

Additional integration coverage was added to SendingNotificationsWithLocaleTest.php.

When a notification returns a Mailable without recipients, use the
notifiable's mail route—the same behavior as MailMessage notifications.
@crynobone crynobone marked this pull request as draft May 25, 2026 01:25
@crynobone crynobone added the needs work Not quite ready for primetime label May 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs work Not quite ready for primetime

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants