Implementing Form Script that Works with php 7

I recently upgraded hosting to php 7.0 since some of my WordPress sites were recommending the upgrade. The WordPress sites were fine, but one of my two last remaining HTML sites was using the Huggins Email Form php script, which isn’t compatible with php 7.0, and so the form started getting server 500 errors.

I looked up a resource I had used for a form for another HTML site, which was the ReusableContact Form Using Bootstrap And PHP.

Just download the zip file, and extract to the root directory for the site.

To test it, see the steps listed on the page where you got the zip file from.

To completely integrate it, I followed these steps:

  • Edit src/formhandler.php to change the email Subject and From.
  • Add any form field validations to handler.php.
  • If you’re using recaptcha, put the site key in the form (you’ll see the example in the formpage.html file), and put the secret key in handler.php.
  • Also, put the destination email address in handler.php.
  • Make sure you refer to the example formpage.html for including the link rels and script statements in the header and the recaptcha script in the body.

The next challenge was implementing a second form for that site. Fortunately the forms were on separate pages, so I didn’t need to use different form ids. I was able to use a generic Subject for both form emails, so no changes needed there. The second form worked fine. I suppose if I needed separate Subjects, separate recipients and separate field validation for each of the forms, then I’d need to figure out how to modify handler.php and formhandler.php. At some point, though, both of the remaining HTML sites will be converted to WordPress and I won’t need form scripts anymore!

 

Error trying to send your message with Contact Form 7 and reCAPTCHA v3

I’m using Contact Form 7 v5.1.1 on my WordPress sites along with reCAPTCHA v3, but when I test a contact form, I get the error: “There was an error trying to send your message. Please try again later.”

The error is outlined with an orange border, which means it’s a spam problem.

After going round and round with Post SMTP plugin, MailGun, and SendGrid, I finally find some information in this post about the Advanced noCAPTCHA Invisible CAPTCHA plugin. It’s an alternative that worked for me. Some users opted to revert back to reCAPTCHA v2 and/or older versions of Contact Form 7.

Install the Advanced noCAPTCHA Invisible CAPTCHA plugin. Remove any integration setup you have for Contact Form 7 with reCAPTCHA. Go to google.recaptcha.com and get your v3 keys and enter those in the settings of Advanced noCAPTCHA Invisible CAPTCHA.

My forms started working immediately. I no longer needed the Post SMTP plugin or SendGrid.