diff --git a/src/Illuminate/Notifications/Channels/MailChannel.php b/src/Illuminate/Notifications/Channels/MailChannel.php index afea7370e0c0..85ebb674ec77 100644 --- a/src/Illuminate/Notifications/Channels/MailChannel.php +++ b/src/Illuminate/Notifications/Channels/MailChannel.php @@ -186,7 +186,7 @@ protected function getRecipients($notifiable, $notification, $message) return collect($recipients)->mapWithKeys(function ($recipient, $email) { return is_numeric($email) - ? [(is_string($recipient) ? $recipient : $recipient->email)] + ? [$email => (is_string($recipient) ? $recipient : $recipient->email)] : [$email => $recipient]; })->all(); } diff --git a/tests/Integration/Notifications/SendingMailNotificationsTest.php b/tests/Integration/Notifications/SendingMailNotificationsTest.php index 099bc6f2e76d..6adbcce0b6fb 100644 --- a/tests/Integration/Notifications/SendingMailNotificationsTest.php +++ b/tests/Integration/Notifications/SendingMailNotificationsTest.php @@ -174,6 +174,36 @@ public function test_mail_is_sent_with_subject() $user->notify($notification); } + public function test_mail_is_sent_to_multiple_adresses() + { + $notification = new TestMailNotificationWithSubject; + + $user = NotifiableUserWithMultipleAddreses::forceCreate([ + 'email' => 'taylor@laravel.com', + ]); + + $this->markdown->shouldReceive('render')->once()->andReturn('htmlContent'); + $this->markdown->shouldReceive('renderText')->once()->andReturn('textContent'); + + $this->mailer->shouldReceive('send')->once()->with( + ['html' => 'htmlContent', 'text' => 'textContent'], + $notification->toMail($user)->toArray(), + Mockery::on(function ($closure) { + $message = Mockery::mock(\Illuminate\Mail\Message::class); + + $message->shouldReceive('to')->once()->with(['foo_taylor@laravel.com', 'bar_taylor@laravel.com']); + + $message->shouldReceive('subject')->once()->with('mail custom subject'); + + $closure($message); + + return true; + }) + ); + + $user->notify($notification); + } + public function test_mail_is_sent_using_mailable() { $notification = new TestMailNotificationWithMailable; @@ -205,6 +235,17 @@ public function routeNotificationForMail($notification) } } +class NotifiableUserWithMultipleAddreses extends NotifiableUser +{ + public function routeNotificationForMail($notification) + { + return [ + 'foo_'.$this->email, + 'bar_'.$this->email, + ]; + } +} + class TestMailNotification extends Notification { public function via($notifiable)