D1, R2 & Resend · Free guide

How to send contact form emails on a static site with Resend and Cloudflare Workers

Static HTML pages cannot hold private API keys or open SMTP sockets directly, so contact forms POST to a lightweight Cloudflare Pages Function or isolated Email Worker that validates Turnstile bot checks and calls Resend's HTTPS API server-side. Keep RESEND_API_KEY encrypted inside Cloudflare Worker secrets—never inside browser JavaScript.

By StaticLaunch · Four Media Group LLC

Why static forms need a small edge endpoint or external relay

Unlike WordPress plugins running on an origin PHP server, pure prebuilt HTML files have zero server runtime by default. Adding one lightweight Worker or third-party form endpoint bridges that gap cleanly without reviving database maintenance.

  • Browser submits JSON or FormData to /api/inquiry on your same domain.
  • Pages Function checks honeypot fields, validates inputs, and verifies Cloudflare Turnstile.
  • Serverless Worker sends POST https://api.resend.com/emails with your encrypted API token.

Use a dedicated Email Worker via Service Binding for strict key isolation

Rather than dropping email credentials directly onto public web environments, isolate your Resend key inside a private internal Worker bound to your Pages project via Service Binding + shared header token verification.

Example
await fetch('https://api.resend.com/emails', {
  method: 'POST',
  headers: {
    Authorization: `Bearer ${env.RESEND_API_KEY}`,
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    from: 'Website Inquiries <[email protected]>',
    to: ['[email protected]'],
    reply_to: cleanEmail,
    subject: `New inquiry from ${cleanName}`,
    text: messageBody,
  }),
});

Pair D1 storage as an instant safety net

Always insert validated submissions into Cloudflare D1 before dispatching Resend HTTP calls so even temporary mail bounces never silently drop a customer lead.

Common questions

Can I put my Resend API key in Astro client script if my site is static?

Never. Anything shipped to browser JavaScript or public assets can be copied cleanly out of DevTools. Always keep RESEND_API_KEY strictly inside Cloudflare Worker / Pages Function server environment secrets.

Is there a simpler zero-code alternative if I do not want Workers yet?

Yes. Services like Formspree or Basin give you an HTML form action URL immediately—while Workers + Resend scale cleanly when you want 100% custom validation inside your own Cloudflare account.

References

Provider interfaces and limits can change. Consult the original documentation before changing production settings.