Falkenstein, Germany · Hetzner Online GmbH
FormHaven

A Next.js contact form without an API route

Drop one client component into your app and every message is spam filtered, stored in Germany and emailed to you. There is no route handler, no Server Action and no email API key to keep on a server, so it also works on a static export.

14 days free, no card. Paste the address where the code says YOUR_FORM_ID.

app/contact/ContactForm.tsx
"use client";
import { useState, type FormEvent } from "react";

type Problem = { field?: string; message: string };

export function ContactForm() {
  const [sent, setSent] = useState(false);
  const [problems, setProblems] = useState<Problem[]>([]);

  async function send(event: FormEvent<HTMLFormElement>) {
    event.preventDefault();
    const form = event.currentTarget;
    const response = await fetch(form.action, {
      method: "POST",
      headers: { Accept: "application/json" },
      body: new FormData(form),
    });
    const result = await response.json();
    setSent(result.ok);
    setProblems(result.ok ? [] : result.errors);
    if (result.ok) form.reset();
  }

  const problem = (field: string) => problems.find((p) => p.field === field)?.message;

  return (
    <form action="https://formhaven.net/f/YOUR_FORM_ID" method="POST" onSubmit={send}>
      <input type="email" name="email" required />
      {problem("email") && <p>{problem("email")}</p>}
      <textarea name="message" required />
      <input type="text" name="_gotcha" style={{ display: "none" }} tabIndex={-1} autoComplete="off" />
      <button type="submit">Send</button>
      <p role="status">{sent ? "Thanks, your message is on its way." : problems.find((p) => !p.field)?.message}</p>
    </form>
  );
}

Set it up

  1. 1

    Create a form in FormHaven

    Sign up, press New form and copy its address. It looks like https://formhaven.net/f/YOUR_FORM_ID.

  2. 2

    Add the component

    Save the code above as app/contact/ContactForm.tsx, paste your address into the action, and render <ContactForm /> from app/contact/page.tsx.

  3. 3

    Read the answer

    With Accept: application/json the reply is {"ok": true}, or {"ok": false, "errors": [...]} where each error has a code, a message and, when one input caused it, the field name.

  4. 4

    Send a test

    Run next dev, fill in the form and check your inbox. Or press Send a test submission in the dashboard.

Static export works too

The Next.js docs list Server Actions among the features a static export does not support. This form never calls your own server, so you can build with output: "export" and host the out folder anywhere, GitHub Pages included.

next.config.js
/** @type {import("next").NextConfig} */
const nextConfig = {
  output: "export",
};

module.exports = nextConfig;

On the Pages Router

The same component works in a pages/ app. Drop the "use client" line, save it under components/ and render it from pages/contact.tsx.

pages/contact.tsx
import { ContactForm } from "../components/ContactForm";

export default function Contact() {
  return (
    <main>
      <h1>Contact us</h1>
      <ContactForm />
    </main>
  );
}

Questions about this setup

Why not a route handler with an email API?
That works on a server, but you write and run the code, keep an API key secret, and still need spam filtering and somewhere to read old messages. It also rules out a static export.
Can an agent set this up for me?
Yes. Ask Claude Code or Cursor to add a FormHaven contact form. Through our MCP server it can fetch a ready React component for your form with get_form_code.
Does it still work without JavaScript?
Yes. The form has a real action and method, so the browser posts it the normal way and the visitor sees our thank-you page, or yours if you set one on the form.
Can my client get the messages instead of me?
Yes. Add up to 5 more addresses to the form. Each one confirms by a link first, and their copy carries no FormHaven branding. You can turn your own copy off.
Where is the data stored?
On our server at Hetzner in Falkenstein, Germany, for 1 to 365 days as you choose per form, or not at all. A data processing agreement covers every account.

More to read

Vercel contact formHosting the site on Vercel Astro contact formA Contact.astro component for a static Astro site HTML form to emailOne line in the action, every message in your inbox Static site contact formOne form for Astro, Hugo, Eleventy, Jekyll or plain HTML Hugo contact formA partial and a shortcode for a static Hugo site Lovable contact formOne prompt for a site built with Lovable GDPR compliant contact formEU storage, a DPA and retention you set Kontaktformular nach DSGVOAuf Deutsch: gespeichert in Deutschland, mit AVV JavaScript contact formA fetch script that keeps the visitor on the page FormSubmit not workingThe usual causes of a silent FormSubmit form Web3Forms not workingThe usual causes of a silent Web3Forms form Eleventy contact formAn include for a static Eleventy (11ty) site Formspree not workingThe usual causes of a silent Formspree form Export from FormspreeEvery Formspree submission, as a file Export from FormsparkEvery Formspark submission, as a file EmailJS not workingThe usual causes of a silent EmailJS form Form backend for AI agentsThe start request, every REST route and MCP tool Claude Code contact formOne prompt, then press Activate Cursor contact formThe prompt and the .cursor/mcp.json entry Contact form privacy policyThe paragraph to copy, in 8 languages GitHub Pages contact formFor user, organisation and project sites on github.io Cloudflare Pages contact formFor sites on pages.dev or your own domain Netlify contact formFor sites on netlify.app or your own domain React contact formOne component for Vite and other React apps Send form submissions to multiple emailsUp to 5 confirmed addresses per form, plus yours SvelteKit contact formOne Svelte 5 component, any adapter Nuxt contact formOne Vue component for Nuxt 4 and 3 Gatsby contact formOne component for a Gatsby 5 site HTML form webhookSigned JSON to your endpoint for every message Jekyll contact formAn include for Jekyll, on GitHub Pages or any host Angular contact formA standalone component that posts with HttpClient Contact form spamWhy forms get spam, and the layers that stop it Contact form honeypotThe hidden field that catches bots, and how to hide it Contact form without PHPFor hosts with no PHP, or mail() that lands in spam HTML form mailtoWhy action="mailto:" fails on webmail visitors, and the one-line fix Contact form templateThe same form in plain HTML Pricing€1 per form a month, €0.50 from the 11th

Get your form address in a minute

14 days free, no card. Then €1 per form a month, €0.50 from the 11th form.

Start your 14-day trial