sanfly Posted May 6, 2006 Share Posted May 6, 2006 Hi, Ive been trying out this PHP email validation script i found on the [a href=\"http://www.zend.com/zend/spotlight/ev12apr.php\" target=\"_blank\"]Zend Website[/a]The code[code]function validateEmail($email){ global $HTTP_HOST; // Check Format if(!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email)) { $result = "The email address is in an incorrect format"; return $result; } // Find Mail Server Address list($username, $domain) = split("@", $email); if(getmxrr($domain, $MXHost)){ $connectAddress = $MXHost[0]; } else{ $connectAddress = $domain; } // Check exists $connect = fsockopen($connectAddress, 25); if($connect){ if(ereg("^220", $out = fgets($connect, 1024))){ fputs($connect, "HELO $HTTP_HOST\r\n"); $out = fgets($connect, 1024); fputs($connect, "MAIL FROM: <{$email}>\r\n"); $from = fgets($connect, 1024); fputs ($connect, "RCPT TO: <{$email}>\r\n"); $to = fgets($connect, 1024); fputs($connect, "QUIT\r\n"); fclose($connect); if(!ereg ("^250", $from) || !ereg("^250", $to)){ $result = "Mail server rejected address"; return $result; } } else{ $result = "No response from mail server"; return $result; } } else{ $result = "Cannot connect to mail server"; return $result; } return true; }[/code]Some valid email addresses it rejects, ("Mail server rejected email address") so I changed the code to echo out the communications between me and the mail server. The error I was getting was only for the MAIL FROM portion...[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]220-We do not authorize the use of this system to transport unsolicited, and/or bulk e-mail[/quote]... but the RCPT TO portion was successfulWhat I assume this means is that they dont allow other servers to come in and send email address from that domain name, but they will recieve emails to that domain name. Can anyone verify this?The script is only being used to confirm email address for a mailing list, therefore I will only be sending emails to that address, so if my theory is correct i should be able to ignore the MAIL FROM error, or even remove that part of the code alltogether?Any help on this would be greatly appreciatedCheers Quote Link to comment https://forums.phpfreaks.com/topic/9210-email-address-validation-with-php/ Share on other sites More sharing options...
sanfly Posted May 8, 2006 Author Share Posted May 8, 2006 Bump Quote Link to comment https://forums.phpfreaks.com/topic/9210-email-address-validation-with-php/#findComment-34417 Share on other sites More sharing options...
High_-_Tek Posted May 9, 2006 Share Posted May 9, 2006 Well that seems a tad over-complicated to me...Try this (it does about the same thing)[code]$email = $_POST['u_email'];$parts = explode("@", $email);$host = $parts[1];if (!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email) && strlen($email) > 0) {die('Email Address is not Valid');}else{if (!f open($host, 'r')){die('Email Server is not Valid!');}}[/code]This checks to see if the addr is in the proper format and the domain host @xxxxx.yyy exists (yahoo.com, hotmail.com, etc):) Quote Link to comment https://forums.phpfreaks.com/topic/9210-email-address-validation-with-php/#findComment-34475 Share on other sites More sharing options...
sanfly Posted May 9, 2006 Author Share Posted May 9, 2006 Thanks, will give it a go tonight Quote Link to comment https://forums.phpfreaks.com/topic/9210-email-address-validation-with-php/#findComment-34477 Share on other sites More sharing options...
trq Posted May 9, 2006 Share Posted May 9, 2006 [!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]This checks to see if the addr is in the proper format and the domain host @xxxxx.yyy exists (yahoo.com, hotmail.com, etc)[/quote]Sorry, but fopen is at least going to need a proticol eg [b]http://[/b]yahoo.com, otherwise it looks for a local file. And who's to say all mail servers have a webpage? Mine doesn't. So... what proticol to look for? Quote Link to comment https://forums.phpfreaks.com/topic/9210-email-address-validation-with-php/#findComment-34478 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.