1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

About Validating emails

Discussion in 'PHP' started by beven, Nov 22, 2013.

  1. #1
    hi
    how we can check emails are exists in reality using php.. I want to develop a software to sort out emails address....
    but facing some problems any one assist in this matter that what is the idea behind it
    SEMrush
     
    beven, Nov 22, 2013 IP
    SEMrush
  2. EricBruggema

    EricBruggema Well-Known Member

    Messages:
    1,730
    Likes Received:
    26
    Best Answers:
    13
    Trophy Points:
    125
    #2
    No, but you can check if the host exists... but if the <name>@domain.com exists? its hard...
     
    EricBruggema, Nov 22, 2013 IP
  3. PoPSiCLe

    PoPSiCLe Illustrious Member

    Messages:
    4,630
    Likes Received:
    724
    Best Answers:
    152
    Trophy Points:
    470
    #3
    It's completely possible, but normally you would check this by querying the email-address and look for a response. Since there are already companies that provide this sort of functionality, it's completely possible, but how, I don't know, since I've never bothered with actually checking if an email actually exists. With todays possibilities of one-time emails, random Gmail/Hotmail/Yahoo-accounts, etc. checking to see if an email is actually active when someone signs up or something similar, is kinda moot. Of course, washing email-lists is another issue alltogether, so there it might have some merit.
     
    PoPSiCLe, Nov 22, 2013 IP
  4. Lam3r

    Lam3r Active Member

    Messages:
    235
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    60
    #4
    Easiest way to just make sure that the email is actually in a valid format is to use filter_var:
    $email = $_GET['email'];
    if(filter_var($email, FILTER_VALIDATE_EMAIL)){
        return "Valid email!";
    }else{
        return "Not a valid email, sucka.";
    }
    PHP:
     
    Lam3r, Nov 25, 2013 IP
  5. deathshadow

    deathshadow Acclaimed Member

    Messages:
    9,040
    Likes Received:
    1,670
    Best Answers:
    236
    Trophy Points:
    515
    #5
    Checking the account actually exists is VERY hard -- as others have already said the best you can usually hope for is to make sure the format of the e-mail is correct, and that the domain in question has a valid A or MX record.

    This is the routine I use for checking mails. A user from another forums and I brainstormed on this one.

    function isValidEmail($address) {
    
        if (filter_var($address,FILTER_VALIDATE_EMAIL)==FALSE) return false;
    
        /* explode out local and domain */
        list($local,$domain)=explode('@',$address);
        $localLength=strlen($local);
        $domainLength=strlen($domain);
    
        return (
            /* check for proper lengths */
            ($localLength>0 && $localLength<65) &&
            ($domainLength>3 && $domainLength<256) &&
            (
                checkdnsrr($domain,'MX') ||
                checkdnsrr($domain,'A')
            )
        );
    
    }
    Code (markup):
    Checks that the address is properly formed, proper lengths (something filter_var fails to do), and makes sure the domain actually exists.
     
    deathshadow, Nov 26, 2013 IP
    NetStar likes this.
  6. beven

    beven Active Member

    Messages:
    483
    Likes Received:
    1
    Best Answers:
    1
    Trophy Points:
    63
    #6
    yes it help me but there i desire to check the all emails are active or not , However thanks for response
     
    beven, Nov 26, 2013 IP
  7. PoPSiCLe

    PoPSiCLe Illustrious Member

    Messages:
    4,630
    Likes Received:
    724
    Best Answers:
    152
    Trophy Points:
    470
    #7
    That will actually allow emails that are too long. Granted, the total length of an email address, or rather, the proper max length of an email-address, have been debated for years, but the concensus is that it's 254 characters total - hence, a total of 65 + @ + 256 will greatly exceed that. Have a look at http://tools.ietf.org/html/rfc5321.
    I suggest adding a check for total length as well.
    I think perhaps that the minimum domainLength could also be altered slightly - given that the minimum TLD is three characters (.XX) and that the minimum domain name length is 2, I would guess that checking for anything less than 5 would do (yes, I'm aware that ending an email-address in @.com for instance is legal, but not very much used...).
    Unfortunately, checking for replies from the mailserver often takes too long, and unfortunately, doesn't always contain the correct return codes :/
     
    PoPSiCLe, Nov 26, 2013 IP
  8. beven

    beven Active Member

    Messages:
    483
    Likes Received:
    1
    Best Answers:
    1
    Trophy Points:
    63
    #8
    k Thanks
     
    beven, Nov 26, 2013 IP
  9. deathshadow

    deathshadow Acclaimed Member

    Messages:
    9,040
    Likes Received:
    1,670
    Best Answers:
    236
    Trophy Points:
    515
    #9
    You're miss-reading 5321... and I quote:
    Local-part is everything before the @, Domain is everything AFTER. The reason it's 255 octets (bytes) is one extra octet is reserved as a stop byte or length limited byte so it fits in a 8 bit delimited string.

    A clearer explanation can be found in RFC 3696:
    http://tools.ietf.org/html/rfc3696#page-6

    ... and I quote:
    Also you misread my code -- the lengths checked for are 64 and 255, NOT 65 and 256, hence the < instead of <=

    320 is the total as specified, no clue where that idiotic and nonsensical 254 number came from apart from parrot quoting people who don't know enough about the specifications to be opening their mouths on the subject. Near as I can tell it's 100% fictional BS if one bothers reading RFC's 5321, 5322, 3696, 6531, etc, etc... Or should I say comprehending it, since there's a mile of difference between reading something and comprehending it.

    I suspect the misunderstanding is akin to the nonsense where people try to claim XHTML should be able to do <div /> because they fail to grasp what the specification means when it says an 'empty element' -- because <div></div> is NOT an empty element by the specification. EMPTY elements are ones that CANNOT contain content, not ones that do not...

    Admittedly, the legalese used in any of the specifications seems carefully crafted to make sure only lawyers and the people who wrote it have a chance in hell of grasping any of it.
     
    deathshadow, Nov 27, 2013 IP
  10. PoPSiCLe

    PoPSiCLe Illustrious Member

    Messages:
    4,630
    Likes Received:
    724
    Best Answers:
    152
    Trophy Points:
    470
    #10
    Take a look here, please: http://www.rfc-editor.org/errata_search.php?rfc=3696&eid=1690
    It's correct that the separate values is 64 and 255, but the TOTAL value cannot (or, should not, since not all mail-servers are created equal) exceed 254. However, I'm reading RFCs now, I haven't actually tested this. Maybe I should. That would however involve registering a domain-name which maxes out the length...

    The fun bit about RFCs is that there are so MANY of them - and they're all SLIGHTLY different, albeit describing the exact same issue or function. Fun times.
     
    PoPSiCLe, Nov 27, 2013 IP
  11. deathshadow

    deathshadow Acclaimed Member

    Messages:
    9,040
    Likes Received:
    1,670
    Best Answers:
    236
    Trophy Points:
    515
    #11
    2821 is obsolete, see the obsolete messages on 5321.

    There are a LOT of RFC, usually the number is a good indicator of which one to follow -- older it is, check for a newer one that obsolete's it.
     
    deathshadow, Nov 27, 2013 IP
  12. NetStar

    NetStar Notable Member

    Messages:
    2,331
    Likes Received:
    486
    Best Answers:
    21
    Trophy Points:
    215
    #12
    Neither one of you will admit to being wrong, because you are both nerds. And nerds are never wrong. With that said, not all email servers are created equal and not all follow the standard. As long as you are checking for an approximate max length that should be good enough to validate an email address.

    ThisIsA170CharacterDomainNameWhichIsLessLikelyToBeUsedByAnyone_IActuallyWouldFlagThisAsInvalidEvenThoughItsValidByRFCStandards_ICantBelieveYouGuysAreArguingAboutThis.com

    Setting a REAL WORLD character cap on an email domain name increases the quality of the validation. I can't see how checking to make sure a DOMAIN does not exceeds 254 characters is anything but counter productive when ATTEMPTING to validate the authenticity of an email address.
     
    NetStar, Nov 27, 2013 IP
  13. PoPSiCLe

    PoPSiCLe Illustrious Member

    Messages:
    4,630
    Likes Received:
    724
    Best Answers:
    152
    Trophy Points:
    470
    #13
    I have no problem admitting I'm wrong, it's just that this have been debated "forever". However, it's mostly a purely theoretical debate, as most hosts sets a limit on domain name length at 64ish characters.
     
    PoPSiCLe, Nov 28, 2013 IP
    NetStar likes this.
  14. tech-24x7

    tech-24x7 Member

    Messages:
    107
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    38
    #14
    first of all you just have to check the status of the emails,whether they are activate or in a valid form....
     
    tech-24x7, Dec 5, 2013 IP
  15. ByteCoder

    ByteCoder Active Member

    Messages:
    239
    Likes Received:
    2
    Best Answers:
    2
    Trophy Points:
    65
    #15
    beven - for your ORIGINAL question - how to check if an email is really active:
    I know only one way that all of us are familiar with - send an activation email :)
     
    ByteCoder, Dec 5, 2013 IP
    ryan_uk likes this.