phpDocumentor VFront
Function-Libraries
[ class tree: VFront ] [ index: VFront ] [ all elements ]

Source for file func.validmail.php

Documentation is available at func.validmail.php

  1. <?php
  2. /**
  3. * Libreria di funzioni per la validazione delle email.
  4. @package VFront
  5. @subpackage Function-Libraries
  6. @author Mario Marcello Verona <marcelloverona@gmail.com>
  7. @copyright 2007 Mario Marcello Verona
  8. @version 0.90
  9. @license http://www.gnu.org/licenses/gpl.html GNU Public License
  10. */
  11.  
  12.  
  13.  
  14. function SnowCheckMail($Email,$Debug=false
  15.     global $HTTP_HOST
  16.     $Return =array();  
  17.     // Variable for return. 
  18.     // $Return[0] : [true|false] 
  19.     // $Return[1] : Processing result save. 
  20.  
  21.     if (!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$"$Email)) 
  22.         $Return[0]=false
  23.         $Return[1]="${Email} is E-Mail form that is not right."
  24.         if ($Debugecho "Error : {$Email} is E-Mail form that is not right.<br>";         
  25.         return $Return
  26.     
  27.     else if ($Debugecho "Confirmation : {$Email} is E-Mail form that is not right.<br>"
  28.  
  29.     // E-Mail @ by 2 by standard divide. if it is $Email this "lsm@ebeecomm.com".. 
  30.     // $Username : lsm 
  31.     // $Domain : ebeecomm.com 
  32.     // list function reference : http://www.php.net/manual/en/function.list.php 
  33.     // split function reference : http://www.php.net/manual/en/function.split.php 
  34.     list $Username$Domain split ("@",$Email)
  35.  
  36.     // That MX(mail exchanger) record exists in domain check . 
  37.     // checkdnsrr function reference : http://www.php.net/manual/en/function.checkdnsrr.php 
  38.     if checkdnsrr $Domain"MX" ) )  
  39.         if($Debugecho "Confirmation : MX record about {$Domain} exists.<br>"
  40.         // If MX record exists, save MX record address. 
  41.         // getmxrr function reference : http://www.php.net/manual/en/function.getmxrr.php 
  42.         if getmxrr ($Domain$MXHost))  
  43.       if($Debug
  44.                 echo "Confirmation : Is confirming address by MX LOOKUP.<br>"
  45.               for $i 0,$j 1$i count $MXHost )$i++,$j++ 
  46.             echo "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Result($j) - $MXHost[$i]<BR>";  
  47.         
  48.             
  49.         
  50.         // Getmxrr function does to store MX record address about $Domain in arrangement form to $MXHost. 
  51.         // $ConnectAddress socket connection address. 
  52.         $ConnectAddress $MXHost[0]
  53.     
  54.     else 
  55.         // If there is no MX record simply @ to next time address socket connection do . 
  56.         $ConnectAddress $Domain;         
  57.         if ($Debugecho "Confirmation : MX record about {$Domain} does not exist.<br>"
  58.     
  59.  
  60.     // fsockopen function reference : http://www.php.net/manual/en/function.fsockopen.php 
  61.     $Connect fsockopen $ConnectAddress25 )
  62.  
  63.     // Success in socket connection 
  64.     if ($Connect)   
  65.     
  66.         if ($Debugecho "Connection succeeded to {$ConnectAddress} SMTP.<br>"
  67.         // Judgment is that service is preparing though begin by 220 getting string after connection . 
  68.         // fgets function reference : http://www.php.net/manual/en/function.fgets.php 
  69.         if ereg "^220"$Out fgets $Connect1024 ) ) ) 
  70.              
  71.             // Inform client's reaching to server who connect. 
  72.             fputs $Connect"HELO $HTTP_HOST\r\n)
  73.                 if ($Debugecho "Run : HELO $HTTP_HOST<br>"
  74.             $Out fgets $Connect1024 )// Receive server's answering cord. 
  75.  
  76.             // Inform sender's address to server. 
  77.             fputs $Connect"MAIL FROM: <{$Email}>\r\n)
  78.                 if ($Debugecho "Run : MAIL FROM: &lt;{$Email}&gt;<br>"
  79.             $From fgets $Connect1024 )// Receive server's answering cord. 
  80.  
  81.             // Inform listener's address to server. 
  82.             fputs $Connect"RCPT TO: <{$Email}>\r\n)
  83.                 if ($Debugecho "Run : RCPT TO: &lt;{$Email}&gt;<br>"
  84.             $To fgets $Connect1024 )// Receive server's answering cord. 
  85.  
  86.             // Finish connection. 
  87.             fputs $Connect"QUIT\r\n")
  88.                 if ($Debugecho "Run : QUIT<br>"
  89.  
  90.             fclose($Connect)
  91.  
  92.                 // Server's answering cord about MAIL and TO command checks. 
  93.                 // Server about listener's address reacts to 550 codes if there does not exist  
  94.                 // checking that mailbox is in own E-Mail account. 
  95.                 if !ereg "^250"$From || !ereg "^250"$To )) 
  96.                     $Return[0]=false
  97.                     $Return[1]="${Email} is address done not admit in E-Mail server."
  98.                     if ($Debugecho "{$Email} is address done not admit in E-Mail server.<br>"
  99.                     return $Return
  100.                 
  101.         
  102.     
  103.     // Failure in socket connection 
  104.     else 
  105.         $Return[0]=false
  106.         $Return[1]="Can not connect E-Mail server ({$ConnectAddress})."
  107.         if ($Debugecho "Can not connect E-Mail server ({$ConnectAddress}).<br>"
  108.         return $Return
  109.     
  110.     $Return[0]=true
  111.     $Return[1]="{$Email} is E-Mail address that there is no any problem."
  112.     return $Return
  113. }
  114.  
  115.  
  116. /**
  117.  * Controllo di validità formale e|o sostanziale di una email
  118.  * Mediante il $controllo_destinatario=true è possibile capire se la mail esiste
  119.  * In caso contrario la validazione è solo formale
  120.  *
  121.  * @param string $email 
  122.  * @param bool $controllo_destinatario 
  123.  * @return bool 
  124.  */
  125. function valid_mail($email,$controllo_destinatario=false){
  126.  
  127.     if($controllo_destinatario){
  128.         
  129.         $check=SnowCheckMail($email);
  130.         return $check[0];
  131.     }
  132.     else{
  133.         return (eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$"$email)) true:false;
  134.     }
  135.  
  136. }
  137.  
  138.  
  139. /**
  140.  * Funzione che estrae le email da un testo
  141.  *
  142.  * @param string $testo 
  143.  * @return array 
  144.  */
  145. function estrai_mail_valide($testo){
  146.     
  147.     
  148.     preg_match_all('"[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})"iu',$testo,$mails);
  149.     
  150.     return (array) $mails[0];
  151. }
  152.  
  153. ?>

Documentation generated on Sat, 22 Sep 2007 11:50:27 +0200 by phpDocumentor 1.4.0a2