How to create a simple HTML contact form from scratch

How to create a simple HTML contact form from scratch

The form we’re building is very simple, if you want to achieve advanced features like file upload or spam protection please take a look at our file upload form

Already have a HTML form and not much time? We offer spam filtering, email notifications and a submissions dashboard on the free plan at formcarry; all you change is the form's action attribute.

Can an HTML form send email on its own?

No. The <form> element collects the values and submits them with the method you set (POST here) to the action URL, and something at that address has to receive them and talk to a mail server. That something is either a server-side script you host, like the PHP file in Option 1, or a form endpoint, like formcarry in Option 2. A mailto: action, the third option you’ll see suggested, only opens the visitor’s own email app and sends nothing unless they finish the job, so I don’t recommend it.

What you’ll need:A text editor and a page on any static hostOption 1: a host that runs PHP with mail() configuredOption 2: a free formcarry account (the Baby plan covers 1 form and 50 submissions a month)About 10 minutes for the HTML and CSS, 2 to 15 more for processingBeginner level: copy and paste works

Create a Simple HTML Contact Form

Copy and paste this code to your HTML page, this is going to be the base of our form.

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta http-equiv="X-UA-Compatible" content="ie=edge" />
    <title>Contact Form</title>
    <!-- Form styling -->
    <link rel="stylesheet" href="formcarry-form.css" />
  </head>
  <body>
    <div class="formcarry-container">
      <form action="#" method="POST" class="formcarry-form">
        <label for="name">Your Name</label>
        <input type="text" id="name" name="fullName" required />

        <label for="email">Your Email Address</label>
        <input type="email" id="email" name="email" required />

        <label for="message">Your Message</label>
        <textarea name="message" id="message" cols="30" rows="10"></textarea>

        <button type="submit">Send</button>
      </form>
    </div>
  </body>
</html>

How do you make a web form from scratch? Three attributes do the work here: method="POST" sends the values in the request body, action is where they go (the # is replaced in Option 1 or Option 2), and every input has a name, because an input without one is never sent and nothing warns you.


CSS codes for your HTML form

File name: formcarry-form.css (Please save using exact name)

Paste this code to make styling work

@import url("https://fonts.googleapis.com/css2?family=Inter:wght@400;700&display=swap");

/*
  CONTACT FORM EXAMPLE FOR formcarry

  IMPORTANT NOTE:
  PLEASE ADD formcarry-form class to your form element
  to apply the styles.
*/

.formcarry-container * {
  box-sizing: border-box;
	font-family: "Inter", sans-serif;

  /* colors */
  --color-blue: #2552d0;
  --color-light-blue: #3266e3;
  --color-gray: #e5e7eb;
  --color-dark-gray: #9da3ae;
  --color-pink: #edadd2;
}

.formcarry-container {
  /* container */
  --c-width: 50%;
  --c-max-width: 500px;

  width: var(--c-width);
  max-width: var(--c-max-width);
  display: block;
  margin: 10vh auto 0 auto;
}

.formcarry-form label {
  display: block;
  padding: 12px 0 2px 0;
  letter-spacing: -0.2px;
  cursor: pointer;
  font-size: 16px;
  font-weight: 700;
}

.formcarry-form input,
.formcarry-form textarea {
  font-size: 16px;
  display: block;
  width: 100%;
  padding: 10px;
  background-color: var(--color-gray);
  border: none;
  border: 4px solid var(--color-gray);
  outline: none;
  border-radius: 8px;
  color: var(--color-dark-gray);
}

.formcarry-form input:focus,
.formcarry-form textarea:focus {
  background-color: #fff;
  color: var(--color-dark-gray);
}

.formcarry-form input:focus:required:invalid {
  border-color: var(--color-pink);
  background-color: #fff;
}

.formcarry-form button {
  display: block;
  margin-top: 12px;
  width: 100%;
  padding: 12px 20px;
  border-radius: 8px;
	border-color: transparent;
  background-color: var(--color-blue);
  color: #fff;
  font-weight: 700;
  font-size: 18px;

  transition: 300ms all;
}

.formcarry-form button:hover {
  background-color: var(--color-light-blue);
}

.formcarry-alert {
  padding: 12px;
  border-radius: 10px;
  color: #fff;
  font-size: 14px;
  font-weight: 400;
  margin-top: 12px;
  display: none;
}

.formcarry-alert.visible {
  display: block;
}

.formcarry-alert.success {
  background: #69cf9d;
}

.formcarry-alert.error {
  background: #de524c;
}

Bonus: Free HTML5 Contact Form Generator

We have created a form generator that you can use to build your own contact forms and completely customize it with your brand or website's color scheme and design style. They are free to download and can be used on your personal or commercial projects.

Check out our free HTML form generator to build one with your own fields and colors.


Option 1: HTML Form Processing with PHP

First replace the # with form-process.php like below

<!-- Replace this -->
<form action="#" method="POST" class="formcarry-form">
<!-- With this -->
<form action="form-process.php" method="POST" class="formcarry-form">
Why? because action part of the form element tells your browser to where to send form data, in this case we need to point our form data to form-process.php

Then create a file called: form-process.php (should be exact name)

<?php
if (isset($_POST['email'])) {

    // REPLACE THIS 2 LINES AS YOU DESIRE
    $email_to = "you@awesomecompany.com";
    $email_subject = "You've got a new submission";

    function problem($error)
    {
        echo "Oh looks like there is some problem with your form data: <br><br>";
        echo $error . "<br><br>";
        echo "Please fix those to proceed.<br><br>";
        die();
    }

    // validation expected data exists
    if (
        !isset($_POST['fullName']) ||
        !isset($_POST['email']) ||
        !isset($_POST['message'])
    ) {
        problem('Oh looks like there is some problem with your form data.');
    }

    $name = $_POST['fullName']; // 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 .= 'Email address does not seem valid.<br>';
    }

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

    if (!preg_match($string_exp, $name)) {
        $error_message .= 'Name does not seem valid.<br>';
    }

    if (strlen($message) < 2) {
        $error_message .= 'Message should not be less than 2 characters<br>';
    }

    if (strlen($error_message) > 0) {
        problem($error_message);
    }

    $email_message = "Form details following:\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);
?>

    <!-- Replace this as your success message -->

    Thanks for contacting us, we will get back to you as soon as possible.

<?php
}
?>

