Yii 1.1: emailvalidator

Email validator

EEmailValidator is a validator class which relies on Manuel Lemos' e-mail address validation class (see that class for further dependencies)

This validator performs basic regex validation and some advanced checks using getmxrr to verify the validity of a given e-mail address.

Manuel Lemos' class uses an alternate GetMXRR function from the DNSResolver code by Moriyoshi Koizumi, in case the getmxrr function is not available or is not working. His code is not OOP, so I tried to make PHP5 classes with it, but it's not fully tested, so, if you don't have a working getmxrr or are under windows, either use it under your own risk or send me patches ;)

Please read the source code for the meaning of the various properties.




  • Yii 1.0 or above


  • Extract the release file under protected/extensions


In the view:

<?php echo CHtml::activeLabel($user, 'email'); ?>
<?php echo CHtml::activeTextField($user, 'email', 
        array('title'=>Yii::t('demo', 'Enter your e-mail'))); ?>
<?php echo CHtml::error($user, 'email'); ?>

In the model:

class UserModel extends CFormModel
   public $email;
   public function rules()
      return array(
   public function attributeLabels()
      return array(
         'email'=>Yii::t('demo', 'Enter your e-mail address: '),

Total 5 comments

#6068 report it
Sebastian K. at 2011/12/09 03:03pm
Attention: "strictValidation = true" is not reliable

Be careful using the strict option, it might reject valid email addresses! I changed EEmailValidator line 138 to just use the host validation:

if ((($result = $validator->ValidateEmailHost($email, $hosts))<0) && ($this->strictValidation)) $valid = false;

Thus I have a "medium-strict" variant, which is much more reliable to use for commercial websites.

btw: you can replace "ereg" by "preg_match" if you run on PHP 5.3

#3573 report it
MetaYii at 2011/04/19 04:56pm
Answer at the forum

Hi jeanluca, I'm explaining at the forum.

#3564 report it
jeanluca at 2011/04/19 07:12am

I tried to translate the message 'The e-mail address is invalid', but it didn't work, but when I changed the Category from 'yii' to 'errors' it worked.

$message = $this->message !== null ? $this->message : Yii::t('errors', 'The e-mail address is invalid.');

From the documentation:

The category yii is reserved for messages used by the Yii Framework core code.


#3537 report it
jeanluca at 2011/04/18 09:55am


Is there any chance this extension can be update. Its complaining that the function ereg is deprecated!


#717 report it
corpix at 2010/03/12 10:05pm

Good thing... i try to use emailsintaxvalidator... it`s most popular...but not working :D This is good solution for me!

Leave a comment

Please to leave your comment.

Create extension
  • Yii Version: 1.1
  • License: New BSD License
  • Developed by: MetaYii
  • Category: Validation
  • Votes: +3
  • Downloaded: 1,715 times
  • Created on: Nov 19, 2008
  • Last updated: Dec 8, 2008