PHP Classes : eMail Validator

Σε αυτή την περιοχή μπορείτε να βρείτε ή να αναζητήσετε πληροφορίες σχετικές με την PHP

Συντονιστές: WebDev Moderators, Super-Moderators, PHP Moderators

Απάντηση
Άβαταρ μέλους
tsiger
Honorary Member
Δημοσιεύσεις: 1431
Εγγραφή: 11 Νοέμ 2002 13:40
Τοποθεσία: Thessaloniki Observation Center
Επικοινωνία:

PHP Classes : eMail Validator

Δημοσίευση από tsiger » 17 Οκτ 2003 15:31

o kwdikas tou class email.php

Κώδικας: Επιλογή όλων

<?php
class myEmailValidator &#123;

    var $myEmail;

	function check_it&#40;&#41;
		&#123;     
         // deite to $this->email. Se alles glwsses tha legame myEmailValidator.email
		 // 
		 if&#40;eregi&#40;"^&#91;^@ &#93;+@&#91;^@ &#93;+\.&#91;^@ \.&#93;+$", $this->myEmail&#41;&#41; 
            return &#40;true&#41;; 
         else 
            return &#40;false&#41;; 
    	&#125; 
		&#125;
?>
kai o kwdikas tis selidas mas

Κώδικας: Επιλογή όλων

<p>Δωστε σωστες και λαθος διευθυνσεις email.</p>
<form name="form1" method="post" action="testmail.php">
  <input type="text" name="myemail">
  <input type="submit" name="Submit" value="Submit">
</form>
<?php
if &#40;isset&#40;$_POST&#91;'myemail'&#93;&#41;&#41; 
	&#123;
	
	include &#40;"email.php"&#41;;
	$myClass = new myEmailValidator;
	
	$myClass->myEmail = $_POST&#91;'myemail'&#93;;
	$check = $myClass->check_it&#40;$_POST&#91;'myemail'&#93;&#41;;
	
	if&#40;$check&#41;
					&#123;
					echo "<strong>CORRECT!</strong>";
					&#125;
	else
					&#123;
					echo "<strong>WRONG!</strong>";
					&#125;

	&#125;
?>

Άβαταρ μέλους
tsiger
Honorary Member
Δημοσιεύσεις: 1431
Εγγραφή: 11 Νοέμ 2002 13:40
Τοποθεσία: Thessaloniki Observation Center
Επικοινωνία:

PHP Classes : eMail Validator

Δημοσίευση από tsiger » 17 Οκτ 2003 15:33


AlexanderTheGr
Δημοσιεύσεις: 153
Εγγραφή: 11 Ιούλ 2003 04:22
Επικοινωνία:

PHP Classes : eMail Validator

Δημοσίευση από AlexanderTheGr » 20 Οκτ 2003 18:18

Tha elega den einai apolyta sosto\

as poume dino tin parakata email diythinsi
qqw#$WE@sd##3.#2%
kai omos kai basi sto script ayto to email bgainei egkyro alla apokleite na deis pote ena tetoio email.

Sto www.zend.com iparxei mia pio polyploki synarthsi kai kanei mia pio sosti douleia (mia mikri metropi ekana mono)

Κώδικας: Επιλογή όλων

function MailVal&#40;$Addr, $Level, $Timeout = 15000&#41; &#123;

