the system stopped working after changing eregi to preg_match

38 Views Asked by At

On my website i have a contact us form which used to work fine until i upgraded to php 7. Now when i fill the form it returns as invalid email and the logs doesn't show any error.

Earlier it was showing error as

PHP Fatal error:  Uncaught Error: Call to undefined function eregi() in /app/index.php:27

This is line 27:

 if (!empty($email) && !preg_match("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email)){
        $err[] = "Invalid email<br>";
    }

So i changed eregi to preg_match but now it just doesn't work.

<?php
$err=array();

if(count($_POST) > 0)
{

    $name = isset($_REQUEST["name"]) ? trim($_REQUEST["name"]) : "";
    $address = isset($_REQUEST["subject"]) ? trim($_REQUEST["subject"]) : "";
    $country = isset($_REQUEST["country"]) ? trim($_REQUEST["country"]) : "";
    $email = isset($_REQUEST["email"]) ? trim($_REQUEST["email"]) : "";
    $contact_no = isset($_REQUEST["contact_no"]) ? trim($_REQUEST["contact_no"]) : "";
    $budget = isset($_REQUEST["budget"]) ? trim($_REQUEST["budget"]) : "";
    $com_name = isset($_REQUEST["com_name"]) ? trim($_REQUEST["com_name"]) : "";
    $message_text = isset($_REQUEST["message_text"]) ? trim(addslashes($_REQUEST["message_text"])) : "";
    $message_text=htmlentities($message_text,ENT_QUOTES);


    $ipaddress = $_SERVER['REMOTE_ADDR'];
    $date = date("F j, Y, g:i a"); 


    if(empty($name)) $err[]="You must enter your name,";
    if(empty($email)) $err[]="proper email address,";

    if (!empty($email) && !preg_match("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email)){
        $err[] = "Invalid email<br>";
    }
    if(empty($contact_no)) $err[]="proper contact no";

    if(!empty($contact_no) && !(is_numeric($contact_no)) )
    $err[]="Contact No must be in Number<br>";
0

There are 0 best solutions below