From d06b8f974be37d72f5ece1c8647c4d8c046da3e9 Mon Sep 17 00:00:00 2001 From: Marc Jauvin Date: Mon, 7 Mar 2022 13:29:25 -0500 Subject: [PATCH 1/2] allow array of email addresses without names --- src/Mail/Mailer.php | 8 ++++++-- tests/Mail/MailerTest.php | 14 ++++++++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/Mail/Mailer.php b/src/Mail/Mailer.php index 88cb6390e..69501a341 100644 --- a/src/Mail/Mailer.php +++ b/src/Mail/Mailer.php @@ -462,7 +462,8 @@ public function sendTo($recipients, $view, array $data = [], $callback = null, $ /** * Process a recipients object, which can look like the following: - * - (string) admin@domain.tld + * - (string) 'admin@domain.tld' + * - (array) ['admin@domain.tld', 'other@domain.tld'] * - (object) ['email' => 'admin@domain.tld', 'name' => 'Adam Person'] * - (array) ['admin@domain.tld' => 'Adam Person', ...] * - (array) [ (object|array) ['email' => 'admin@domain.tld', 'name' => 'Adam Person'], [...] ] @@ -477,7 +478,10 @@ protected function processRecipients($recipients) $result[$recipients] = null; } elseif (is_array($recipients) || $recipients instanceof Collection) { foreach ($recipients as $address => $person) { - if (is_string($person)) { + if (is_int($address) && is_string($person)) { + // no name provided, only email address + $result[$person] = null; + } elseif (is_string($person)) { $result[$address] = $person; } elseif (is_object($person)) { if (empty($person->email) && empty($person->address)) { diff --git a/tests/Mail/MailerTest.php b/tests/Mail/MailerTest.php index 51368609a..2f9148271 100644 --- a/tests/Mail/MailerTest.php +++ b/tests/Mail/MailerTest.php @@ -44,6 +44,20 @@ public function testProcessRecipients() $this->assertArrayHasKey('user@domain.tld', $result); $this->assertEquals('Adam Person', $result['user@domain.tld']); + /* + * Array of email addresses without names + */ + $recipients = [ + 'admin@domain.tld', + 'single@address.com', + 'charles@barrington.com', + ]; + $result = self::callProtectedMethod($mailer, 'processRecipients', [$recipients]); + $this->assertCount(3, $result); + $this->assertEquals('admin@domain.tld', $result[0]); + $this->assertEquals('single@address.com', $result[1]); + $this->assertEquals('charles@barrington.com', $result[2]); + /* * Array */ From 4f49035f28ecfc02ec244dc195ea01148716f7f5 Mon Sep 17 00:00:00 2001 From: Marc Jauvin Date: Mon, 7 Mar 2022 13:45:23 -0500 Subject: [PATCH 2/2] fix unit test --- tests/Mail/MailerTest.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/tests/Mail/MailerTest.php b/tests/Mail/MailerTest.php index 2f9148271..e1f9d4fcc 100644 --- a/tests/Mail/MailerTest.php +++ b/tests/Mail/MailerTest.php @@ -54,9 +54,10 @@ public function testProcessRecipients() ]; $result = self::callProtectedMethod($mailer, 'processRecipients', [$recipients]); $this->assertCount(3, $result); - $this->assertEquals('admin@domain.tld', $result[0]); - $this->assertEquals('single@address.com', $result[1]); - $this->assertEquals('charles@barrington.com', $result[2]); + foreach ($recipients as $key => $value) { + $this->assertArrayHasKey($value, $result); + $this->assertEquals(null, $result[$value]); + } /* * Array