//  Valid Top-Level Domains
    $gTLDs = "com&#58;net&#58;org&#58;edu&#58;gov&#58;mil&#58;int&#58;arpa&#58;";
    $CCs   = "ad&#58;ae&#58;af&#58;ag&#58;ai&#58;al&#58;am&#58;an&#58;ao&#58;aq&#58;ar&#58;as&#58;at&#58;au&#58;aw&#58;az&#58;ba&#58;bb&#58;bd&#58;be&#58;bf&#58;".
             "bg&#58;bh&#58;bi&#58;bj&#58;bm&#58;bn&#58;bo&#58;br&#58;bs&#58;bt&#58;bv&#58;bw&#58;by&#58;bz&#58;ca&#58;cc&#58;cf&#58;cd&#58;cg&#58;ch&#58;ci&#58;".
             "ck&#58;cl&#58;cm&#58;cn&#58;co&#58;cr&#58;cs&#58;cu&#58;cv&#58;cx&#58;cy&#58;cz&#58;de&#58;dj&#58;dk&#58;dm&#58;do&#58;dz&#58;ec&#58;ee&#58;eg&#58;".
             "eh&#58;er&#58;es&#58;et&#58;fi&#58;fj&#58;fk&#58;fm&#58;fo&#58;fr&#58;fx&#58;ga&#58;gb&#58;gd&#58;ge&#58;gf&#58;gh&#58;gi&#58;gl&#58;gm&#58;gn&#58;".
             "gp&#58;gq&#58;gr&#58;gs&#58;gt&#58;gu&#58;gw&#58;gy&#58;hk&#58;hm&#58;hn&#58;hr&#58;ht&#58;hu&#58;id&#58;ie&#58;il&#58;in&#58;io&#58;iq&#58;ir&#58;".
             "is&#58;it&#58;jm&#58;jo&#58;jp&#58;ke&#58;kg&#58;kh&#58;ki&#58;km&#58;kn&#58;kp&#58;kr&#58;kw&#58;ky&#58;kz&#58;la&#58;lb&#58;lc&#58;li&#58;lk&#58;".
             "lr&#58;ls&#58;lt&#58;lu&#58;lv&#58;ly&#58;ma&#58;mc&#58;md&#58;mg&#58;mh&#58;mk&#58;ml&#58;mm&#58;mn&#58;mo&#58;mp&#58;mq&#58;mr&#58;ms&#58;mt&#58;".
             "mu&#58;mv&#58;mw&#58;mx&#58;my&#58;mz&#58;na&#58;nc&#58;ne&#58;nf&#58;ng&#58;ni&#58;nl&#58;no&#58;np&#58;nr&#58;nt&#58;nu&#58;nz&#58;om&#58;pa&#58;".
             "pe&#58;pf&#58;pg&#58;ph&#58;pk&#58;pl&#58;pm&#58;pn&#58;pr&#58;pt&#58;pw&#58;py&#58;qa&#58;re&#58;ro&#58;ru&#58;rw&#58;sa&#58;sb&#58;sc&#58;sd&#58;".
             "se&#58;sg&#58;sh&#58;si&#58;sj&#58;sk&#58;sl&#58;sm&#58;sn&#58;so&#58;sr&#58;st&#58;su&#58;sv&#58;sy&#58;sz&#58;tc&#58;td&#58;tf&#58;tg&#58;th&#58;".
             "tj&#58;tk&#58;tm&#58;tn&#58;to&#58;tp&#58;tr&#58;tt&#58;tv&#58;tw&#58;tz&#58;ua&#58;ug&#58;uk&#58;um&#58;us&#58;uy&#58;uz&#58;va&#58;vc&#58;ve&#58;".
             "vg&#58;vi&#58;vn&#58;vu&#58;wf&#58;ws&#58;ye&#58;yt&#58;yu&#58;za&#58;zm&#58;zr&#58;zw&#58;";

//  The countries can have their own 'TLDs', e.g. mydomain.com.au
    $cTLDs = "com&#58;net&#58;org&#58;edu&#58;gov&#58;mil&#58;co&#58;ne&#58;or&#58;ed&#58;go&#58;mi&#58;";
    $fail = 0;

//  Shift the address to lowercase to simplify checking
    $Addr = strtolower&#40;$Addr&#41;;

// Check for invalid chars
    if &#40;!eregi&#40;"^&#91;0-9a-z&#93;&#40;&#91;-_.&#93;?&#91;0-9a-z&#93;&#41;*@&#91;0-9a-z&#93;&#40;&#91;-.&#93;?&#91;0-9a-z&#93;&#41;*\\.&#91;a-z&#93;&#123;2,4&#125;$", $Addr&#41; OR &#40;strrpos&#40;$Addr,' '&#41; > 0&#41;&#41; &#123;
      $fail = 1;
    &#125;
//  Split the Address into user and domain parts
    $UD = explode&#40;"@", $Addr&#41;;
    if &#40;sizeof&#40;$UD&#41; != 2 || !$UD&#91;0&#93;&#41; &#123;
      $fail = 1;
    &#125;
//  Split the domain part into its Levels
    $Levels = explode&#40;".", $UD&#91;1&#93;&#41;;
    $sLevels = sizeof&#40;$Levels&#41;;
    if &#40;$sLevels < 2&#41; &#123;
      $fail = 1;
    &#125;
//  Get the TLD, strip off trailing &#93; &#125; &#41; > and check the length
    $tld = $Levels&#91;$sLevels-1&#93;;
    $tld = ereg_replace&#40;"&#91;>&#41;&#125;&#93;$|&#93;$", "", $tld&#41;;
    if &#40;strlen&#40;$tld&#41; < 2 || strlen&#40;$tld&#41; > 3 && $tld != "arpa"&#41; &#123;
      $fail = 1;
    &#125;
    $Level--;

