Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/Mail/Mailer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'], [...] ]
Expand All @@ -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)) {
Expand Down
15 changes: 15 additions & 0 deletions tests/Mail/MailerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,21 @@ 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);
foreach ($recipients as $key => $value) {
$this->assertArrayHasKey($value, $result);
$this->assertEquals(null, $result[$value]);
}

/*
* Array
*/
Expand Down