This is how your form supposed to look like:

Styled HTML contact form with name, email and message fields and a blue Send button

You’ll know it’s working when: the thanks message shows and the email arrives at $email_to within a minute. Thanks text with no email means a delivery problem, not an HTML one.

Watch out for:

  • Field names that don’t match the script: the PHP reads $_POST['fullName'], $_POST['email'] and $_POST['message']. Rename an input without changing the script and it dies with the problem message.
  • The From: header set to the visitor’s address: mail providers that enforce domain authentication junk or reject mail claiming to come from a domain you don’t own. Put an address on your own domain in From: and keep the visitor in Reply-To:.
📊
By the Numbers: Nearly half of what a typical contact form receives is spam: 45.8%. Source: formcarry's analysis of 2,580 active forms, January 2024 to October 2026. Decide how you will filter it before the first real message arrives.

While this will create a working HTML form that sends you an email, you need to be aware of:

  • No spam protection: there is no filtering in this PHP, and building your own takes time to implement and improve.
  • Emails can land into the spam folder: mail() hands the message to the local mail system, and the PHP manual is explicit that a true return only means the message was accepted for delivery, not that it reached anyone. Google’s Email sender guidelines require SPF or DKIM on the sending domain and a reported spam rate below 0.3%; a shared host with neither record lands in spam. Your server might also crash and you won’t notice it for a long time, which can cost very bad for your business.
  • File upload takes time to implement: In case you need to upload files from your form, be aware that implementation of it takes a lot of time, and creates a lot more complexity and security concerns to deal with.

Option 2: HTML form processing with formcarry

If you need more functionalities from your form, you need to deal with the complexity that comes with it. If you want to make a working simple HTML contact form backend without PHP, we have the solution.

Try formcarry for free; it works with your own HTML code, you just need to change your form action attribute.

Create a form in formcarry

Create an account then create a form like below

Creating a form in formcarry dashboard

Create a form in formcarry

