The problem with that script is that it only checks if the e-mail has been sent to an adress, not the actual adress it self.
What I wanted to do was to check the inputted e-mail address for bad letters, bad domain etc. The script does that as it is quite fine but would be great to get some more feedback on parts you can make better.
I have made a better version which is a bit cleaned up and it looks like this.
PHP Code:
function verify($email){ // If no e-mail address is inputted to begin with the user will get an error message. if(!isset($email)){ // Return incorrect e-mail to main site. return -1; } // Check so the e-mail uses allowed chars and correct structure. // If match not made it sends user back to form. if (!preg_match('/^[^\x00-\x20()<>@,;:\\".[\]\x7f-\xff]+(?:\.[^\x00-\x20()<>@,;:\\".[\]\x7f-\xff]+)*\@[^\x00-\x20()<>@,;:\\".[\]\x7f-\xff]+(?:\.[^\x00-\x20()<>@,;:\\".[\]\x7f-\xff]+)+$/i', $email)){ // Return incorrect e-mail to main site. return -2; } // Grab the domain from the e-mail adress. $domain = strstr($email, '@'); $domain = substr($domain, 1); // Shifts selection by one so not @ is added with the domain. // Checks that the domain is resolved to an IP. // If hostname isn't resolved to and IP user is sent back to form. if (!ip2long(gethostbyname($domain))){ // Return incorrect e-mail to main site. return -3; } // It passed all the tests, hurrah for us! return 0; }
As I see it this is the best to do it. I have seen scripts that checks the domain through its DNS to see if it has Mail Exchange registerd on it. But when i read more aobut it not all DNS servers and domain/IPs has this flag so it might turn down a valid e-mail due to that they cannot find a MX-flag on the IP.
|