× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



I am using a small PHP program to perform validation on e-mail domain names
using gethostbyname.

To perform a DNS lookup for an e-mail address, for example user@xxxxxxx you need to do this:

a) Look up the A record for "foo.com"
b) If (A) didn't work, look up the MX records for foo.com
c) Go through each MX record and look up the corresponding A record. At least one of those MX records needs to resolve to an IP address.

You can't do this with gethostbyname(). Actually, you could use gethostbyname() for the A records, but I wouldn't because gethostbyname() will use the host table if available, and that's not technically legal for e-mail.

For the MX records, gethostbyname() definitely won't work. You need to use the lower-level resolver routines for that. Namely, use res_search() to look up the MX records... the hard part is decoding the results from res_search which are in a compressed format.

I have samples of doing that, but I've only written those routines in C and RPG, never in PHP.

I found that some domains (e.g. xyz.com) gave false fails, so I adapted the
program to also try mail.xxx.xxx.  I'm still seeing failures on some
addresses that are supposed to be good.  Any ideas on what else to check?

No, don't make up domain names. If the e-mail address is user@xxxxxxx, don't look up mail.foo.com, that's not how e-mail works.


As an Amazon Associate we earn from qualifying purchases.

This thread ...

Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.