-4

I have a contact form for my website is say:

Deprecated: Function eregi() is deprecated in /home/sessionj/domains/XXX.com/public_html/test/contactform.php on line 12

But the email was send to me, and the "CAUTION" is annoying.

Any bad code?

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<link rel="stylesheet" href="css/style.css" />
<title> Contact Form</title>
</head>
<body>
<?php
function is_valid_email($vemail) {
$result = TRUE;
     if(!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$",    $vemail)) {
$result = FALSE;
}
   return $result;
  }
//if "email" is filled out, send email
if (isset($_REQUEST['email']) && $_REQUEST['email'] != '' && $_REQUEST['name'] != '' && $_REQUEST['message'] != ''
&& is_valid_email($_REQUEST['email']))
{
//send email
$email = $_REQUEST['email'] ;
$name = $_REQUEST['name'] ;
$subject = $_REQUEST['subject'] ;
$message = $_REQUEST['message'] ;
$recievers_email = "info@xxx.com";

mail($recievers_email, "$subject",
$message, "From:" . $email);
echo "<p class='form_success'>Message sent! Thank you!</p><p class='form_success_sub'>We'll reply as soon as possible, SJ.</p>";
}
else
{
 //if "email" is not filled out, display the form
if(!is_valid_email($_REQUEST['email']))
{
    echo "<p class='form_error'>Please, insert an email address.</p>";                         
 }
else if($_REQUEST['name'] == '')
{
    echo "<p class='form_error'>Please, write your name.</p>";
}
else if($_REQUEST['message'] == '')
{
    echo "<p class='form_error'>Please, leave your message.</p>";
}
}
?>
</body>
</html>
gmsantos
  • 1,412
  • 22
  • 30
  • And simpler even for just validating the email address: [PHP email validation](http://stackoverflow.com/q/3613589) – mario Aug 06 '14 at 10:50

1 Answers1

0

Deprecation is a status applied to a computer software feature, characteristic, or practice indicating it should be avoided, typically because of it being superseded.

Take a look at the PHP manual for eregi. As you can see, it has the following warning:

This function has been DEPRECATED as of PHP 5.3.0. Relying on this feature is highly discouraged.

Further down the page there is some advice on what to use instead:

eregi() is deprecated as of PHP 5.3.0. preg_match() with the i (PCRE_CASELESS) modifier is the suggested alternative.

So you can use the preg_match function instead.

Zaraileto
  • 3
  • 1
  • Would be nice to explain the differences between `ereg` and `preg` (like inclusion of delimiters and the case insensitive flag). – gmsantos Aug 06 '14 at 10:55