How To Create an HTML Contact Form from Scratch [2022]

Having a contact structure on your site is similarly essential as significant as having a telephone in your office. In our current reality where comfort is the top dog, it permits your clients (and possible clients) to reach out to you whenever of day. Indeed, even the most essential contact structures offer an incredible method for catching leads, developing your email list, and interfacing with your crowd. There’s only one detour: HTML. Build high-quality HTML forms in minutes.

How To Create an HTML Contact Form from Scratch [2022]

HTML (Hypertext Markup Language) is the standard code used to make most of the sites and applications on the web. What’s more, similarly with any language, aside from the language of affection, it’s not something you can learn in one evening.

Fortunately, you can make an HTML contact structure without devoting your life to coding. Sorry don’t as well on the off chance that you don’t have the foggiest idea about your UTF-8 from your SRC – in this post, we’ll direct you through all that you want to be aware of to begin fabricating an HTML contact structure today.

Before we start, require one moment to consider the off chance that you genuinely need to make a structure utilizing HTML. Things are a lot less difficult when you utilize a structure-building device like Paperform – you’ll make a superior-looking and more-impressive contact structure in a small part of the time.

How To Create an HTML Contact Form from Scratch
How To Create an HTML Contact Form from Scratch

Five steps to creating an HTML contact form

  1. Choose an HTML editor.
  2. Make a file with a .html extension.
  3. Make a file with the .php extension.
  4. Generate the PHP code to capture form data.
  5. Create your HTML contact form.

1. Choose an HTML editor

How To Create an HTML Contact Form from Scratch
How To Create an HTML Contact Form from Scratch

To make HTML code, you want an HTML supervisor. It helps convert the code into anything you’re attempting to make – for this situation a contact structure.

Consider an HTML supervisor like a unique word processor explicitly for making things for pages. You utilize any word processor to make HTML code, however, devoted editors offer much more accommodation and usefulness.

There’s no lack of incredible HTML editors. A few famous choices include:

  • Notepad++
  • Codepen
  • Atom
  • CoffeeCup
  • Brackets
  • Kompozer
  • Sublime Text 3

Any of the above instruments will finish the work, yet there are many choices assuming you’re the sort that likes to search for the ideal arrangement. Most are free, so you can evaluate a couple and see which turns out best for you.

2. Make another document with the. HTML expansion

Then, you need to give your working framework the head’s up that you’re making another HTML record. Fortunately, this step is truly basic. You should make another record with your HTML proofreader and save it with the ‘.html’ expansion.

Name the document and follow it with .html. While you’re managing code it’s ideal to keep things clear, so we recommend naming the document ‘contact_form.html’ or something almost identical.

Whenever you’ve named it, type it into the text field. This reports to your desired proofreader to make HTML code. It’s similar to when you play Charades and signal the class you’re doing before you begin acting it out.

Your manager will consequently create the accompanying code for you. It’ll be similar whether you’re making a basic contact structure or a whole HTML site.

<!DOCTYPE html>

3. Create a new file with the .PHP extension

Presently you need to make another record. However this time you need to save it with the ‘.php’ augmentation. This one takes care of the structure accommodation cycle and ensures the information you gather from your respondents goes where you really want it to.

Without the PHP record, your structure resembles a vehicle without a motor – the information will stay put. Seeing the resource structures is to gather data, this makes it sort of fundamental.

The PHP record is associated with your structure by a line of code in your HTML (we’ll get to that in the following stage). You can see what it resembles underneath:

<form id="fcf-form-id" class="fcf-form-class" method="post" action="contact-form-process.php">

4. Generate the PHP code to capture form data

So the PHP record empowers you to catch information (name, email, message, and some other info type you’ve included). It then conveys it directly to your email address as a plain instant message.

Beneath we’ve included PHP code that, in specialized terms, approves client inputs on the server-side. To decipher that from gobbledygook: ensures everything works. It likewise creates any blunder and affirmation messages that clients might get when they finish up your structure.

Reorder the beneath code into the .php record. You should add your own email, title, and achievement message (they’re framed inside the code).

