From 776e671dee3ecff6cba9015c2e79fce4158d148c Mon Sep 17 00:00:00 2001 From: Dries Vints Date: Thu, 10 Feb 2022 11:24:44 +0100 Subject: [PATCH 1/2] Fix notification email recipient --- src/Illuminate/Mail/Message.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Illuminate/Mail/Message.php b/src/Illuminate/Mail/Message.php index 67b738a4b7f3..88a3fa5b05c8 100755 --- a/src/Illuminate/Mail/Message.php +++ b/src/Illuminate/Mail/Message.php @@ -200,7 +200,11 @@ protected function addAddresses($address, $name, $type) if (is_array($address)) { $type = lcfirst($type); - $addresses = collect($address)->map(function (string|array $address) { + $addresses = collect($address)->map(function (string|array $address, $key) { + if (is_string($key) && is_string($address)) { + return new Address($key, $address); + } + if (is_array($address)) { return new Address($address['email'] ?? $address['address'], $address['name'] ?? null); } From d7d3fbc1abaee447a3e5b84f9b98be8b3beb93ca Mon Sep 17 00:00:00 2001 From: Dries Vints Date: Thu, 10 Feb 2022 11:28:23 +0100 Subject: [PATCH 2/2] Add test --- tests/Mail/MailMessageTest.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/Mail/MailMessageTest.php b/tests/Mail/MailMessageTest.php index d36812492df4..1756059de6bc 100755 --- a/tests/Mail/MailMessageTest.php +++ b/tests/Mail/MailMessageTest.php @@ -41,8 +41,11 @@ public function testReturnPathMethod() public function testToMethod() { - $this->assertInstanceOf(Message::class, $message = $this->message->to('foo@bar.baz', 'Foo', false)); + $this->assertInstanceOf(Message::class, $message = $this->message->to('foo@bar.baz', 'Foo')); $this->assertEquals(new Address('foo@bar.baz', 'Foo'), $message->getSymfonyMessage()->getTo()[0]); + + $this->assertInstanceOf(Message::class, $message = $this->message->to(['bar@bar.baz' => 'Bar'])); + $this->assertEquals(new Address('bar@bar.baz', 'Bar'), $message->getSymfonyMessage()->getTo()[0]); } public function testToMethodWithOverride()