React & Next.js 5 min read Updated 2026-11-21

How to Build a Next.js Contact Form Without Writing an API Route

Marketing sites and static Next.js exports should not need database pools, Nodemailer secrets, and custom spam logic just to receive a contact message.

Why Custom /api/contact Routes Add Unnecessary Maintenance

When building a Next.js landing page or client site, wiring up a custom Route Handler means provisioning an email API key, installing SDK packages, building HTML email templates, storing submissions in a database so leads are never lost if an email bounces, and writing honeypot or rate-limiting middleware.

If you use Next.js output: "export" for cheap CDN hosting on Cloudflare Pages or S3, Route Handlers and Server Actions do not even run at runtime.

Copy-Paste Next.js Client Component (Zero Extra Packages)

Drop this TypeScript component into any Next.js App Router project. It submits FormData directly over HTTPS with loading and success states.

components/ContactForm.tsx
'use client';

import { useState } from 'react';

export function ContactForm() {
  const [status, setStatus] = useState<'idle' | 'sending' | 'sent' | 'error'>('idle');

  async function handleSubmit(e: React.FormEvent<HTMLFormElement>) {
    e.preventDefault();
    setStatus('sending');

    try {
      const res = await fetch('https://www.submitdrop.com/api/f/YOUR_FORM_ID', {
        method: 'POST',
        body: new FormData(e.currentTarget),
        headers: { Accept: 'application/json' },
      });

      if (!res.ok) throw new Error('Submission failed');
      setStatus('sent');
      e.currentTarget.reset();
    } catch {
      setStatus('error');
    }
  }

  return (
    <form onSubmit={handleSubmit} className="space-y-4 max-w-md">
      <input type="text" name="name" required placeholder="Your Name" className="w-full p-3 rounded-lg border" />
      <input type="email" name="email" required placeholder="you@company.com" className="w-full p-3 rounded-lg border" />
      <textarea name="message" required rows={4} placeholder="Project details..." className="w-full p-3 rounded-lg border" />
      <input type="text" name="_gotcha" className="hidden" tabIndex={-1} autoComplete="off" />

      <button type="submit" disabled={status === 'sending'} className="px-6 py-3 rounded-lg bg-black text-white font-semibold">
        {status === 'sending' ? 'Sending...' : 'Send Message'}
      </button>

      {status === 'sent' && <p className="text-emerald-600 text-sm">Thanks! We received your message.</p>}
      {status === 'error' && <p className="text-rose-600 text-sm">Could not send — please try again.</p>}
    </form>
  );
}

Frequently Asked Questions

Does fetch() work from localhost during Next.js development?

Yes. SubmitDrop sets Access-Control-Allow-Origin: * on /api/f/* so both http://localhost:3000 and production domains work immediately.

Try SubmitDrop Free on Your Site

3 active endpoints & 250 submissions/month free forever. Includes Resend emails, Slack/Discord webhooks, auto-replies, and honeypot spam filtering.

Get Free Endpoint

Related Tools & Resources

More Guides