Integrate your HTML form

Copy your form endpoint by clicking copy clipboard button (the formcarry quickstart shows where it sits in the dashboard), then change your HTML form code that we used above.

<!-- Replace this -->
<form action="#" method="POST" class="formcarry-form">
<!-- With this -->
<form action="{PASTE YOUR FORM ENDPOINT HERE}" method="POST" class="formcarry-form">

That’s all you need to process your form now

Try your form

Submitting the test contact form and landing on formcarry's default thank-you page

Just by changing your action attribute, you can achieve:

  • Email notifications for new submissions
  • A dashboard that you can sort and filter your form data
  • Spam protection on every plan; flagged submissions stay visible, never deleted
  • Zapier, which reaches 3,000+ apps

On a paid plan (from $6 a month) the same form also gets:

📊
By the Numbers: Forms start needing integrations once they collect a lot of submissions. Which integrations depends on the kind of form and the industry. One thing is clear: among teams that get 50 or more real submissions a month, 58% use at least one integration, a webhook or Zapier. Source: formcarry data on teams with a paid plan, November 2026.

Take a look at your dashboard and you’ll see your new submission:

Opening the new submission in the formcarry dashboard to read the message fields

Also email notification for the new submission. The free plan notifies one address; on a paid plan you can add as many emails as you like from the self email notification settings.

Email notification from formcarry showing the contact form submission in an inbox

Creating a working form with formcarry takes less than 2 minutes, and the free Baby plan covers 1 form and 50 submissions a month; spam does not count toward the limit (see the free plan).

You’ll know it’s working when: the submission appears in the dashboard and its delivery log shows the email notification as delivered. The thank-you page only proves the browser reached formcarry; the delivery log proves the email left and where it went.


HTML Form Field examples

It's possible for you to ask which HTML element is used to create an HTML form for user input? Let us show you the fields that you can use in your form, just copy and paste the codes below.

How many fields should a contact form have? Four or five. The typical contact form has 4.4 fields, against 7.2 for a quote form and 11 for an order form. Source: formcarry data, 2,580 active forms. Name, email and message are the core, and a fourth field, phone or subject, earns its place only if someone will act on it.


HTML Label Field

Label field is the text that’ll focus to the desired form element on click, to target a field you need to give target element id inside the label elements for attribute like this:

<!-- insert the ID of target element inside the for attribute -->
<label for="myElement">Focus to the field</label>
<!-- give an ID attribute to the target element so label can work -->
<input id="myElement" type="text" />

HTML Text Field

Text field is the most used form field on the web, this is widely used for short texts.

<label for="name">Text Field</label>
<input type="text" id="name" name="fullName" />

HTML Textarea Field

Textarea is like text field but it’s for much bigger content, like messages.

<label for="message">Textarea Field</label>
<textarea type="text" id="message" rows="5" cols="5" name="message"></textarea>

rows and cols attributes allow you to specify width and height of textarea yet you can always manipulate that using CSS.

💡
Quick Insight: The message box is where spam lands. A typical form with a message field gets 42.2% spam. A typical form without a message field gets 3.9% spam. Source: formcarry data, 2,580 active forms. A contact form needs that box, so plan your filtering around it instead of dropping it.

HTML Email Field

Some HTML fields have built in validations, Email input is one of them, it will complain unless you enter a valid email address, and it won’t let you submit.

<input type="email" />
Try to submit by entering normal text, the field will warn you that it requires a valid email address
Notice how input border color reacts to validity of your input, until you enter a valid email address you’ll see a red color, I’ve implemented this for demo purposes so that’s not the default behavior.

The browser blocks the submit until the value matches an email pattern (MDN on the email input). Treat that as a convenience, not a defense: MDN’s form validation guide is clear that client checks can be bypassed, which is why form-process.php validates again on the server.


HTML Telephone Field

You specify a number pattern with telephone field, and it will complain unless you enter phone number through the pattern you have specified.

<input type="tel" pattern="[0-9]{3}-[0-9]{2}-[0-9]{3}" />

Required format 123-45-678

Tel field also shows num pad on mobile devices.

Mobile browser showing the numeric keypad for an HTML telephone input field

