CodeIgniter Forums
email scrub - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forum-21.html)
+--- Thread: email scrub (/thread-7585.html)



email scrub - El Forum - 04-15-2008

[eluser]infusionmedia[/eluser]
I am currently working on a list management application. I need to be able to segregate email data based on tld, non-tld, .gov, .edu, @spam... I guess my question is, has anybody else worked on something similar that can share some info and/or share some code that I can implement into this application? Thanks...


email scrub - El Forum - 04-15-2008

[eluser]Leggy[/eluser]
You could do a regex to see if it a valid email e.g. (taken from the CI validator class)

Code:
preg_match("/^([a-z0-9\+_\-]+)(\.[a-z0-9\+_\-]+)*@([a-z0-9\-]+\.)+[a-z]{2,6}$/ix", $str)

There are better ways, i used to have a very good one but i have lost it since.

EDIT: I think i found it again, i made a few alterations to the code but here is the function:

Code:
function check_email( $email, $rec_type = 'MX' )
{
    // Check if the domain is the correct format e.g. [email protected]
    if( [email protected]_match( '/^([a-z0-9\+_\-]+)(\.[a-z0-9\+_\-]+)*@([a-z0-9\-]+\.)+[a-z]{2,6}$/ix', $email ) ) return;
    else
    {
        // Seperate the username and domain to for checking
        list( $username, $domain ) = split( '@', $email );
        
        // Check if the domain has a mail handler
        if( @checkdnsrr( $domain, $rec_type ) ) return true;
        else return;
    }
}



email scrub - El Forum - 04-15-2008

[eluser]infusionmedia[/eluser]
i appreciate the response. thanks.


email scrub - El Forum - 04-15-2008

[eluser]infusionmedia[/eluser]
dude. you are the man, that was very helpful.