Simple Validated Mail Form with HTML, PHP & Javascript

Alex Deeley
Apr 23, 2018 · 1 min read

Have you ever wanted to create a PHP mail form on your website? Even if you have no idea what you’re doing, this guide will help you get your form up and running in no time.

You’re going to need to work from 4 files:

  1. HTML file, which holds the actual form.
  2. PHP file, which will compile the form contents, validate and actually send the email.
  3. Javascript file, which will help validate the form fields and keep spam bots from flooding your inbox.
  4. Another HTML file, which will serve as a thank you page when the form submission is completed successfully.

We are going to be creating a simple form, featuring a First Name, Last Name, Email, Phone and Message inputs. We will also be directing the post of the form to our PHP file, sendmail.php, which will take care of the rest of the processing.

Next, we will be creating the PHP sendmail.php script.

The javascript form validator is rather simple, but effective.

Lastly, the thank you page for successful submission of the form.

That’s it! Feel free to modify this script as you see necessary.

astro

Modern development for forward thinkers.

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store