PHP and MySQL Web Development (4th Edition) by Welling Luke & Thomson Laura

PHP and MySQL Web Development (4th Edition) by Welling Luke & Thomson Laura

Author:Welling, Luke & Thomson, Laura [Welling, Luke]
Language: eng
Format: mobi
Publisher: Sams
Published: 2008-09-30T16:00:00+00:00


If the URL is valid, you then go on to check the email address. First, you split it into username and hostname with a call to explode():

$email = explode('@', $email);

$emailhost = $email[1];

When you have the host part of the address, you can check to see whether there is a place for that mail to go by using the dns_get_mx() function:

dns_get_mx($emailhost, $mxhostsarr);

This function returns the set of Mail Exchange (MX) records for an address in the array you supply at $mxhostsarr.

An MX record is stored at the DNS and is looked up like a hostname. The machine listed in the MX record isn’t necessarily the machine where the email will eventually end up. Instead, it’s a machine that knows where to route that email. (There can be more than one; hence, this function returns an array rather than a hostname string.) If you don’t have an MX record in the DNS, there’s nowhere for the mail to go.

Note that the dns_get_mx() function is not implemented in Windows versions of PHP. If you are using Windows, you should look into the PEAR::Net_DNS package, which will work for you (http://pear.php.net/package/NET_DNS).

If all these checks are okay, you can put this form data in a database for later review by a staff member.

In addition to the functions you just used, you can use the more generic function checkdnsrr(), which takes a hostname and returns true if any record of it appears in the DNS.



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.