HTML form to email
How do I build a React contact form that sends email without a backend?
By the FormToMail team · Checked against official sources · Updated
In React you send the form data to a form endpoint with `fetch()` in the submit handler and keep the status in state; the endpoint emails you. No backend of your own is needed, so it works in Vite, Next.js static exports and React apps generated by Lovable, Bolt or v0.
| Approach | Backend needed | Notes |
|---|---|---|
| fetch() to a form endpoint | No | Code below |
| Next.js Server Action / Route Handler | Yes (Node server) | Not available in output: 'export' |
| Supabase / database insert | Hosted DB | Stores the message but doesn't email you by itself |
Component
import { useState } from "react";
export function ContactForm() {
const [status, setStatus] = useState<"idle" | "sending" | "sent" | "error">("idle");
async function onSubmit(e: React.FormEvent<HTMLFormElement>) {
e.preventDefault();
setStatus("sending");
const res = await fetch("https://getformtomail.com/f/YOUR_FORM_ID", {
method: "POST",
body: new FormData(e.currentTarget),
headers: { Accept: "application/json" },
});
setStatus(res.ok ? "sent" : "error");
}
if (status === "sent") return <p>Thanks! We'll get back to you.</p>;
return (
<form onSubmit={onSubmit}>
<input name="name" required />
<input name="email" type="email" required />
<textarea name="message" required />
<button disabled={status === "sending"}>{status === "sending" ? "Sending…" : "Send"}</button>
{status === "error" && <p>Something went wrong. Please try again.</p>}
</form>
);
}react-hook-form
With react-hook-form, call the same fetch() inside handleSubmit, sending JSON.stringify(values) with Content-Type: application/json. Validation still runs client-side; the endpoint also refuses empty submissions.
Quick answers
React contact form send email without backend?
Yes: fetch() to a form endpoint, as above.
Can I use a form backend with a React single page app?
Yes. CORS is open on FormToMail's endpoint, so any origin can call it.
Is it safe to put a form endpoint URL in frontend code?
Yes, it is meant to be public. Abuse is handled by spam checks and rate limits, not by hiding the URL. See is a public form key safe.
What to do next
Create an endpoint and paste it into the component.
Get your form endpointSources
Checked: . Prices, limits and features of other services change: confirm current values at the official links above. Product names belong to their owners; we are not affiliated with them.