//  If the string after the last dot isn't in the generic TLDs or country codes, it's invalid.
    if &#40;$Level && !$fail&#41; &#123;
      $Level--;
      if &#40;!ereg&#40;$tld."&#58;", $gTLDs&#41; && !ereg&#40;$tld."&#58;", $CCs&#41;&#41; &#123;
        $fail = 2;
      &#125;
    &#125;

//  If it's a country code, check for a country TLD; add on the domain name.
    if &#40;$Level && !$fail&#41; &#123;
      $cd = $sLevels - 2;
      $domain = $Levels&#91;$cd&#93;.".".$tld;
      if &#40;ereg&#40;$Levels&#91;$cd&#93;."&#58;", $cTLDs&#41;&#41; &#123;
        $cd--;
        $domain = $Levels&#91;$cd&#93;.".".$domain;
      &#125;
    &#125;

//  See if there's an MX record for the domain
    if &#40;$Level && !$fail&#41; &#123;
      $Level--;
      if &#40;!getmxrr&#40;$domain, $mxhosts, $weight&#41;&#41; &#123;
        $fail = 3;
      &#125;
    &#125;

//  Attempt to connect to port 25 on an MX host
    if &#40;$Level && !$fail&#41; &#123;
      $Level--;
      while &#40;!$sh && list&#40;$nul, $mxhost&#41; = each&#40;$mxhosts&#41;&#41; &#123;
        $sh = fsockopen&#40;$mxhost, 25&#41;;
      &#125;
      if &#40;!$sh&#41; &#123;
        $fail = 4;
      &#125;
    &#125;

//  See if anyone answers
    if &#40;$Level && !$fail&#41; &#123;
      $Level--;
      set_socket_blocking&#40;$sh, false&#41;;
      $out = "";
      $t = 0;
      while &#40;$t++ < $Timeout && !$out&#41; &#123;
        $out = fgets&#40;$sh, 256&#41;;
      &#125;
      if &#40;!ereg&#40;"^220", $out&#41;&#41; &#123;
        $fail = 5;
      &#125;
    &#125;

    if &#40;isset&#40;$sh&#41;&#41; fclose&#40;$sh&#41;;

    return $fail;
&#125; //MailVal

Άβαταρ μέλους
iNDEFiX
Honorary Member
Δημοσιεύσεις: 2569
Εγγραφή: 20 Δεκ 2002 00:48
Τοποθεσία: κλειστή λόγω έργων
Επικοινωνία:

PHP Classes : eMail Validator

Δημοσίευση από iNDEFiX » 20 Οκτ 2003 18:33

// Attempt to connect to port 25 on an MX host

ola ta lefta :wink: :wink:

Άβαταρ μέλους
Cha0s
SysAdmin
Δημοσιεύσεις: 10242
Εγγραφή: 28 Ιούλ 2001 03:00

PHP Classes : eMail Validator

Δημοσίευση από Cha0s » 20 Οκτ 2003 21:33

Nai nai!
Treli patenta ayto!

Sou elegxei an iparxei kai to account ston mail server pera apola ta ipoloipa ;)

Άβαταρ μέλους
Rapid-eraser
WebDev Moderator
Δημοσιεύσεις: 6851
Εγγραφή: 05 Απρ 2003 17:50
Τοποθεσία: Πειραιάς
Επικοινωνία:

PHP Classes : eMail Validator

Δημοσίευση από Rapid-eraser » 20 Οκτ 2003 21:36

pou tnv eidate tnv patevta re :P
to eixa ftiaksei kai egw priv arketo kairo
helo-script ama 8imaste kala
Cu, Rapid-eraser, Tα αγαθά copies κτώνται.
Love is like oxygen, You get too much you get too high
Not enough and you're gonna die, Love gets you high

Άβαταρ μέλους
Cha0s
SysAdmin
Δημοσιεύσεις: 10242
Εγγραφή: 28 Ιούλ 2001 03:00

PHP Classes : eMail Validator

Δημοσίευση από Cha0s » 20 Οκτ 2003 21:41

Nai nai to thimamai :)

Άβαταρ μέλους
tsiger
Honorary Member
Δημοσιεύσεις: 1431
Εγγραφή: 11 Νοέμ 2002 13:40
Τοποθεσία: Thessaloniki Observation Center
Επικοινωνία:

