Often in forms we take user email-id. However those email ids may not be a valid email id. Here is a simple way to validate the email-id before proceeding
Code:
function VALIDATE_EMAIL ( $email ) {
global $mxrecords;
if ( $email == '' ) return (-1);
list ( $username , $domaintld ) = split ( "@" , $email , 2 ) ;
$domaintld = strtolower ( $domaintld ) ;
if ( !getmxrr ( $domaintld , $mxrecords ) || !preg_match ( "(^[-\w\.]+$)" , $username ) ) return 0;
return 1;
}
Now, use this function to validate email id. just call VALIDATE_EMAIL ('emailid@domain.com') to check it is valid or invalid. Function will return -1 if no email id is given, 0 if invalid email id, 1 if it is valid.