|
|
@ -38,11 +38,22 @@ class EmailValidator extends Validator |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public $allowName = false; |
|
|
|
public $allowName = false; |
|
|
|
/** |
|
|
|
/** |
|
|
|
* @var boolean whether to check the MX record for the email address. |
|
|
|
* @var boolean whether to check whether the emails domain exists and has either an A or MX record. |
|
|
|
* Defaults to false. To enable it, you need to make sure the PHP function 'checkdnsrr' |
|
|
|
* Be aware of the fact that this check can fail due to temporary DNS problems even if the email address is |
|
|
|
* exists in your PHP installation. |
|
|
|
* valid and an email would be deliverable. Defaults to false. |
|
|
|
|
|
|
|
* @see dnsMessage |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public $checkMX = false; |
|
|
|
public $checkDNS = false; |
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* @var string the error message to display when the domain of the email does not exist. |
|
|
|
|
|
|
|
* It may contain the following placeholders which will be replaced accordingly by the validator: |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* - `{attribute}`: the label of the attribute being validated |
|
|
|
|
|
|
|
* - `{value}`: the value of the attribute being validated |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* @see checkDNS |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
public $dnsMessage; |
|
|
|
/** |
|
|
|
/** |
|
|
|
* @var boolean whether to check port 25 for the email address. |
|
|
|
* @var boolean whether to check port 25 for the email address. |
|
|
|
* Defaults to false. |
|
|
|
* Defaults to false. |
|
|
@ -69,6 +80,9 @@ class EmailValidator extends Validator |
|
|
|
if ($this->message === null) { |
|
|
|
if ($this->message === null) { |
|
|
|
$this->message = Yii::t('yii', '{attribute} is not a valid email address.'); |
|
|
|
$this->message = Yii::t('yii', '{attribute} is not a valid email address.'); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if ($this->dnsMessage === null) { |
|
|
|
|
|
|
|
$this->dnsMessage = Yii::t('yii', 'The domain of this email address does not seem to exist.'); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
@ -105,8 +119,8 @@ class EmailValidator extends Validator |
|
|
|
} |
|
|
|
} |
|
|
|
$valid = preg_match($this->pattern, $value) || $this->allowName && preg_match($this->fullPattern, $value); |
|
|
|
$valid = preg_match($this->pattern, $value) || $this->allowName && preg_match($this->fullPattern, $value); |
|
|
|
if ($valid) { |
|
|
|
if ($valid) { |
|
|
|
if ($this->checkMX && function_exists('checkdnsrr')) { |
|
|
|
if ($this->checkDNS) { |
|
|
|
$valid = checkdnsrr($domain, 'MX'); |
|
|
|
$valid = checkdnsrr($domain, 'MX') || checkdnsrr($domain, 'A'); |
|
|
|
} |
|
|
|
} |
|
|
|
if ($valid && $this->checkPort && function_exists('fsockopen')) { |
|
|
|
if ($valid && $this->checkPort && function_exists('fsockopen')) { |
|
|
|
$valid = fsockopen($domain, 25) !== false; |
|
|
|
$valid = fsockopen($domain, 25) !== false; |
|
|
|