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); } 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()