You are here

protected function ContactEmailer::removeInvalidEmails in Contact Emails 8

Remove invalid emails.

Parameters

array $emails: An array of potentially valid emails.

Return value

array An array of valid emails.

1 call to ContactEmailer::removeInvalidEmails()
ContactEmailer::getTo in src/ContactEmailer.php
Get who to send the email to.

File

src/ContactEmailer.php, line 171

Class

ContactEmailer
Class ContactEmailer.

Namespace

Drupal\contact_emails

Code

protected function removeInvalidEmails(array $emails) {
  $valid_emails = [];
  foreach ($emails as $email) {
    if ($this->emailValidator
      ->isValid($email)) {
      $valid_emails[] = $email;
    }
    else {
      $error = $this
        ->t('The following email does not appear to be valid and was not sent to: @email', [
        '@email' => $email,
      ]);
      $this->messenger
        ->addWarning($error);
    }
  }
  return $valid_emails;
}