-3

The web hosting service provider upgraded to PHP 7.1 and it broke the contact form of the page. I've narrowed it down to this piece of code:

function check_email($mail)
{
    $email_host = explode("@", $mail);
    $email_host = $email_host['1'];
    $email_resolved = gethostbyname($email_host);
    if ($email_resolved != $email_host && @eregi("^[0-9a-z]([-_.~]?[0-9a-z])*@[0-9a-z]([-.]?[0-9a-z])*\\.[a-z]{2,4}$",$mail))
    $valid = 1; return $valid;
}

I've found that the eregi function is no longer supported in PHP 7.1 but I dont know how and with what i should replace it.

GrimmMaze
  • 5
  • 1
  • 2

1 Answers1

1

Have a look at the documentation of eregi function in php.net:

Warning

This function was DEPRECATED in PHP 5.3.0, and REMOVED in PHP 7.0.0.

Alternatives to this function include:

preg_match() (with the i (PCRE_CASELESS) modifier)

You should always have a look there when it comes do deprecated functions.

For validating email addresses you could also use filter_var now:

if (filter_var('test@example.com', FILTER_VALIDATE_EMAIL)) {
    echo "Email valid.";
}
digijay
  • 1,329
  • 4
  • 15
  • 25