← Back to Recipes

Email Notification Guide

Receive an email notification for every new form submission.

1. Get a Resend API Key

  1. Sign up for free at https://resend.com.
  2. Create an API key from the dashboard.
  3. Verify your sending domain (or use Resend's shared domain for testing).

2. Install Dependencies

npm install resend

3. Create a Notification Handler

Deploy this as a serverless function or Node.js endpoint. Your frontend posts here; the handler forwards to Peach Form and sends you an email.

// handler.js — deploy to Vercel, Netlify, or any Node.js server
import { Resend } from "resend";

const resend = new Resend(process.env.RESEND_API_KEY);

export default async function handler(req, res) {
  if (req.method !== "POST") {
    return res.status(405).end("Method not allowed");
  }

  const body = req.body; // parsed JSON

  // 1. Forward submission to Peach Form
  const pfRes = await fetch("https://api.peachform.com/f/YOUR_FORM_ID", {
    method: "POST",
    headers: { "Content-Type": "application/json" },
    body: JSON.stringify(body),
  });

  if (!pfRes.ok) {
    return res.status(502).json({ error: "Peach Form submission failed" });
  }

  // 2. Send email notification
  const html = Object.entries(body)
    .map(([k, v]) => `<p><strong>${k}:</strong> ${v}</p>`)
    .join("");

  await resend.emails.send({
    from: "[email protected]",
    to: "[email protected]",
    subject: "New form submission",
    html: `<h2>New submission</h2>${html}`,
  });

  return res.status(200).json({ success: true });
}

4. Set Environment Variables

RESEND_API_KEY=re_...

Expected Output

After a successful submission you will receive an email like this:

Subject: New form submission

New submission
name: Jane Doe
email: [email protected]
message: Hello!