D1, R2 & Resend · Free guide

Sending branded transactional receipts and lead confirmations with Resend and D1

When visitors submit an estimate inquiry or unlock a starter pack, record the validated payload inside Cloudflare D1 first, assign a reference ID, and trigger both an owner alert email and a clean confirmation receipt via Resend. Using server-side validation and HTML escaping ensures user input can never inject malicious scripts into emails.

By StaticLaunch · Four Media Group LLC

Always save to D1 before emailing externally

Network requests to external APIs can experience momentary timeouts. Writing the verified inquiry row to D1 first guarantees your customer request is safely recorded before email delivery runs.

Escape every user-submitted field inside HTML email bodies

Sanitize &, <, >, quotes, and strip header newlines from subjects or reply-to strings before passing HTML templates to Resend so spam payloads never corrupt layouts.

Example
const escapeHtml = (s) => String(s)
  .replace(/&/g, '&amp;')
  .replace(/</g, '&lt;')
  .replace(/>/g, '&gt;')
  .replace(/"/g, '&quot;');

Do not silently fail if an optional email worker isn't bound yet

Log non-fatal delivery metadata cleanly and design clear error feedback whenever neither D1 nor email forwarding succeeds so visitors never think a dropped submission went through.

Common questions

Should every confirmation email copy the full form message back to the sender?

Be conservative—for public forms, sending a concise confirmation ('Received reference #1234') avoids spammers abusing your site as a third-party message relay.

Can Resend track whether an inquiry alert bounced?

Yes. Resend exposes delivery webhooks and bounce logs cleanly on verified sending domains.

References

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