Skip to content

Send an HTML form to email without writing a backend

Point any HTML form at one endpoint and get every answer by email, with spam filtering and a thank-you page, and no server code.

3 min read

On this page

A plain HTML form needs somewhere to send its answers. The usual options are a PHP script on shared hosting, a serverless function you have to maintain, or a mailto link that opens the visitor's email app and loses half your leads. There is a simpler way: set the form's action to a form backend endpoint, and let it store the answers, filter spam and email them to you.

This guide walks through it with Formpik. It works on any static site: a hand-written page, a site generator such as Hugo or Eleventy, or a template you bought.

How a form backend works

An HTML form sends its fields to the address in its action attribute, using the method in method. Normally that address is a script on your own server. A form backend gives you a ready-made address instead. When the browser posts to it, the backend checks the answers, stores the submission, runs whatever should happen next (an email, a Slack message, a webhook) and sends the visitor back to your page.

Step 1: Create a form and an HTML source

In Formpik, create a form with the fields your page sends, such as name, email and message. Then add a source and pick HTML form. The source gives you an endpoint address that ends in a unique key. That address is all your page needs.

Step 2: Point the form at the endpoint

<form action="https://formpik.com/api/in/YOUR_KEY" method="POST">
  <label for="name">Name</label>
  <input id="name" name="name" required>

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

  <label for="message">Message</label>
  <textarea id="message" name="message"></textarea>

  <button type="submit">Send</button>
</form>

The name of each input must match a field key in Formpik. If your page sends a field the form does not have yet, turn on Learn new fields automatically and it is added the first time it arrives.

Step 3: Keep visitors on the page

Without any script, a classic form post leaves the page. Formpik answers it with a 303 See Other redirect back to your page with ?submitted=1 added, or to your own thank-you page if you add a hidden _redirect input. That works everywhere, even with JavaScript turned off.

If you would rather keep visitors where they are, add the Formpik script. It catches the submit, sends the form in the background and shows a success or error message under the form, so the page never reloads:

<script src="https://formpik.com/formpik.js" defer></script>

Step 4: Get every answer by email

Open Flows, start from the Form submitted trigger and add a Send email step. Put your address in To and {{email}} in Reply to, so answering the email answers the visitor. The message can list every answer with {{submission.all_fields}}, or pick fields one by one. Turn the flow on and send a test from your page.

Step 5: Keep spam out

Every form comes with a hidden spam trap field turned on. Bots fill it in, people never see it, and those submissions are stored under Spam without sending any email. You can also limit how many submissions one visitor may send in an hour, and list the websites allowed to post to the form, so nobody can reuse your endpoint on another site.

What you get beyond email

  • An inbox with every submission, searchable and exportable, so nothing lives only in someone's mailbox.
  • File uploads, stored privately and opened through short-lived links.
  • Field rules such as required, length limits and work emails only, checked on the server so nobody can skip them.
  • Flows that can route by answer, post to Slack or Teams, or call your own webhook.

References

Keep reading

More from the blog