You are here

public static function PHPMailer::ValidateAddress in SMTP Authentication Support 7

Same name and namespace in other branches
  1. 7.2 smtp.phpmailer.inc \PHPMailer::ValidateAddress()

Check that a string looks roughly like an email address should Static so it can be used without instantiation Tries to use PHP built-in validator in the filter extension (from PHP 5.2), falls back to a reasonably competent regex validator Conforms approximately to RFC2822 @link http://www.hexillion.com/samples/#Regex Original pattern found here

@static @access public

Parameters

string $address The email address to check:

Return value

boolean

2 calls to PHPMailer::ValidateAddress()
PHPMailer::AddAnAddress in ./smtp.phpmailer.inc
Adds an address to one of the recipient arrays Addresses that have been added already return FALSE, but do not throw exceptions
PHPMailer::SetFrom in ./smtp.phpmailer.inc
Set the From and FromName properties

File

./smtp.phpmailer.inc, line 542
The mail handler class in smtp module, based on code of the phpmailer library, customized and relicensed to GPLv2.

Class

PHPMailer
PHPMailer - PHP email transport class NOTE: Requires PHP version 5 or later @package PHPMailer @author Andy Prevost @author Marcus Bointon @copyright 2004 - 2009 Andy Prevost

Code

public static function ValidateAddress($address) {
  if (function_exists('filter_var')) {

    //Introduced in PHP 5.2
    if (filter_var($address, FILTER_VALIDATE_EMAIL) === FALSE) {
      return FALSE;
    }
    else {
      return TRUE;
    }
  }
  else {
    return preg_match('/^(?:[\\w\\!\\#\\$\\%\\&\'\\*\\+\\-\\/\\=\\?\\^\\`\\{\\|\\}\\~]+\\.)*[\\w\\!\\#\\$\\%\\&\'\\*\\+\\-\\/\\=\\?\\^\\`\\{\\|\\}\\~]+@(?:(?:(?:[a-zA-Z0-9_](?:[a-zA-Z0-9_\\-](?!\\.)){0,61}[a-zA-Z0-9_-]?\\.)+[a-zA-Z0-9_](?:[a-zA-Z0-9_\\-](?!$)){0,61}[a-zA-Z0-9_]?)|(?:\\[(?:(?:[01]?\\d{1,2}|2[0-4]\\d|25[0-5])\\.){3}(?:[01]?\\d{1,2}|2[0-4]\\d|25[0-5])\\]))$/', $address);
  }
}