Changeset 463

Show
Ignore:
Timestamp:
03/08/08 10:46:31 (7 months ago)
Author:
syrus
Message:

Ajout du test d email par connexion au serveur destinataire

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • wifidog/wifidog-auth/wifidog/classes/Mail.php

    r42 r463  
    4848require_once('lib/PHPMailer/class.smtp.php'); 
    4949 
     50require('Net/SMTP.php'); 
     51 
    5052/** 
    5153 * This a wrapper class conforming RFC822 capable of sending valid UTF-8 MIME 
     
    344346 
    345347        /** 
     348         * Test email onto MX host 
     349         * 
     350         * This function performs a test to MX host, and check if e-mail is valid or not 
     351         * 
     352         * @param string $srv Server to test 
     353         * @param string $email  The email to validate 
     354         * 
     355         * @return bool Returns if email exists or not 
     356         * 
     357         * @static 
     358         * @access public 
     359         */ 
     360 
     361        public function testMail($srv, $email) 
     362        { 
     363 
     364                $host = $_SERVER['SERVER_NAME']; 
     365                $from = "rafi@wireless-fr.org"; 
     366                $fromLine = "mail from: check@$host\n"; 
     367                $rcpt = "rcpt to: $email\n"; 
     368 
     369                /* Create a new Net_SMTP object. */ 
     370                if (! ($smtp = new Net_SMTP($srv))) { 
     371                        // echo("Unable to instantiate Net_SMTP object\n"); 
     372                        return false; 
     373                } 
     374                 
     375                /* Connect to the SMTP server. */ 
     376                if (PEAR::isError($e = $smtp->connect())) { 
     377                        // echo($e->getMessage() . "\n"); 
     378                        return false; 
     379                } 
     380 
     381                /* HELO to the SMTP server. */ 
     382                if (PEAR::isError($e = $smtp->helo($host))) { 
     383                        // echo($e->getMessage() . "\n"); 
     384                        return false; 
     385                } 
     386 
     387                /* Send the 'MAIL FROM:' SMTP command. */ 
     388                if (PEAR::isError($smtp->mailFrom($from))) { 
     389                        // echo("Unable to set sender to <$from>\n"); 
     390                        return false; 
     391                } 
     392                 
     393                /* Address the message to each of the recipients. */ 
     394                if (PEAR::isError($res = $smtp->rcptTo($email))) { 
     395                        // echo("Unable to add recipient <$email>: " . $res->getMessage() . "\n<br />Error ".implode(": ",$smtp->getResponse())); 
     396                        return false; 
     397                } 
     398 
     399                /* Disconnect from the SMTP server. */ 
     400                $smtp->disconnect(); 
     401                return true; 
     402        } 
     403 
     404 
     405        /** 
    346406         * Validates an email address 
    347407         * 
    348408         * This function will make sure an e-mail is RFC822 compliant 
    349          * and is not black listed. 
     409         * and is not black listed. Check the e-mail onto MX host. 
    350410         * 
    351411         * @param string $mail The email address to validate 
     
    372432                            $_retVal = true; 
    373433                        } 
     434 
     435                        // Check if email is valid on mx host 
     436 
     437                        // gets domain name 
     438                        list($username,$domain)=split('@',$email); 
     439                        // checks for if MX records in the DNS 
     440                        $mxhosts = array(); 
     441                        if(!getmxrr($domain, $mxhosts)) { 
     442                                // no mx records, ok to check domain 
     443                                $fp=@fsockopen($domain,25,$errno,$errstr,30); 
     444                                if (!$fp) { 
     445                                        $_retVal = false; 
     446                                } else { 
     447                                        fclose($fp); 
     448                                        $_retVal = testMail($host,$email); 
     449                                } 
     450                        } else { 
     451                                // mx records found 
     452                                foreach ($mxhosts as $host) { 
     453                                        // echo "MX host : ".$host."<br>\n"; 
     454                                        $fp=@fsockopen($host,25,$errno,$errstr,30); 
     455                                        if ($fp) { 
     456                                                fclose($fp); 
     457                                                $_retVal = Mail::testMail($host,$email); 
     458                                        } 
     459                                } 
     460                        } 
    374461                } 
    375462 
    376463                return $_retVal; 
    377464        } 
    378  
    379465} 
     466 
    380467 
    381468/*