Forum |  HardWare.fr | News | Articles | PC | S'identifier | S'inscrire | Shop Recherche
1611 connectés 

  FORUM HardWare.fr
  Programmation
  PHP

  Utilisation d'une fonction..

 


 Mot :   Pseudo :  
 
Bas de page
Auteur Sujet :

Utilisation d'une fonction..

n°1563758
ncdetoulou​se
Posté le 23-05-2007 à 00:52:40  profilanswer
 

Hello à tous !
 
J'ai le script de la fonction suivante ci-dessous, et je ne parviens pas à l'utiliser ..
Bien utilisée, elle doit donner le meme résultat que sur http://www.tienhuis.nl/php-email-a [...] ify-probe/
Merci à celui qui arrivera à m'aider ..
 
Excellente semaine à tous en tout cas :-)
 
 
<?
 
highlight_file(__FILE__);
 
function validateEmail($email, $domainCheck = false, $verify = false, $return_errors=false) {
    global $debug;
    if($debug) {echo "<pre>";}
    $errors = array();
    # Check syntax with regex
    if (preg_match('/^([a-zA-Z0-9\._\+-]+)\@((\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,7}|[0-9]{1,3})(\]?))$/', $email, $matches)) {
        $user = $matches[1];
        $domain = $matches[2];
        # Check availability of DNS MX records
        if ($domainCheck && function_exists('checkdnsrr')) {
            # Construct array of available mailservers
            if(getmxrr($domain, $mxhosts, $mxweight)) {
                for($i=0;$i<count($mxhosts);$i++){
                    $mxs[$mxhosts[$i]] = $mxweight[$i];
                }
                asort($mxs);
                $mailers = array_keys($mxs);
            } elseif(checkdnsrr($domain, 'A')) {
                $mailers[0] = gethostbyname($domain);
            } else {
                $mailers=array();
            }
            $total = count($mailers);
            # Query each mailserver
            if($total > 0 && $verify) {
                # Check if mailers accept mail
                for($n=0; $n < $total; $n++) {
                    # Check if socket can be opened
                    if($debug) { echo "Checking server $mailers[$n]...\n";}
                    $connect_timeout = 2;
                    $errno = 0;
                    $errstr = 0;
                    $probe_address = 'postmaster@tienhuis.nl';
                    # Try to open up socket
                    if($sock = @fsockopen($mailers[$n], 25, $errno , $errstr, $connect_timeout)) {
                        $response = fgets($sock);
                        if($debug) {echo "Opening up socket to $mailers[$n]... Succes!\n";}
                        stream_set_timeout($sock, 5);
                        $meta = stream_get_meta_data($sock);
                        if($debug) { echo "$mailers[$n] replied: $response\n";}
                        $cmds = array(
                            "HELO outkast.tienhuis.nl",  # Be sure to set this correctly!
                            "MAIL FROM: <$probe_address>",
                            "RCPT TO: <$email>",
                            "QUIT",
                        );
                        # Hard error on connect -> break out
                        if(!$meta['timed_out'] && !preg_match('/^2\d\d[ -]/', $response)) {
                            $error = "Error: $mailers[$n] said: $response\n";
                            break;
                        }
                        foreach($cmds as $cmd) {
                            $before = microtime(true);
                            fputs($sock, "$cmd\r\n" );
                            $response = fgets($sock, 4096);
                            $t = 1000*(microtime(true)-$before);
                            if($debug) {echo htmlentities("$cmd\n$response" ) . "(" . sprintf('%.2f', $t) . " ms)\n";}
                            if(!$meta['timed_out'] && preg_match('/^5\d\d[ -]/', $response)) {
                                $error = "Unverified address: $mailers[$n] said: $response";
                                break 2;
                            }
                        }
                        fclose($sock);
                        if($debug) { echo "Succesful communication with $mailers[$n], no hard errors, assuming OK";}
                        break;
                    } elseif($n == $total-1) {
                        $errors = "None of the mailservers listed for $domain could be contacted";
                    }
                }
            } else {
                $error = "No usable DNS records found for domain '$domain'";
            }
        }
    } else {
        $error = 'Address syntax not correct';
    }
    if($debug) { echo "</pre>";}
    #echo "</pre>";
    if($return_errors) {
        # Give back details about the error(s).
        # Return FALSE if there are no errors.
        # Keep this in mind when using it like:
        # if(checkEmail($addr)) {
        # Because of this strange behaviour this
        # is not default ;-)
        if(isset($error)) return htmlentities($error); else return false;
    } else {
        # 'Old' behaviour, simple to understand
        if(isset($error)) return false; else return true;
    }
}
 
 
?>

mood
Publicité
Posté le 23-05-2007 à 00:52:40  profilanswer
 

n°1563761
naceroth
Posté le 23-05-2007 à 01:24:05  profilanswer
 

Mais encore ? "je parviens pas à l'utiliser", c'est vachement parlant comme explication...

n°1563822
ncdetoulou​se
Posté le 23-05-2007 à 10:44:51  profilanswer
 

Comment tester une adresse email avec ce script ?

n°1563859
omega2
Posté le 23-05-2007 à 11:35:57  profilanswer
 

En faisant par exemple :

Code :
  1. if (validateEmail("monadresse@mondomaine.com" ) ){
  2. echo "tout est OK";
  3. }else{
  4. echo "pas bon";
  5. }

si tu veux juste vérifier le format de l'adresse
 
ou

Code :
  1. if (validateEmail("monadresse@mondomaine.com",true,true) ){
  2. echo "tout est OK";
  3. }else{
  4. echo "pas bon";
  5. }


si tu veux qu'il vérifie l'existance réelle de l'adresse. (plus long voire beaucoup beaucoup plus long si le serveur distant ne répond pas et ca ne marche que si le serveur autorise les conections à d'autres serveurs)

n°1563867
ncdetoulou​se
Posté le 23-05-2007 à 11:43:48  profilanswer
 

Merci beaucoup ça fonctionne !!
Encore merci !
Je vais analyser tout ça pour pouvoir me débrouiller moi mm la prochaine fois ;)


Aller à :
Ajouter une réponse
  FORUM HardWare.fr
  Programmation
  PHP

  Utilisation d'une fonction..

 

Sujets relatifs
Inno Setup (utilisation de la fonction WorkingDir)Utilisation d'une fonction ?
Utilisation de la fonction CopyFile en vbsUtilisation de la fonction time
Utilisation de la fonction splitUtilisation fonction md5crypt (ou crypter en md5 unix)
utilisation fonction perso sous excelUtilisation d'une fonction écrite en C++
Utilisation d'une fonction d'une dllutilisation d'une fonction excel avec VB
Plus de sujets relatifs à : Utilisation d'une fonction..


Copyright © 1997-2022 Hardware.fr SARL (Signaler un contenu illicite / Données personnelles) / Groupe LDLC / Shop HFR