if (isset($_POST['Email'])) {

    $email_to = "";
    $email_subject = "New form submissions";

    function problem($error)
        echo "We're sorry, but there were error(s) found with the form you submitted. ";
        echo "These errors appear below.<br><br>";
        echo $error . "<br><br>";
        echo "Please go back and fix these errors.<br><br>";

    // validation expected data exists
    if (
        !isset($_POST['Name']) ||
        !isset($_POST['Email']) ||
    ) {
        problem('We're sorry, but there appears to be a problem with the form you submitted.');

    $name = $_POST['Name']; // required
    $email = $_POST['Email']; // required
    $message = $_POST['Message']; // required

    $error_message = "";
    $email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';

    if (!preg_match($email_exp, $email)) {
        $error_message .= 'The Email address you entered does not appear to be valid.<br>';

    $string_exp = "/^[A-Za-z .'-]+$/";

    if (!preg_match($string_exp, $name)) {
        $error_message .= 'The Name you entered does not appear to be valid.<br>';

    if (strlen($message) < 2) {
        $error_message .= 'The Message you entered do not appear to be valid.<br>';

    if (strlen($error_message) > 0) {

    $email_message = "Form details below.\n\n";

    function clean_string($string)
        $bad = array("content-type", "bcc:", "to:", "cc:", "href");
        return str_replace($bad, "", $string);

    $email_message .= "Name: " . clean_string($name) . "\n";
    $email_message .= "Email: " . clean_string($email) . "\n";
    $email_message .= "Message: " . clean_string($message) . "\n";

    // create email headers
    $headers = 'From: ' . $email . "\r\n" .
        'Reply-To: ' . $email . "\r\n" .
        'X-Mailer: PHP/' . phpversion();
    @mail($email_to, $email_subject, $email_message, $headers);


    Thanks for getting in touch. We'll get back to you soon.


5. Create your HTML contact form

All that is left is to make your structure. We’ve incorporated a layout that will produce a fundamental HTML contact structure for you. Simply duplicate the code straightforwardly into your supervisor of decision.

<!DOCTYPE html>
    <title>Contact Form</title>
    <h3>Contact us</h3>
    <form id="fcf-form-id" class="fcf-form-class" method="post" action="contact-form-process.php">
            <label for="Name" class="fcf-label">Your name</label>
            <div class="fcf-input-group">
                <input type="text" id="Name" name="Name" class="fcf-form-control" required>
        <div class="fcf-form-group">
            <label for="Email" class="fcf-label">Your email address</label>
            <div class="fcf-input-group">
                <input type="email" id="Email" name="Email" class="fcf-form-control" required>
        <div class="fcf-form-group">
            <label for="Message" class="fcf-label">Your message</label>
            <div class="fcf-input-group">
                <textarea id="Message" name="Message" class="fcf-form-control" rows="6" maxlength="3000" required></textarea>
        <div class="fcf-form-group">
            <button type="submit" id="fcf-button" class="fcf-btn fcf-btn-primary fcf-btn-lg fcf-btn-block">Send</button>

In the event that you’re new to HTML, it’s really smart to get the overall essence of what the code implies. If not you could be making a very shrewd A.I. furthermore, not even know it.

The “input” tag characterizes where clients can enter information, while the “mark” order addresses a subtitle for a thing in the UI (like where it says ‘Your Name’ over a passage field). “H1” marks the heading, and “div” behaves like a bookmark isolating various portions of the code.

One of the main parts is the “structure-activity” connecting to the PHP record. Without this to connect the HTML with the PHP record, your structure is simply doing a decent impression of a contact structure. It’ll look right, yet it will not really work.

At the point when you’ve entered the code it will create a structure that seems to be this:

Contact shapes frequently have dropdown boxes as well as standard structure fields. You can undoubtedly add one of your own with the accompanying lines of code:

 <label for="contact reason">Contact Reason</label>
    <select id="contact reason" name="contact reason">
      <option value="sales">Sales</option>
      <option value="help">Help</option>
      <option value="billing">Billing</option>

You can also add a checkbox, which is a useful way to get customers to opt-in to your email newsletter.

<input type="checkbox" id="newsletter" name="newsletter" value="newslettersignup">
  <label for="newsletter">Join our newsletter</label><br>

Recommended Theme: Newspaper v10.3.7 WordPress Theme Free Download [Activated] – Beaver Builder Pro v2.4.0.6 Plugin Free Download [2020] – Newspaper v10.3.6.1 Theme Free Download [Activated] – Bimber v8.5.1 WordPress Theme Free Download [2020] – GeneratePress Premium v1.12.2 Stable Free Download [2020] – Astra Pro Addon v2.6.4 Latest Version Free Download [2020] – REHub v12.9.3 WordPress Theme Free Download [Activated] – Bimber v8.5.0 WordPress Theme Free Download [Activated] – Jupiter X v1.20.1 WordPress Theme Free Download [Activated] –  Extra Theme v4.6.5 Latest Version Free Download [Activated]

Recommended Plugin: Yoast SEO Premium v14.6.1 Latest Version Free Download [2020] – Yoast SEO Premium v15.0 Plugin Free Download [2020] – GeneratePress Premium v1.12.1 Stable Free Download [2020] – Astra Pro Addon v2.6.4 Latest Version Free Download [2020] – WP Rocket v3.7.2 Premium Plugin Free Download [2020] – GeneratePress Premium v1.12.2 Stable Free Download [2020] – Mailster v2.4.14 Plugin Latest Version Free Download [Activated] – WP Smush Pro v3.7.1 Plugin Free Download [Activated] – Elementor Pro v3.0.5 Plugin Free Download [Activated] – Divi Builder v4.6.5 +1347 Premade Layouts Free Download [2020] – Restrict Content Pro v3.4.4 – With 17 Addons Free Download

Leave a Comment