PHP - Verify that the email is gmail or other

-1

Using an array that will determine GMAIL, HOTMAIL, OUTLOOK, how can I tell if what the user has submitted is some?

Easy ...

Using an Array, you can check any types of official E_mails you want.

$email = '[email protected]';
$array_emails = array('gmail.com', 'hotmail.com', 'outlook.com');

$separate_email = explode('@', $email);
$email_name = $separate_email[0];
$email_domain = $separate_email[1];

if (!in_array($email_domain, $array_emails)) {

    echo "Este e-mail não é official.";

}

* Thanks to those who helped

Visit and give opinions about the Project. www.superfacil.pt

    
asked by anonymous 28.04.2018 / 13:28

2 answers

0

You can do it this way:

$email = '[email protected]';
$separa_array = explode('@', $email);
$inicio = $separa_array[0];
$fim = $separa_array[1];
echo "$inicio [@$fim]";

With the function explode you separate the string according to '@' and then merge according to your wish.

    
28.04.2018 / 13:37
0

It has a simpler way of doing it at a glance as I did

$email = '[email protected]';

if(strpos($email, '@gmail')){
    echo 'Gmail';
}else if(strpos($email, '@hotmail')) {
    echo 'Hotmail';
}else if(strpos($email, '@outlook')) {
    echo 'Outlook';
}else {
    echo 'Outros';
}
    
28.04.2018 / 14:09