Every Next.js site eventually needs a contact form. And every time, the same question comes up: where do the submissions actually go?
Next.js on Vercel or Netlify has no mail server. So you either write some backend code, configure an email provider, or hand the job to a service. Let's look at the three options, then build the simplest one step by step.
Option 1: Your own API route + an email API
Create app/api/contact/route.js, validate the input, and send an email with a provider like Resend, Postmark or SendGrid.
Pros: full control, no third party for the form itself.
Cons: you own everything: domain verification (SPF/DKIM), spam protection, rate limiting, storing submissions, and keeping it working when something changes. For a simple portfolio or client site, that's a lot of moving parts.
Option 2: Your host's built-in forms
Netlify Forms works well if you're on Netlify, but it ties your form to that host. Move to Vercel or a VPS and you rewrite it.
Option 3: A form backend
You point the form at an external endpoint that receives the submission, filters spam and notifies you. No backend code, and it works on any host. This is what we'll build.
For this example I'm using Formiz, a form backend I built (full disclosure). It sends submissions to email and Telegram and keeps them in a small dashboard. The same pattern works with other form backends too.
Step 1: Get an access key
Create a free account at formiz.app, create a project and copy its access key. Then add your email address under Channels so notifications have somewhere to go.
Put the key in .env.local:
NEXT_PUBLIC_FORMIZ_KEY=your-access-key It's fine for this key to be public: it only allows sending submissions to your project, and you can restrict it to your own domains in the dashboard.
Step 2: The form component
// app/ContactForm.jsx 'use client'; import { useState } from 'react'; export default function ContactForm() { const [status, setStatus] = useState('idle'); // idle | sending | sent | error const [error, setError] = useState(''); async function onSubmit(e) { e.preventDefault(); const form = e.currentTarget; setStatus('sending'); setError(''); try { const res = await fetch('https://api.formiz.app/submit', { method: 'POST', headers: { Accept: 'application/json' }, body: new FormData(form), }); const data = await res.json(); if (!res.ok || !data.success) throw new Error(data.message || 'Something went wrong'); form.reset(); setStatus('sent'); } catch (err) { setError(err.message); setStatus('error'); } } return ( <form onSubmit={onSubmit}> <input type="hidden" name="access_key" value={process.env.NEXT_PUBLIC_FORMIZ_KEY} /> <input type="hidden" name="subject" value="New message from my site" /> {/* Honeypot: hidden from humans, bots fill it in */} <input type="checkbox" name="_honey" style={{ display: 'none' }} tabIndex={-1} autoComplete="off" /> <input name="name" placeholder="Your name" required /> <input name="email" type="email" placeholder="you@example.com" required /> <textarea name="message" rows={5} placeholder="How can we help?" required /> <button type="submit" disabled={status === 'sending'}> {status === 'sending' ? 'Sending…' : 'Send message'} </button> {status === 'sent' && <p role="status">Thanks! Your message has been sent.</p>} {status === 'error' && <p role="alert">{error}</p>} </form> ); } A few details worth noticing:
-
Accept: application/jsontells the endpoint to answer with JSON instead of redirecting, so you can show your own success message. -
FormDatasends every field as is. Add any field you like (phone,company,budget…) and it shows up in the notification. - The honeypot (
_honey) is a cheap, effective spam filter: real visitors never see it, bots tend to tick every box. - A field named
emailbecomes the reply-to address, so hitting Reply in the notification email answers the visitor directly.
Step 3: Use it on a page
// app/page.jsx import ContactForm from './ContactForm'; export default function Page() { return ( <main> <h1>Contact us</h1> <ContactForm /> </main> ); } Run npm run dev, submit the form, and the message lands in your inbox a few seconds later.
No JavaScript? Plain HTML works too
If you don't need a custom success message, skip React state entirely:
<form action="https://api.formiz.app/submit" method="POST"> <input type="hidden" name="access_key" value="YOUR_ACCESS_KEY"> <input type="hidden" name="redirect" value="https://example.com/thanks"> <input name="name" required> <input name="email" type="email" required> <textarea name="message"></textarea> <button>Send</button> </form> The visitor is sent to your redirect URL after submitting. This version works in any static site, WordPress theme or Webflow embed.
The full example
The complete, runnable project (with styling and a .env.example) is on GitHub:
👉 github.com/loc0w/formiz-nextjs-contact-form
Which option should you pick?
- Building a product with its own backend already? Option 1 fits naturally.
- Hosting only on Netlify and never moving? Option 2 is fine.
- Client sites, portfolios, landing pages, anything static? A form backend saves you the most time.
If you try Formiz, I'd love to hear what's missing. It's free while in early access, and I'm building it solo, so feedback goes straight into the next update. 🙌



