You are here

private function SparkpostMail::createRecipientField in Sparkpost email 8.2

Helper to generate an array of recipients.

Parameters

mixed $to: A comma delimited list of email addresses in 1 of 2 forms: user@domain.com any number of names <user@domain.com>.

Return value

array array of email addresses

1 call to SparkpostMail::createRecipientField()
SparkpostMail::mail in src/Plugin/Mail/SparkpostMail.php
Sends a message composed by \Drupal\Core\Mail\MailManagerInterface->mail().

File

src/Plugin/Mail/SparkpostMail.php, line 245

Class

SparkpostMail
Sparkpost mail plugin.

Namespace

Drupal\sparkpost\Plugin\Mail

Code

private function createRecipientField($to) {
  $recipients = [];
  $to_array = explode(',', $to);
  foreach ($to_array as $email) {
    if (preg_match(ClientService::EMAIL_REGEX, $email, $matches)) {
      $recipients[] = [
        'address' => [
          'name' => $matches[1],
          'email' => $matches[2],
        ],
      ];
    }
    else {
      $recipients[] = [
        'address' => [
          'email' => $email,
        ],
      ];
    }
  }
  return $recipients;
}