PHP Classes : eMail Validator

Δημοσίευση από tsiger » 21 Οκτ 2003 01:49

den eipa oti einai swsto eipa oti einai ena typiko paradeigma enos class opou to pattern den einai oti poio filosofimeno. vgalte kai kamia efarmogi sto emporio ama einai na elegxei email :hammer: :hammer:

Άβαταρ μέλους
cordis
Administrator, [F|H]ounder, [C|S]EO
Δημοσιεύσεις: 27616
Εγγραφή: 09 Οκτ 1999 03:00
Τοποθεσία: Greece
Επικοινωνία:

PHP Classes : eMail Validator

Δημοσίευση από cordis » 08 Ιούλ 2004 21:26

άλλη μια function για αυτόν τον σκοπό...

Κώδικας: Επιλογή όλων

<? 
/* ======================================================================= 
    
ifsnow's email valid check function SnowCheckMail Ver 0.1 
   
funtion SnowCheckMail &#40;$Email,$Debug=false&#41; 

$Email &#58; E-Mail address to check. 
$Debug &#58; Variable for debugging. 

* Can use everybody if use without changing the name of function. 

Reference &#58; O'REILLY - Internet Email Programming 

HOMEPAGE &#58; http&#58;//www.hellophp.com 

ifsnow is korean phper. Is sorry to be unskillful to English. *^^*;; 

========================================================================= */ 

