Foros del Web » Programando para Internet » PHP »

Verificar si mail existe

Estas en el tema de Verificar si mail existe en el foro de PHP en Foros del Web. Bueno, antes que nada, quiero avisar que me lei absolutamente todos los post que tenian las palabras "mail existe" dentro de la categoria php. Tambien ...
  #1 (permalink)  
Antiguo 19/06/2005, 14:49
 
Fecha de Ingreso: marzo-2005
Mensajes: 171
Antigüedad: 19 años, 2 meses
Puntos: 0
Pregunta Verificar si mail existe

Bueno, antes que nada, quiero avisar que me lei absolutamente todos los post que tenian las palabras "mail existe" dentro de la categoria php. Tambien me lei las FAQ y busque por internet, pero no encontre nada.
Tengo un script que lo que hace es verificar si existe un determinado email. Primero verifica la sintaxis, luego verifica si existe el dominio y por ultimo, si existe el email.
El script es el siguiente:

Código PHP:
<?php

if (!$HTTP_POST_VARS){
echo 
"<html><body>
<form action=p2.php method=POST>
 <input type=text name=mail>
 <input type=submit name=boton value=Aceptar>
 </form>
</html>"
;
}

else {
ValidateMail($mail);

// Step 1 -- Initialize the script
// The first step in any script, of course, is to initialize any variables you'll be using. In this case, declare any global variables you'll be using:

        
function ValidateMail($Email) {
            global 
$HTTP_HOST;
    
$result = array();

// Step 2 -- Check the e-mail address format

// Next, you'll use our regular expression to determine if the e-mail address is properly formatted. If the e-mail address is not valid, return in error:
if (!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$"$Email)) {

  
$result[0]=false;
        
$result[1]="$Email is not properly formatted";
        return 
$result;
    }

// Step 3 -- Find the address of the mail server

// Now, split apart the e-mail address and use the domain name to search for a mail server you can use to further check the e-mail address. If no mail server is found, you'll just use the domain address as a mail server address:

// Note: In the event that the optional step 4 is not followed, the else portion of this step must return in error in order for the script to function properly.

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

   if (
getmxrr($Domain$MXHost))  {

        
$ConnectAddress $MXHost[0];
    } else {

        
$ConnectAddress $Domain;

    }

// Step 4 -- Connect to mail server and check e-mail address (OPTIONAL)

// Finally, once you have the best guess at a mail server, it's time to open a connection and talk to the server. As I stated earlier, this step is optional. After every command you send, you'll need to read a kilobyte (1024 bytes) of data from the server. It should be more than enough to receive the complete response from the server for that command.

// Note that you'll store the output from the server in three separate variables: $To, $From and $Out. This is done so you can check the responses after you close the connection, to see if you actually have a real e-mail address or not.

// If the script cannot connect at all, or the e-mail address wasn't valid, set the $result array to the proper values:

        
$Connect fsockopen $ConnectAddress25 );

    if (
$Connect) {

        if (
ereg("^220"$Out fgets($Connect1024))) {

           
fputs ($Connect"HELO $HTTP_HOST\r\n");
           
$Out fgets $Connect1024 );
           
fputs ($Connect"MAIL FROM: <{$Email}>\r\n");
           
$From fgets $Connect1024 );
           
fputs ($Connect"RCPT TO: <{$Email}>\r\n");
           
$To fgets ($Connect1024);
           
fputs ($Connect"QUIT\r\n");
           
fclose($Connect);
            if (!
ereg ("^250"$From) ||
!
ereg "^250"$To )) {
               
$result[0]=false;
               
$result[1]="Server rejected address";
               return 
$result;

            }
        } else {

            
$result[0] = false;
            
$result[1] = "No response from server";
            return 
$result;
          }

    }  else {

        
$result[0]=false;
        
$result[1]="Can not connect E-Mail server.";
        return 
$result;
    }

// Step 5 -- Return the results

// Finally, our last and easiest step is to return the results and finish:
    
$result[0]=true;
    
$result[1]="$Email appears to be valid.";
    return 
$result;
// end of function
}
?>
Bueno, como soy totalmente nuevo en PHP, quisiera saber si alguien conoce algun tutorial que explique paso a paso como funciona el script. Si nadie conoce, por lo menos, expliquenme que hago con el $result, ya que el mail exista o no, no me aparece nada. Cada tanto me tira un un error de que no se puede conectar en esta linea:

Código PHP:
        $Connect fsockopen $ConnectAddress25 ); 
Pero creo que eso es por timeout, porque esta un tiempo pensando y luego me tira el error. Lo que probe, fue poner un echo $result al final de todo, pero unicamente me indica cuando el email es correcto, si esta mal no me dice nada.
Bueno, agradezco cualquier tipo de ayuda o explicacion que alguien me proporcione. Es mas, si alguien se juega haciendo un tutorial (se que es mucho pedir, pero no existe ninguno por la red) seria perfecto. Muchisimas gracias.
Francisco Dimattia
  #2 (permalink)  
Antiguo 20/06/2005, 19:02
 
Fecha de Ingreso: marzo-2005
Mensajes: 171
Antigüedad: 19 años, 2 meses
Puntos: 0
Nadie que pueda ayudarme???
Por favor......................
  #3 (permalink)  
Antiguo 10/04/2008, 12:48
 
Fecha de Ingreso: marzo-2008
Ubicación: Pereira
Mensajes: 2
Antigüedad: 16 años, 1 mes
Puntos: 0
Re: Verificar si mail existe

Mi apreciado amigo, el codigo que colocaste me fue muy util, muchas gracias,no entiendo porque no te funciono.

Lo unico que hice fue lo siguiente:

1 Asigne una variable con el resultado de la funcion:
$variable= ValidateMail($correo);

2. Para conocer el resultado solo hice un echo dandole la posicion uno ya que el resultado que retorna la funcion es en forma de array.
echo $variable[1];

Otra cosa mas que le agregue fue esta funcion: error_reporting(0); con el fin que cuando el dominio fuera falso no mostrara los errores de php.


Aunque tengo para decirte que probe el script localmente en mi pc y no me funciono, pero lo subi al hosting y funciono perfecto
  #4 (permalink)  
Antiguo 10/11/2009, 20:10
 
Fecha de Ingreso: febrero-2005
Mensajes: 183
Antigüedad: 19 años, 2 meses
Puntos: 0
Respuesta: Verificar si mail existe

Hola, se q es tarde pero tengo entendido q solo funciona con un servidor linux, si lo estas corriendo local/localhost en tu pc bajo windows no funcionara.

Salu2
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Tema Cerrado




La zona horaria es GMT -6. Ahora son las 06:12.