Esempio n. 1
0
 public function testIsEmail()
 {
     $this->assertTrue(StringUtils::isEmail('*****@*****.**'));
     $this->assertTrue(StringUtils::isEmail('*****@*****.**'));
     $this->assertTrue(StringUtils::isEmail('*****@*****.**'));
     $this->assertTrue(StringUtils::isEmail('*****@*****.**'));
     $this->assertTrue(StringUtils::isEmail('*****@*****.**'));
     $this->assertFalse(StringUtils::isEmail('----this-is-not-an-(email)(most)+(definitely)@email.com'));
     $this->assertFalse(StringUtils::isEmail('non-email-string'));
     $this->assertFalse(StringUtils::isEmail('pretending@tobeemail'));
     $this->assertFalse(StringUtils::isEmail('@undefined'));
     $this->assertFalse(StringUtils::isEmail(''));
 }
Esempio n. 2
0
 /**
  * Verifies the given email address does it fit the patterns of email addresses for the Mailer.
  * 
  * It can be an email string, an array of email strings or an array where keys are emails and values are names.
  * 
  * @param string|array $address Address to verify.
  * @param bool $allowMulti Are multiple emails allowed? Default: true.
  * @return bool
  * 
  * @throws InvalidArgumentException When $address is neither string nor array.
  */
 public function verifyEmailAddress($address, $allowMulti = true)
 {
     if (!is_string($address) && !is_array($address)) {
         throw new InvalidArgumentException('string or array', $address);
     }
     if (is_string($address)) {
         return StringUtils::isEmail($address);
     }
     if (!$allowMulti && count($address) > 1) {
         return false;
     }
     foreach ($address as $key => $value) {
         if (is_string($key)) {
             if (!StringUtils::isEmail($key)) {
                 return false;
             }
         } else {
             if (!StringUtils::isEmail($value)) {
                 return false;
             }
         }
     }
     return true;
 }