You are here

function sparkpost_get_to in Sparkpost email 7.2

Same name and namespace in other branches
  1. 7 sparkpost.module \sparkpost_get_to()

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 sparkpost_get_to()
SparkpostMailSystem::mail in includes/sparkpost.mail.inc
Send the email message.

File

./sparkpost.module, line 113
Sparkpost integration.

Code

function sparkpost_get_to($to) {
  $recipients = array();
  $to_array = explode(',', $to);
  foreach ($to_array as $email) {
    if (preg_match(SPARKPOST_EMAIL_REGEX, $email, $matches)) {
      $recipients[] = array(
        'address' => array(
          'name' => $matches[1],
          'email' => $matches[2],
        ),
      );
    }
    else {
      $recipients[] = array(
        'address' => array(
          'email' => $email,
        ),
      );
    }
  }
  return $recipients;
}