HTML Date Field

Date field is very handy most of the time, because it’s a native type all devices will show some sort of date selector to the user, you can specify minimum and maximum ranges for dates to be chosen.

<input type="date" value="2022-10-29" min="2022-01-01" max="2022-12-31" />
Native date picker opened by an HTML date input in a browser

HTML Password Field

Password field is normal text field but the difference is the value you entered will be masked with asterisks to hide sensitive information.

<input type="password" />

As a product engineer who works on payments, I’ll be blunt: this field does not belong in a contact form, and neither does a card number. The values travel as plain fields, land in an inbox and get forwarded, and none of those places is built to hold a secret; a card number also pulls your site into PCI DSS scope. Use this field on a login form that posts to your own authentication backend, and leave card details to a payment provider’s hosted checkout.


Test your form before you ship it

Submit a real test from the live page, not from a file opened on your desktop, and check three things in order.

  1. The browser left the page. Option 1 shows the thanks text from form-process.php; Option 2 lands on the thank-you page. If you stay where you were, the action is wrong or the method isn’t POST.
  2. The data arrived complete. Option 1: open the email and check every field is present; a missing one means a name attribute is missing or misspelled. Option 2: open the submission in the dashboard and check the same.
  3. The email was delivered, not just sent. Option 1: check the server’s mail log and your spam folder, because mail() can return true and reach nobody. Option 2: open the submission’s delivery log; it records whether the notification was delivered or bounced, and incident tracking emails you when a recipient starts failing.
🔑
Key Takeaway: For a new contact form, the email is the whole delivery. Test that it arrives, not just that the thank-you page shows.

Then repeat the test from a phone, where a blocked required field is easy to miss.


Frequently asked questions

How do I make an HTML contact form send email?

Point the form’s action at something that can talk to a mail server; HTML only describes the fields and where to send them. That something is a script on your server (Option 1) or a form endpoint such as formcarry (Option 2).

How do I make an HTML contact form send email without PHP?

Point the form’s action at a form endpoint. Create a form in formcarry, paste its endpoint URL into action, keep method="POST", and every submission is stored, filtered for spam and emailed to you with no server code on your side. This is the route on a static host where PHP can’t run.

Why does my HTML form not send the data?

Check four things in order. The action still says # or points to a file that doesn’t exist. The method is missing, so the browser sends a GET and your PHP reads an empty $_POST. An input has no name attribute, so its value is never sent. Or a required field is empty and the browser blocked the submit. The browser’s network tab shows what left on Send.

Is mailto: a good way to send a contact form?

No. action="mailto:you@example.com" doesn’t send anything; it asks the visitor’s device to open an email app with the fields pasted into a new message. On a phone with no mail app, nothing happens, and visitors who do get a draft often don’t press send. Keep it as a fallback link, never as the form’s action.

How do I stop spam on an HTML contact form?

With the PHP option you build it yourself: validate on the server and add a captcha challenge. With formcarry, spam protection runs several independent detection layers at ingest, and you can add a captcha challenge to any form. Flagged submissions stay visible and are never deleted, so a real message caught by mistake can be marked as not spam.

Where can I get free HTML contact form code for my website?

The code at the top of this page is free to copy for personal or commercial use, and the HTML contact form example page has a ready version wired to a formcarry endpoint. For different fields or colors, the HTML form generator above produces the markup and CSS. Either way the form still needs a processing step; code alone doesn’t deliver email.


Conclusion

A simple HTML contact form is three fields, a method="POST" and an action that points somewhere that can send email. The HTML and CSS above get you the form. form-process.php gets you a working email on a host that runs PHP, as long as you authenticate your sending domain and watch delivery. A formcarry endpoint gets you the same result on any host, plus spam filtering, a dashboard and a delivery log for every submission. Whichever you pick, verify the email arrived, not just that the thank-you page showed.

Get started free and have your first form delivering in a couple of minutes.

About the numbers: they come from formcarry's analysis of its own submission records. "Typical" means the median of 2,580 active forms, each with at least 20 real submissions between January 2024 and October 2026. "Spam" is what formcarry flagged and kept out of the count of real submissions. Form types are worked out from form and field names.