Skip to content

Commit 47f56c8

Browse files
authored
[9.x] Fix notification email recipient (#40921)
* Fix notification email recipient * Add test
1 parent 1c7a41e commit 47f56c8

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

src/Illuminate/Mail/Message.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,11 @@ protected function addAddresses($address, $name, $type)
200200
if (is_array($address)) {
201201
$type = lcfirst($type);
202202

203-
$addresses = collect($address)->map(function (string|array $address) {
203+
$addresses = collect($address)->map(function (string|array $address, $key) {
204+
if (is_string($key) && is_string($address)) {
205+
return new Address($key, $address);
206+
}
207+
204208
if (is_array($address)) {
205209
return new Address($address['email'] ?? $address['address'], $address['name'] ?? null);
206210
}

tests/Mail/MailMessageTest.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,11 @@ public function testReturnPathMethod()
4141

4242
public function testToMethod()
4343
{
44-
$this->assertInstanceOf(Message::class, $message = $this->message->to('[email protected]', 'Foo', false));
44+
$this->assertInstanceOf(Message::class, $message = $this->message->to('[email protected]', 'Foo'));
4545
$this->assertEquals(new Address('[email protected]', 'Foo'), $message->getSymfonyMessage()->getTo()[0]);
46+
47+
$this->assertInstanceOf(Message::class, $message = $this->message->to(['[email protected]' => 'Bar']));
48+
$this->assertEquals(new Address('[email protected]', 'Bar'), $message->getSymfonyMessage()->getTo()[0]);
4649
}
4750

4851
public function testToMethodWithOverride()

0 commit comments

Comments
 (0)