1

I have a website with a contact form, when I submit the details I get an error message about deprecated eregi() on line. This is the block of code that seems to be having a problem. I don't know php, so could anyone give a hand?

if (email_is_valid($youremail) && !eregi("\r",$youremail) && !eregi("\n",$youremail) && $yourname != "" && $yourmessage != "" && substr(md5($user_answer),5,10) === $answer) {
              mail($to,$subject,$message,$headers);
              $yourname = '';
              $youremail = '';
              $yourmessage = '';
              echo '<p style="color: #200041; text-align: center;">'.$contact_submitted.'</p>';
            }
3
  • 3
    you can post your code in better format, put you code between two ` Commented Jul 8, 2015 at 9:05
  • 1
    As stated from php.net website: This function has been DEPRECATED as of PHP 5.3.0. Relying on this feature is highly discouraged. Commented Jul 8, 2015 at 9:07
  • eregi is very deprecated since the PHP 5.3.0. Use mb_eragi() instead Commented Jul 8, 2015 at 9:09

2 Answers 2

2

Eregi is deprecated, so remove it from your code:

if (email_is_valid($youremail)&& $yourname != "" && $yourmessage != "" && substr(md5($user_answer),5,10) === $answer) {  
     mail($to,$subject,$message,$headers);
     $yourname = ''; 
     $youremail = ''; 
     $yourmessage = ''; 
     echo ''.$contact_submitted.'

You can forget about it, because it only check for new line signs.
If you want to keep new line checking, replace eregi with the preg_match function (but read the manual about it).

Sign up to request clarification or add additional context in comments.

Comments

1

eregi() is deprecated. So you can use preg_match()

And your code will be

<?php
    if (email_is_valid($youremail) && $yourname != "" && $yourmessage != "" && substr(md5($user_answer),5,10) == '$answer')
    {
        mail($to,$subject,$message,$headers);
        $yourname = '';
        $youremail = '';
        $yourmessage = '';
        echo '<p style="color: #200041; text-align: center;">'.$contact_submitted.'</p>';
    }
    else
    {
        echo '<p style="color: red; text-align: center;">Error</p>';
    }

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.