I have been looking for a good email verification script and I seem to find the same one coming up all over the place. I like everything i read about it. I have implemented it but there is one glitch i cannot figure out. It uses fsockopen to verify a domain name and when the domain does not exist it displays the traditional PHP warnings at the top of the screen instead of being caught like (i think) it is supposed to be. When the domain is good, no errors occur. here are the warnings. (code below)

"Warning: fsockopen() [function.fsockopen]: php_network_getaddresses: getaddrinfo failed: Name or service not known in /home/vcsvaul9/public_html/clients/changeemail.php on line 27

Warning: fsockopen() [function.fsockopen]: unable to connect to vcsvault.co:25 (Unknown error) in /home/vcsvaul9/public_html/clients/changeemail.php on line 27"

Here is the code I am using for verification. Line 27 is the fsockopen line.:

function checkEmail($email) 
{
   if(eregi("^[a-zA-Z0-9_]+@[a-zA-Z0-9\-]+\.[a-zA-Z0-9\-\.]+$]", $email)) 
   {
      return FALSE;
   }

   list($Username, $Domain) = split("@",$email);

   if(getmxrr($Domain, $MXHost)) 
   {
      return TRUE;
   }
   else 
   {
      if(fsockopen($Domain, 25, $errno, $errstr, 30))  //LINE 27!!!
      {
         return TRUE; 
      }
      else 
      {
         return FALSE; 
      }
   }
}

Thanks!!
Daiv

    BTW,

    I am running it on a linux machine with PHP 5.0.4.

    Thanks.

      Well it raises a warning because it can't open the connection. Put @ in front of fsockopen.

      @fsockopen

      By the way the script is absolutely pointless as far as verifying an email is good. All it does is waste time looking up details about the authoritative mailserver for an address but doesn't even interogate that mailserver to check it will recieve for the address in question let alone validate it. The only true way to validate is send an email to it and wait for a reply.

        Thanks for the help! the @ did the trick.

        I am aware that this script will not validate if the actual email address exists, but it does validate that the domain exists.

        This is important to me because I will be sending the inputed email address a daily log and it is a pay service. While it is still their responsibility to enter the correct address, at least this can verify that the email format is correct and the domain is correct. I want to eliminate as many problems as possible that the client might encounter otherwise it increases my work helping them troubleshoot it, even if it is just a typo on their end.

        Cheers and good day!
        Daiv07.

          [man]gethostbyname[/man] (and [man]gethostbyaddr[/man]) will do a DNS (and reverse DNS) lookup of whatever you give it. Assuming a DNS record exists, one or the other will work (depending on whether the email address uses the domain name or the IP).

          Also, note what it says on the [man]getmxrr[/man] page:

          Note:This function should not be used for the purposes of address verification. ...

            Write a Reply...