Skip to content

Commit

Permalink
Fixes for multiple emails + format tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
rhukster committed Feb 28, 2023
1 parent 6bdfd96 commit 6414501
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
# v4.0.0-rc.4
## 02/27/2023

1. [](#bugfix)
* Fixed for multiple recipients [#167](https://github.com/getgrav/grav-plugin-email/issues/167)
* Fix for simple array format with names which wasn't working

# v4.0.0-rc.3
## 10/27/2022

Expand Down
22 changes: 16 additions & 6 deletions classes/Email.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ public function buildMessage(array $params, array $vars = []): Message
// Create message object.
$message = new Message();
$headers = $message->getEmail()->getHeaders();
$email = $message->getEmail();

// Extend parameters with defaults.
$params += [
Expand Down Expand Up @@ -201,9 +202,9 @@ public function buildMessage(array $params, array $vars = []): Message
case 'cc':
case 'bcc':
case 'reply_to':
$recipients = $this->processRecipients($key, $params);
foreach ($recipients as $address) {
$message->$key($address);
if ($recipients = $this->processRecipients($key, $params)) {
$key = $key === 'reply_to' ? 'replyTo' : $key;
$email->$key(...$recipients);
}
break;
case 'tags':
Expand Down Expand Up @@ -241,9 +242,13 @@ protected function processRecipients(string $type, array $params): array
if (is_array($recipients) && Utils::isAssoc($recipients)) {
$list[] = $this->createAddress($recipients);
} else {
if (is_array($recipients[0])) {
foreach ($recipients as $recipient) {
$list[] = $this->createAddress($recipient);
if (is_array($recipients)) {
if (count($recipients) ===2 && $this->isValidEmail($recipients[0]) && is_string($recipients[1])) {
$list[] = $this->createAddress($recipients);
} else {
foreach ($recipients as $recipient) {
$list[] = $this->createAddress($recipient);
}
}
} else {
if (is_string($recipients) && Utils::contains($recipients, ',')) {
Expand Down Expand Up @@ -450,6 +455,11 @@ protected function jsonifyRecipients(array $recipients): string
return json_encode($json);
}

protected function isValidEmail($email): bool
{
return is_string($email) && filter_var($email, FILTER_VALIDATE_EMAIL) !== false;
}

/**
* @return void
* @deprecated 4.0 Switched from Swiftmailer to Symfony/Mailer - No longer supported
Expand Down

0 comments on commit 6414501

Please sign in to comment.