validate an email adress
Moderator: General Moderators
Well here is what the backend does. Try it! It uses fsockopen to contact the remote mail server.Roja wrote:So which method are you using to ask it that? VRFY?
Nice script. Haven't had a proper look at the code, but do you use Ajax?bokehman wrote:Well here is what the backend does. Try it! It uses fsockopen to contact the remote mail server.Roja wrote:So which method are you using to ask it that? VRFY?
You didn't answer the question at all. You just posted another link to another script that also doesn't show what method it uses.bokehman wrote:Well here is what the backend does. Try it! It uses fsockopen to contact the remote mail server.Roja wrote:So which method are you using to ask it that? VRFY?
What request is it making via fsock to check if an address is valid? Is it simply checking if the mailserver of record will respond on a given port? Is it sending a VRFY request?
Please, be more specific. Saying "It uses fsockopen" leaves thousands of ports and thousands of commands it could be using.
I'm not sure what you mean by library. Isn't that a place from which you borrow books?
I just put a little bit of javascript in the webpage. Look at the page source and you will see. The code is forked so it works in mozilla and IE. Very simple. And the back end is just a normal php script but with the header "header('Content-Type: text/xml');".
I just put a little bit of javascript in the webpage. Look at the page source and you will see. The code is forked so it works in mozilla and IE. Very simple. And the back end is just a normal php script but with the header "header('Content-Type: text/xml');".
How right you are. It means something slightly different in the context of programming.bokehman wrote:I'm not sure what you mean by library. Isn't that a place from which you borrow books?
What I was referring to was something such as JSpan. If you don't know it yet, have a look.
No! I just connect to the remote mail server and send (amongst other things):Roja wrote:So which method are you using to ask it that? VRFY?bokehman wrote:This is nothing to do with REGEX. It is a real time connection with the remote mail server to see if it will accept mail for an address it has authority for.
RCPT TO:<your@email.com>
if the remote mailserver replies with:
'250 something...'
it means it is willing to accept mail for that address.
reg. Ajax: there's a nice background article over at Sitepoint: http://www.sitepoint.com/article/remote-scripting-ajax
Of course. I'm assuming you mean my PHP code!Roja wrote:Can you share the code, or list all the commands you use?
Here it is in a function. In places it may seem like there is unnecessary code but this is because different mailservers give diffent response and this needs to be taken into consideration. Anyway, enjoy!
Code: Select all
function check_email_address_exists($email)
{
$result = true;
// Extract the mail server name from the email address.
list ($user, $domain) = split ("@", $email);
if (getmxrr($domain, $mxhost)){
$ConnectAddress = $mxhost[0];
}else{
$ConnectAddress = $domain;
}
if(gethostbynamel($ConnectAddress) === FALSE){
return FALSE;
}
// Try to open a socket at the mail server address.
if($ConnectAddress == $domain){
$connect = @fsockopen($ConnectAddress, 25, $errno, $errstr, 5);
}else{
$tries = count($mxhost);
$i = 0;
$connect = @fsockopen($mxhost[$i], 25, $errno, $errstr, 5);
while(!$connect && !$tries == 0){
$i++;
$connect = @fsockopen($mxhost[$i], 25, $errno, $errstr, 5);
$tries--;
}
}
if ($connect)
{
if (ereg("^220", $out = fgets($connect, 1024)))
{
while(ereg('220', $out)){
$debug[] = 'Remote: '.$out;
stream_set_timeout($connect, 0, 5000);
$out = fgets ( $connect, 1024 );
stream_set_timeout($connect, 10);
}
$debug[] = "Local: EHLO {$_SERVER['HTTP_HOST']}";
fputs ($connect, "EHLO {$_SERVER['HTTP_HOST']}\r\n");
$out = fgets ( $connect, 1024 );
while(!ereg('^250', $out)&&(!empty($out))){
$debug[] = 'Remote: '.$out;
stream_set_timeout($connect, 0, 5000);
$out = fgets ( $connect, 1024 );
stream_set_timeout($connect, 10);
}
for($tries = 15; $tries > 0; $tries--){
if(ereg('^250', $out)){
$debug[] = 'Remote: '.$out;
$for_loop_hop = $out;
}elseif(empty($out)){
usleep(100000);
}else{
$debug[] = 'Remote: '.$out;
}
stream_set_timeout($connect, 0, 5000);
$out = fgets($connect, 1024);
stream_set_timeout($connect, 10);
}
if(!ereg('^250', $for_loop_hop)){
$debug[] = 'No 250';
if(isset($_GET['debug'])){
foreach($debug as $line){
echo $line.'<br>';
}
}
return FALSE;
}
$debug[] = htmlspecialchars("Local: MAIL FROM: <{$email}>\r\n");
fputs ($connect, "MAIL FROM: <{$email}>\r\n");
$from = fgets ( $connect, 1024 );
$debug[] = 'Remote: '.$from;
$debug[] = htmlspecialchars("Local: RCPT TO: <{$email}>\r\n");
fputs ($connect, "RCPT TO: <{$email}>\r\n");
$to = fgets ($connect, 1024);
$debug[] = 'Remote: '.$to;
$debug[] = "Local: QUIT\r\n";
fputs ($connect, "QUIT\r\n");
$quit = fgets ($connect, 1024);
$debug[] = 'Remote: '.$quit;
fclose($connect);
// Validate our exchange with the mail server.
// Server rejected address.
if (!ereg ("^250", $from) || !ereg ("^250", $to))
{
$result = false;
}
}
// Strange or no response from remote mail server.
else
{
$result = false;
}
}
// Can't connect to server.
else
{
$result = 'Failed to connect to remote mail server';
}
if(isset($_GET['debug'])){
if($debug > 0){
foreach($debug as $line){
print "$line <br />\r\n";
}
}
}
return $result;
}