function SnowCheckMail&#40;$Email,$Debug=false&#41; 
&#123; 
    global $HTTP_HOST; 
    $Return =array&#40;&#41;;   
    // Variable for return. 
    // $Return&#91;0&#93; &#58; &#91;true|false&#93; 
    // $Return&#91;1&#93; &#58; Processing result save. 

    if &#40;!eregi&#40;"^&#91;_a-z0-9-&#93;+&#40;\.&#91;_a-z0-9-&#93;+&#41;*@&#91;a-z0-9-&#93;+&#40;\.&#91;a-z0-9-&#93;+&#41;*&#40;\.&#91;a-z&#93;&#123;2,3&#125;&#41;$", $Email&#41;&#41; &#123; 
        $Return&#91;0&#93;=false; 
        $Return&#91;1&#93;="$&#123;Email&#125; is E-Mail form that is not right."; 
        if &#40;$Debug&#41; echo "Error &#58; &#123;$Email&#125; is E-Mail form that is not right.<br>";          
        return $Return; 
    &#125; 
    else if &#40;$Debug&#41; echo "Confirmation &#58; &#123;$Email&#125; is E-Mail form that is not right.<br>"; 

    // E-Mail @ by 2 by standard divide. if it is $Email this "lsm@ebeecomm.com".. 
    // $Username &#58; lsm 
    // $Domain &#58; ebeecomm.com 
    // list function reference &#58; http&#58;//www.php.net/manual/en/function.list.php 
    // split function reference &#58; http&#58;//www.php.net/manual/en/function.split.php 
    list &#40; $Username, $Domain &#41; = split &#40;"@",$Email&#41;; 

    // That MX&#40;mail exchanger&#41; record exists in domain check . 
    // checkdnsrr function reference &#58; http&#58;//www.php.net/manual/en/function.checkdnsrr.php 
    if &#40; checkdnsrr &#40; $Domain, "MX" &#41; &#41;  &#123; 
        if&#40;$Debug&#41; echo "Confirmation &#58; MX record about &#123;$Domain&#125; exists.<br>"; 
        // If MX record exists, save MX record address. 
        // getmxrr function reference &#58; http&#58;//www.php.net/manual/en/function.getmxrr.php 
        if &#40; getmxrr &#40;$Domain, $MXHost&#41;&#41;  &#123; 
      if&#40;$Debug&#41; &#123; 
                echo "Confirmation &#58; Is confirming address by MX LOOKUP.<br>"; 
              for &#40; $i = 0,$j = 1; $i < count &#40; $MXHost &#41;; $i++,$j++ &#41; &#123; 
            echo "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Result&#40;$j&#41; - $MXHost&#91;$i&#93;<BR>";   
        &#125; 
            &#125; 
        &#125; 
        // Getmxrr function does to store MX record address about $Domain in arrangement form to $MXHost. 
        // $ConnectAddress socket connection address. 
        $ConnectAddress = $MXHost&#91;0&#93;; 
    &#125; 
    else &#123; 
        // If there is no MX record simply @ to next time address socket connection do . 
        $ConnectAddress = $Domain;          
        if &#40;$Debug&#41; echo "Confirmation &#58; MX record about &#123;$Domain&#125; does not exist.<br>"; 
    &#125; 

    // fsockopen function reference &#58; http&#58;//www.php.net/manual/en/function.fsockopen.php 
    $Connect = fsockopen &#40; $ConnectAddress, 25 &#41;; 

    // Success in socket connection 
    if &#40;$Connect&#41;    
    &#123; 
        if &#40;$Debug&#41; echo "Connection succeeded to &#123;$ConnectAddress&#125; SMTP.<br>"; 
        // Judgment is that service is preparing though begin by 220 getting string after connection . 
        // fgets function reference &#58; http&#58;//www.php.net/manual/en/function.fgets.php 
        if &#40; ereg &#40; "^220", $Out = fgets &#40; $Connect, 1024 &#41; &#41; &#41; &#123; 
              
            // Inform client's reaching to server who connect. 
            fputs &#40; $Connect, "HELO $HTTP_HOST\r\n" &#41;; 
                if &#40;$Debug&#41; echo "Run &#58; HELO $HTTP_HOST<br>"; 
            $Out = fgets &#40; $Connect, 1024 &#41;; // Receive server's answering cord. 

            // Inform sender's address to server. 
            fputs &#40; $Connect, "MAIL FROM&#58; <&#123;$Email&#125;>\r\n" &#41;; 
                if &#40;$Debug&#41; echo "Run &#58; MAIL FROM&#58; &lt;&#123;$Email&#125;&gt;<br>"; 
            $From = fgets &#40; $Connect, 1024 &#41;; // Receive server's answering cord. 

            // Inform listener's address to server. 
            fputs &#40; $Connect, "RCPT TO&#58; <&#123;$Email&#125;>\r\n" &#41;; 
                if &#40;$Debug&#41; echo "Run &#58; RCPT TO&#58; &lt;&#123;$Email&#125;&gt;<br>"; 
            $To = fgets &#40; $Connect, 1024 &#41;; // Receive server's answering cord. 

            // Finish connection. 
            fputs &#40; $Connect, "QUIT\r\n"&#41;; 
                if &#40;$Debug&#41; echo "Run &#58; QUIT<br>"; 

            fclose&#40;$Connect&#41;; 

                // Server's answering cord about MAIL and TO command checks. 
                // Server about listener's address reacts to 550 codes if there does not exist   
                // checking that mailbox is in own E-Mail account. 
                if &#40; !ereg &#40; "^250", $From &#41; || !ereg &#40; "^250", $To &#41;&#41; &#123; 
                    $Return&#91;0&#93;=false; 
                    $Return&#91;1&#93;="$&#123;Email&#125; is address done not admit in E-Mail server."; 
                    if &#40;$Debug&#41; echo "&#123;$Email&#125; is address done not admit in E-Mail server.<br>"; 
                    return $Return; 
                &#125; 
        &#125; 
    &#125; 
    // Failure in socket connection 
    else &#123; 
        $Return&#91;0&#93;=false; 
        $Return&#91;1&#93;="Can not connect E-Mail server &#40;&#123;$ConnectAddress&#125;&#41;."; 
        if &#40;$Debug&#41; echo "Can not connect E-Mail server &#40;&#123;$ConnectAddress&#125;&#41;.<br>"; 
        return $Return; 
    &#125; 
    $Return&#91;0&#93;=true; 
    $Return&#91;1&#93;="&#123;$Email&#125; is E-Mail address that there is no any problem."; 
    return $Return; 
&#125; 
?> 
Δεν απαντάω σε προσωπικά μηνύματα με ερωτήσεις που καλύπτονται από τις ενότητες του forum. Για ο,τι άλλο είμαι εδώ για εσάς.
- follow me @twitter

panosru
WebDev Moderator
Δημοσιεύσεις: 1885
Εγγραφή: 13 Σεπ 2005 16:13
Τοποθεσία: Camp

PHP Classes : eMail Validator

Δημοσίευση από panosru » 19 Δεκ 2005 23:52

me bash to post tou AlexanderTheGr to opoio dokiazo tora parathrhsa pos mails opos yahoo mail hotmail msn ktl den leitourgoun bgazei pos den einai valid.

Απάντηση

Επιστροφή στο “PHP Προγραμματισμός”

Μέλη σε σύνδεση

Μέλη σε αυτήν τη Δ. Συζήτηση: Δεν υπάρχουν εγγεγραμμένα μέλη και 0 επισκέπτες