Validating Emails Part2
- Posted by thomasw at 00:42:54 // //
- Validate
Hy interesting ones,
It’s time for a second blog entry about Zend_Validate_EmailAddress. The last two weeks I reworked it again and implemented some new features which could come handy to you.
*) Deep nested mail Server detection
The mail server detection is now much more able to detect mail servers based on their records.
A mail server can have a MX record. This was already supported in past by giving a true as second parameter:
$valid = new Zend_Validate_EmailAddress(Zend_Validate_Hostname::ALLOW_DNS, true);
Now with ZF 1.10 you can do a deep nested detection. This means that not only the MX record, but also the A, AAAA and A6 records are used to detect a mail server. These records can be used by a mail server as replacement for the MX record.
$valid = new Zend_Validate_EmailAddress(array('mx' => true, 'deep' => true);
Additionally we made the check more secure as invalid IP addresses are no longer accepted. MX checks are only usefull and allowed for external servers. This means that for example 192.168.* addresses are no longer valid for a MX check.
You should be aware that these two options use network functions of your OS. This means that they need some time as the records are fetched from your network.
*) Local validation
As with ZF 1.10 it is also possible to do only a validation of the local part, and ignore the domain part of the email address.
$valid = new Zend_Validate_EmailAddress(array('domain' => true);
Even if this is the fastest way for a email address verification, you should be aware that it can be a problem when you store or use the unchecked domain part.
*) Array and Zend_Config options
All validators, and also the email validator have now support for parameters as array, or by Zend_Config.
This simplifies usage and is better for readability.
$valid = new Zend_Validate_EmailAddress(array('domain' => true);
or
$valid = new Zend_Validate_EmailAddress(new Zend_Config_Ini('/path/to/config.ini'));
I hope you find this new features usefull.
Have a good work with Zend Framework.
Greetings
Thomas Weidner
I18N Team Leader, Zend Framework
Zend Framework Advisory Board Member
Zend Certified Engineer for Zend Framework
