Your AI Built the Site — Now Make Its Contact Form Actually Send Emails
Michael Sacca•We've written a lot about the moment the folder of files Claude generated becomes a real website — deploying it to Cloudflare Pages, QA-ing it before it ships, keeping it updated on autopilot. What almost every guide in this genre skips is the least glamorous feature on the page: the contact form.
It looks done. There's a <form>, some inputs, a button with rounded corners. And it does absolutely nothing. A static site has no server to receive a POST request, no inbox to forward anything to, no way to tell the difference between a real inquiry and a bot. Your beautiful form is a prop.
This post is about the plumbing: turning that prop into a form that actually sends email, using free serverless endpoints, without ever standing up a backend. And since you built the site with an LLM, we'll keep the LLM in the loop for the part where things inevitably break.
Why the form breaks (and why that's structural, not a bug)
A static host — GitHub Pages, Cloudflare Pages, Netlify serving plain files — serves HTML, CSS, and JavaScript. That's it. When a visitor submits your form, the browser tries to send that data somewhere. By default, that "somewhere" is a navigation to the current page with the form fields appended to the URL, which is why a broken form often just reloads the page and silently throws the message away.
There's no email server on a CDN. So you have exactly three realistic paths:
- A form-to-email service — a third party that exposes an endpoint your form POSTs to, and which forwards submissions to your inbox. Formspree, Web3Forms, and Getform are the names you'll see most; most offer a free tier with monthly submission limits that vary by plan, so check the current numbers before committing.
- Your host's built-in form handling — Netlify, for example, can process forms natively on sites it deploys if you add the right attribute to the form tag. Convenient, but it locks the feature to that host.
- A tiny serverless function you write yourself — a file that runs when the form is POSTed, which calls an email API (Resend, SendGrid, or similar) and returns a response. Free tiers of both the host's functions and the email API usually cover a personal site's volume.
Option 3 is the one worth learning, because it's the one you fully own — and because it's the exact thing Claude is good at writing.
The pattern: static files plus one function
The mental model is simple. Everything about your site stays exactly as it is. You add one directory that your host treats as serverless functions, and one file in it. Your form's JavaScript POSTs to that function's URL instead of nowhere.
On Cloudflare Pages, that directory is functions/. A contact endpoint looks roughly like this:
// functions/api/contact.js
export async function onRequestPost(context) {
const { name, email, message } = await context.request.json();
if (!name || !email || !message) {
return Response.json({ ok: false, error: "Missing fields" }, { status: 400 });
}
const res = await fetch("https://api.resend.com/emails", {
method: "POST",
headers: {
"Authorization": `Bearer ${context.env.RESEND_API_KEY}`,
"Content-Type": "application/json",
},
body: JSON.stringify({
from: "[email protected]",
to: "[email protected]",
subject: `New message from ${name}`,
text: message,
}),
});
if (!res.ok) return Response.json({ ok: false }, { status: 500 });
return Response.json({ ok: true });
}
On the front end, your form handler stops being a plain submission and becomes a fetch:
form.addEventListener("submit", async (e) => {
e.preventDefault();
const data = Object.fromEntries(new FormData(form));
const res = await fetch("/api/contact", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify(data),
});
// show success or error state
});
Deploy, and the form works. Except, of course, it won't — the first time.
The parts that actually go wrong
This is where the post you're reading earns its keep, because every one of these failure modes will happen to you:
- The API key has to live server-side. If the email API key ends up in your front-end JavaScript, anyone can read it and send email as you. It belongs in your host's environment variables — Cloudflare calls them environment variables on the project settings page — and the function reads them from its runtime context, never the page.
- Sender verification. Email APIs require you to prove you own the address you're sending from, usually by adding DNS records. If your domain's DNS lives somewhere your host doesn't manage — see our breakdown of the four layers behind your site's URL — you'll be adding records at your registrar, not your host.
- Spam. A working public form endpoint gets found by bots within days. A honeypot field (a hidden input bots fill and humans don't) plus a rate limit on the function handles most of it at free-tier scale.
- CORS and error states. A silent
fetchfailure and a successful submission look identical if you didn't write the success/error UI. Test both paths.
Where the LLM loop comes in
You could debug all of this yourself. But you're already working with an assistant that can read your function code, your deployment logs, and your form handler and reason across all three. The workflow that works:
- Paste the error verbatim. Deployment logs and browser console output are worth more than your paraphrase of them. "It doesn't work" gets you guesses; the actual 500 response from
/api/contactgets you the diagnosis. - Give it the whole path, not a fragment. The form HTML, the fetch code, the function, and where the env var is configured. Most form bugs are a mismatch between two of those four pieces — a field named
messagein the form andmsgin the function, a fetch to/api/contactwhen the function deployed at/api/contact.js. - Ask it to write the failure modes in. A good prompt isn't "write me a contact form." It's "write a contact form handler with visible success and error states, a honeypot field, and validation for empty inputs."
- Use MCP where your host offers it. Cloudflare ships MCP servers that let Claude inspect your actual deployments and logs rather than working from pasted excerpts — the difference between debugging from a description and debugging from the scene of the accident.
The pattern from our piece on the second-order work nobody's tutorial covers applies here too: the generation is the ten minutes, the plumbing is the afternoon, and the LLM earns its keep almost entirely in the second half.
The honest trade-off
If all you need is "messages land in my inbox," a hosted form service's free tier is genuinely less work — one endpoint URL, no functions, no DNS records. The build-it-yourself path buys you ownership: no per-submission pricing cliff, no vendor watermark on the thank-you state, and a function you can extend into newsletter signups, webhook relays, or anything else without changing vendors.
For a site you plan to keep, the afternoon of plumbing is usually the right trade. And now the form on your AI-built page is no longer a prop — it's the only part of the site that talks back.
Keep Reading
Your AI-Built Site Looks Fine on Your Laptop. Run This QA Prompt Before You Ship It.
Nov 29, 2026
Every AI-Built Site Looks the Same. Here's the Design System File That Makes Claude Build Yours Instead.
Nov 23, 2026
The Self-Updating Site: Wiring Claude and MCP Into a Pipeline That Publishes Without You
Nov 30, 2026