diff --git a/src/SendGridChannel.php b/src/SendGridChannel.php index cef541b..e1f245c 100644 --- a/src/SendGridChannel.php +++ b/src/SendGridChannel.php @@ -50,8 +50,9 @@ public function send($notifiable, Notification $notification) // Handle the case where routeNotificationForMail returns an array (email => name) if (is_array($to)) { - reset($to); - $message->to(key($to), current($to)); + foreach ($to as $email => $name) { + $message->to($email, $name); + } } else { $message->to($to); } diff --git a/tests/SendGridChannelTest.php b/tests/SendGridChannelTest.php index b12089b..ed41696 100644 --- a/tests/SendGridChannelTest.php +++ b/tests/SendGridChannelTest.php @@ -137,6 +137,27 @@ public function routeNotificationForMail($notification) $this->assertEquals($message->tos[0]->getEmail(), 'john@example.com'); $this->assertEquals($message->tos[0]->getName(), 'John Doe'); + + //Also support multiple recipients + $notifiableWithEmailAndName = new class { + use Notifiable; + + public function routeNotificationForMail($notification) + { + return [ + 'john@example.com' => 'John Doe', + 'jane@example.com' => 'Jane Doe', + ]; + } + }; + + $channel->send($notifiableWithEmailAndName, $notification); + $message = $notification->sendgridMessage; + + $this->assertEquals($message->tos[0]->getEmail(), 'john@example.com'); + $this->assertEquals($message->tos[0]->getName(), 'John Doe'); + $this->assertEquals($message->tos[1]->getEmail(), 'jane@example.com'); + $this->assertEquals($message->tos[1]->getName(), 'Jane Doe'); } private function mockSendgrid($statusCode = 200)