Check valid domains in an eMail address
<p>I have the following function that checks whether an eMail is valid:</p>

<pre><code>function validate_email ($getemail, $type)
{
    $email = $getemail;
    if (filter_var($email, FILTER_VALIDATE_EMAIL)) {
        $chkdomain = explode("@", $email);
        $domain = $chkdomain[1];
        switch ($type) :
            case 1: //FOR USERS
                if ($domain == "oxfordmontessori.com" || $domain == "student.com" || $domain == "vendor.com")
                    return 'Not Valid';
                else
                    return TRUE;
        endswitch
        ;
    } else {
        return FALSE;
    }
}
</code></pre>

<p>I am calling fuction in this way.</p>

<pre><code>var_dump($email);
$response = validate_email($email, '1');
var_dump($response);
if ($response == FALSE) {
    $error = "Incorrect Email-Id";
} elseif ($response == 'Not Valid') {
    $error = "Email domain is not valid for user.";
}
var_dump($response);
</code></pre>

<p>The code has the following issues</p>

<ol>
<li><p>Function is that not much restrict with email validation like <code>sunrise@o.com</code> and 'sunrise@o.c' both are consider as valid email id's.</p></li>
<li><p>If function return TRUE than also I get "Email domain is not valid for user."</p></li>
</ol>

<p>One issue is still their that is on return of TRUE it gives me error <code>Email domain is not valid for user.</code></p>
