Contact-form-handler.php has stopped working on my sites – PHP – SitePoint Forums


I maintain a few websites (mine and a non-profit) that have a contact/donation form. This form was obtained many years ago in free form. It stopped working and I’m trying to fix it but I don’t know PHP. Can I copy the script here so someone can look at it and help me fix it?

Of course, you can copy the code here. When you post code on the forum, you must format it. To do this, you can either select all the code and click on the or type 3 backticks “` on a separate line both before and after the code block.

We will also need to know what error(s) you get when someone submits a form. If nothing is displayed in the browser, you should check the error logs. They should be available from your control panel.

It would also be useful to know what version of PHP your server uses.

Do you know what changed between when it worked and when it didn’t?
If it’s an old script, the host may have stopped providing an older version of PHP and the script is no longer compatible. Maybe that’s not it, just the first idea that came to mind.
But the error log is often the key to finding what’s wrong.

Here is the code for the donation form. I don’t know when it stopped working. My client contacted me recently to tell me that visitors to her site could not use the form. After filling out the form and hitting the submit button, it takes me to a page that says this page is not working. It is currently unable to process this request. His site is hosted on and uses PHP 8.1.

	Contact form handler

The eregi function was removed in PHP 7.
Use preg_match Instead of that. Although in this case you should use filter_var to validate an email address.
I assume the host was updated from PHP 5.X

if(!filter_var($email, FILTER_VALIDATE_EMAIL)){
   $errors .= "rn Error: Invalid email address";

I changed the (!eregi( as you suggested. I found a website that is a PHP sandbox and ran the code. Here are the results.

Warning: Undefined array key "name" in /home/user/scripts/code.php on line 10

Warning: Undefined array key "address" in /home/user/scripts/code.php on line 11

Warning: Undefined array key "city" in /home/user/scripts/code.php on line 12

Warning: Undefined array key "state" in /home/user/scripts/code.php on line 13

Warning: Undefined array key "zipcode" in /home/user/scripts/code.php on line 14

Warning: Undefined array key "email" in /home/user/scripts/code.php on line 15

Warning: Undefined array key "phone" in /home/user/scripts/code.php on line 16

Warning: Undefined array key "memory" in /home/user/scripts/code.php on line 17

Warning: Undefined array key "honor" in /home/user/scripts/code.php on line 18

Warning: Undefined array key "checkbox" in /home/user/scripts/code.php on line 19

	Contact form handler

Error: all fields are required
Error: Invalid email address

I guess it’s because there is no $_POST data from a form submission in your sandbox.
Really, all form processing should be in a condition like this:-

    // Process form data here!!

So it only runs when the form is submitted.
But I guess it won’t work in your sandbox, because no post data will cause error anymore, it just means nothing happens, because it doesn’t try anymore to process data that is not the.

I uploaded the PHP code to my test site and it works. At least I have no more errors. I asked my client to check her emails to make sure she had received a test one from me.

I changed the exact same code on my contact form and I’m still getting an error with mine. It says
Error: all fields are required
Error: invalid email address

The only difference between his code and mine is at the top

The form on my client’s site now takes me to the thank you page after filling out the form, but no email is sent with the form information. I changed the email address to mine to test it and checked my spam folder, but no email, so I’m not sure if that’s the cause. Can anyone please look at the code again and see what else might need updating?

The problem could be with your host and the PHP mail() function. You better use something like PHPMailer to send the email. Besides being more reliable, you can get diagnostics if needed.


Comments are closed.