Welcome Guest, Not a member yet? Register   Sign In
The best way of verifying an email
#7

[eluser]Leggy[/eluser]
@stanleyxu - Yes, true but for a general use thing like a comment system sending the email would just get annoying

@Jemgames - I did see a function where is gets a response from the server to weather the email is valid and it could tell when i gave it an invalid email e.g. [email protected]

@Sean Murphy - I have seen that too, from what i see it's just a bigger and more complicated regex thing to see if the email is the right format, not its validity. His regex is probably better and more in depth then the one i used.

Here is both of the function's together: (I have been having a problem with ip's though e.g. I tested with my friends server's ip and it doesn't work (either fsockopen or checkdnsrr))

Code:
function check_email( $email, $rec_type = 'MX' )
{
    // Check that there is one @ symbol, and that the lengths are right
    if( !ereg( '^[^@]{1,64}@[^@]{1,255}$', $email ) ) return;
    
    // Split it into sections to make life easier
    list( $user, $domain ) = @split( '@', $email );
    
    $local_array = explode( '.', $user );
    
    // Check the beggining of the email (before the @) to see if it is valid
    for( $i = 0; $i < sizeof( $local_array ); $i++ )
    {
        if( !ereg( '^(([A-Za-z0-9!#$%&\'*+/=?^_`{|}~-][A-Za-z0-9!#$%&\'*+/=?^_`{|}~\.-]{0,63})|("[^(\\|\")]{0,62}"))$', $local_array[$i] ) ) return;
    }
    
    // Check if domain is IP. If not, it should be valid domain name
    if( !ereg( '^\[?[0-9\.]+\]?$', $domain ) )
    {
        $domain_array = explode( '.', $domain );
        
        // Check if the domain contains domain.*
        if( sizeof( $domain_array ) < 2 ) return;
        
        for( $i = 0; $i < sizeof( $domain_array ); $i++ )
        {
            if( !ereg( '^(([A-Za-z0-9][A-Za-z0-9-]{0,61}[A-Za-z0-9])|([A-Za-z0-9]+))$', $domain_array[$i] ) ) return;
        }
    }
    
    // Check if they included a rec type to check the server
    if( $rec_type == ( '' or null or false ) ) return true;
    else
    {
        // Check if the server is a Windows server
        if( @stristr( PHP_OS, 'Win' ) and PHP_OS != 'Darwin' )
        {
            // Check the domain's socket (25)
            if( @fsockopen( $domain, 25, $errno, $errstr, 30 ) ) return true;
            else return;
        }
        else
        {
            // Check the DNS record
            if( @checkdnsrr( $domain, $rec_type ) == true ) return true;
            else return;
        }
    }
}


Messages In This Thread
The best way of verifying an email - by El Forum - 04-19-2008, 06:00 AM
The best way of verifying an email - by El Forum - 04-19-2008, 09:37 AM
The best way of verifying an email - by El Forum - 04-19-2008, 12:44 PM
The best way of verifying an email - by El Forum - 04-19-2008, 05:24 PM
The best way of verifying an email - by El Forum - 04-20-2008, 03:30 AM
The best way of verifying an email - by El Forum - 04-21-2008, 10:37 AM
The best way of verifying an email - by El Forum - 04-21-2008, 12:20 PM
The best way of verifying an email - by El Forum - 04-21-2008, 03:51 PM
The best way of verifying an email - by El Forum - 04-22-2008, 11:20 AM



Theme © iAndrew 2016 - Forum software by © MyBB