← Back

A contact form that can't fail silently: Resend and React Email

27 November 2026 · 3 min read

A portfolio contact form has one job: a message from a real person reaches me. The failure that matters is the silent one, where the visitor sees “sent” and nothing arrives. So the form is built around never reporting success it can’t back up.

The request path

The form posts to /api/brief. The handler is a plain function that takes the parsed body and the client address and returns a status, so it can be tested without a server. It does four things in order:

  1. Honeypot. A hidden website field that humans never fill. If it has a value, the handler answers 200 and sends nothing, so bots get no signal that they were caught.
  2. Rate limit. Five requests per minute per client address, then a 429. Behind a reverse proxy the address is the proxy’s, so the server build only reads X-Forwarded-For when TRUST_PROXY=1 is set. Setting it when the app is reachable directly would let anyone forge the header.
  3. Validation. Every field is trimmed and checked, and the message is capped at 5,000 characters. Emoji and other unicode pass through untouched. Problems come back as a per-field error map.
  4. Send. If the Resend key is missing or the API call fails, the visitor gets an error with a mailto link, never a green tick.

A real email instead of a text dump

The first version sent the brief as plain text, and it read like a log line. It now renders a React Email template on the server: a branded header, labelled fields, and a “Reply to” button that appears when the contact is an email address. reply_to is set too, so pressing Reply in your mail client goes to the person who wrote in. A plain-text version is sent alongside the HTML for clients that prefer it.

The template is rendered with a dynamic import inside the send function, so none of the React code is pulled into a request that fails validation. A test checks that user input is HTML-escaped, because a brief containing <script> shouldn’t become markup in my inbox.

The Resend gotcha

Until you verify a domain, Resend only lets you send from onboarding@resend.dev, and only to the email address that owns the Resend account. Send to anyone else and it is refused. That is easy to mistake for a bug in your code. The fix is to verify your domain in Resend, add the DKIM, SPF and MX records it gives you at your DNS provider, and switch the from address to something on that domain.

Even with a verified domain, check the Resend log rather than guessing: it records “delivered” or the exact reason it wasn’t.

More posts Work with me