# DidMyFormSend > DidMyFormSend tells freelancers and small agencies when a contact form handler they or their coding agent wrote stops getting mail out. The handler reports every mail send (a heartbeat with what the mail provider answered), a signed test can push one test mail through the handler's real send path to our mailbox, and the owner gets an email when a send is refused, a test fails or fewer messages arrive than expected. An agent can set it up end to end: reserve a monitor without an account, get the code for the stack, and run the test. ## When to use it - You wrote or changed a contact form handler (the server code that emails the owner when a visitor submits a form) and want the owner told when its mail stops going out. - You want proof that a handler you just deployed gets mail out: run a signed test and read whether the mail left the handler, reached our mailbox, how long it took and what our receiver read (From domain, SPF, DKIM, DMARC). - What it shows: what the handler reports and what reaches our own mailbox. Where the usual recipient's copy lands is not something it can see. ## Prices - €2 per monitor a month for the first 10 monitors, €1 from the 11th, billed for at least 5 monitors (€10 a month). 14-day trial, card needed to start. - Monitors 1 to 10: €2 per monitor a month, or €20 a year. - Monitors 11 and up: €1 per monitor a month, or €10 a year. - Billed for at least 5 monitors: €10 a month, or €100 a year. - 5 monitors: €10 a month. - 12 monitors: €22 a month. - 40 monitors: €50 a month. - Trial: 14 days. A card is needed to start. No free plan. - Includes: A record of every mail send your handler reports: accepted or refused by your mail provider, or skipped by the handler itself. Daily counts and state changes are kept 400 days. - Includes: An email when your handler reports that the provider refused a send, or when fewer messages arrive than the minimum you set. - Includes: Signed tests: one request into your handler and a test mail to our mailbox, with the time it took and what our receiver read for SPF, DKIM and DMARC. - Includes: The REST API and an MCP server, so your own scripts or coding agent can create, change and pause monitors, run tests and read their history. - It does not buy a check of anyone's inbox or spam folder: we see what your handler reports to us, not where your client's copy of a message lands, and not whether a person read it. - How to pay: A person presses Activate on the claim_url that POST /api/v1/start returns, or Subscribe on the billing page, and adds a card in Stripe Checkout. The first charge comes after the 14-day trial. The card and the subscription are managed in Stripe's billing portal, linked from the billing page. - As JSON: GET https://didmyformsend.com/api/v1/pricing ## Start without an account For an agent with no API key. One request reserves a monitor; the site owner switches it on. 1. POST https://didmyformsend.com/api/v1/start with a JSON body. No auth. Fields: - name (required): What the owner calls this handler, e.g. "Contact form, client.nl". Shown on the Activate page and in alerts. - stack (required): Where the handler runs; picks the code you get. - handler_url: Optional: the https URL the form posts to. Checked and set on the monitor at activation. - client: Optional: the name of the agent or tool making this call, e.g. "Claude Code". Shown to the owner on the Activate page. 2. The 201 answer: {"ok": true, "data": {"id", "status", "claim_url", "setup_key", "heartbeat_key", "heartbeat_key_prefix", "test_secret", "expires_at"}, "code": the snippet and what to set, "pricing": the price list, "sign_up_open": false while new accounts cannot be created (then only an owner with an existing account can activate), "next": what to do now in plain words}. 3. Store data.heartbeat_key as the handler's secret DIDMYFORMSEND_HEARTBEAT_KEY and data.test_secret as DIDMYFORMSEND_TEST_SECRET right away: they are shown in that answer only. Deploy "code" (below for each stack). 4. Give the site owner data.claim_url. They log in or create an account, press Activate and add a card in Stripe Checkout. Until then the heartbeat endpoint answers 403 MONITOR_NOT_ACTIVE and stores nothing, so send the first message through the form after activation. The reservation lapses after 7 days. 5. Keep data.setup_key private. GET https://didmyformsend.com/api/v1/start/{id} with "Authorization: Bearer " returns status waiting_for_owner, waiting_for_payment or active. Once active, the same key works on the REST API and the MCP server for this one monitor only: it cannot see or change the account's other monitors. 6. A handler that crashes or stops receiving posts sends no heartbeat at all, so set an expected minimum after activation (expected_min_count with expected_min_days, through PATCH https://didmyformsend.com/api/v1/monitors/{id} or update_monitor): the owner is emailed when fewer sends than that arrive. Limit: 10 starts an hour from one address. ## The client-side rule Written into every snippet. Our endpoint can never break or slow the form: 1. Send the visitor's answer first. The heartbeat runs after the response where the platform allows it (Cloudflare Workers `ctx.waitUntil`, and the equivalent on Vercel, Netlify and Supabase), or with a hard timeout of 1,500 ms where it does not (PHP: after `fastcgi_finish_request()` if available, else `CURLOPT_TIMEOUT_MS` 1500). 2. Never retry inline. One attempt. 3. Never throw. The call sits in its own try/catch and its result is ignored. 4. Never change the visitor's response because of the heartbeat. 5. Never send a heartbeat for a signed test: the test reports its own result. The heartbeat key is a secret: the call runs in the handler on the server, never in the visitor's browser. ## The heartbeat Your form handler calls this once after each real mail send, with the monitor's heartbeat key as Authorization: Bearer and a JSON body of at most 1 KB. Report what the mail provider answered: result "sent" when it accepted the mail, "failed" when it refused it, "skipped" when your handler dropped a submission on purpose (its own spam check). Never send visitor data: unknown fields and any value holding an @ are refused with 422. A repeated event_id answers 200 with "duplicate": true and is stored once. A paused monitor answers 202 with "paused": true and stores nothing. Call it after the visitor has their answer, once, with a short timeout, and ignore the result. POST https://didmyformsend.com/api/v1/heartbeat with "Authorization: Bearer " and a JSON body: - result (required): What the mail provider did with the mail: sent (accepted), failed (refused), skipped (your handler dropped the submission on purpose; counted, but neither a message nor a failure). - provider: Which sender, e.g. resend, postmark, smtp. - provider_status: The provider's short status or error code, e.g. 200 or validation_error. Never its error sentence: that can hold an address. - http_status: The HTTP status the provider's API answered. - event_id: Idempotency key, e.g. the provider's message id. The same id twice is stored once. - occurred_at: When the send happened, in unix seconds. Used when it lies between 24 hours before and 5 minutes after our clock; otherwise our time is stored and the difference noted. ## Code per stack Each snippet below has the heartbeat call and the signed test check in it. add_monitor, POST /api/v1/start and GET /api/v1/monitors/{id}/code return the same code. ### Cloudflare Worker (stack "cloudflare_worker") File: worker.js Secrets: - RESEND_API_KEY: Your Resend API key. - TURNSTILE_SECRET: The secret key of your Turnstile widget. Needed only when the form uses Turnstile: without it the code refuses every visitor, unless you removed the Turnstile check as the setup says. - DIDMYFORMSEND_HEARTBEAT_KEY: This monitor's heartbeat key, shown once when the monitor was created or its key rotated. - DIDMYFORMSEND_TEST_SECRET: This monitor's test secret, shown once when the monitor was created or the secret rotated. Needed for signed tests only. Variables: - MAIL_FROM: The sender, on a domain you verified in Resend, for example "Website ". - OWNER_TO: The address that receives the enquiries. Setup: 1. The code is a complete form handler. It checks Cloudflare Turnstile and answers 400 "Bot check failed" to every submission without a valid Turnstile token, before any mail or heartbeat. 2. If your form has no Turnstile widget (for example it uses a honeypot field), delete the three lines from if (!test && !(await turnstileOk( to the closing brace after return new Response("Bot check failed", { status: 400 });, and the function turnstileOk. TURNSTILE_SECRET is then not needed. 3. If you already have a handler, keep it and copy in the constants HEARTBEAT_URL, TEST_DOMAIN and RESEND_URL and the functions monitorTest, setupProof, testReply, sendWithResend, safe, sendHeartbeat, checkMonitorTest, signatureMatches, sameBytes and base64Bytes. Call them in three places, as the code does: monitorTest first (return test.reply when it is set, and skip your bot check when test is set), sendWithResend for the mail (to the test address and answered with testReply when test is set), and sendHeartbeat in ctx.waitUntil after the visitor has their answer. 4. Save the code as your Worker's script (for example src/worker.js) and deploy it with npx wrangler deploy. 5. Set each secret with npx wrangler secret put , and the two variables under [vars] in wrangler.toml or in the Cloudflare dashboard. 6. Point your HTML form's action at the Worker's URL, method POST. 7. The form posts the fields name, email and message, plus the cf-turnstile-response field the Turnstile widget adds. 8. Without DIDMYFORMSEND_HEARTBEAT_KEY the form still works and sends no reports. 9. Send one message through the form yourself. The monitor shows it as its first heartbeat. 10. For signed tests: set DIDMYFORMSEND_TEST_SECRET, save the Worker's URL as the monitor's handler address, and run the setup check. A test skips Turnstile and sends its mail only to the test address on didmyformsend.com. 11. If your site is behind Cloudflare with Bot Fight Mode on and a test is reported as challenged by Cloudflare, add an IP Access rule that allows 167.233.49.68 (action Allow, this website). A WAF custom rule does not skip Bot Fight Mode. ```javascript // Contact form handler for Cloudflare Workers. // It checks Turnstile, sends the message to you through Resend, answers the visitor, // and then reports the outcome of the send to your monitor. // // Secrets (set each with: npx wrangler secret put ): // RESEND_API_KEY your Resend API key // TURNSTILE_SECRET your Turnstile widget's secret key // DIDMYFORMSEND_HEARTBEAT_KEY your monitor's heartbeat key // DIDMYFORMSEND_TEST_SECRET your monitor's test secret (for signed tests) // Variables (wrangler.toml [vars] or the dashboard): // MAIL_FROM sender address on a domain you verified in Resend, for example "Website " // OWNER_TO the address that receives the enquiries // // The form posts the fields name, email and message, plus the Turnstile widget's // cf-turnstile-response field. // // The report never holds the visitor's data or any address: only whether Resend // accepted the mail, Resend's status or error code, and Resend's message id. // It is sent after the visitor has their answer, once, with a 3 second limit, and its // result is ignored. If the monitor is slow or down, the form works as before. // Without DIDMYFORMSEND_HEARTBEAT_KEY no report is sent. // // Signed tests: your monitor can send a signed test request to this handler. A request // that carries well-formed test headers (webhook-id, webhook-timestamp, webhook-signature) // is checked against DIDMYFORMSEND_TEST_SECRET and never treated as a visitor. A valid test // skips the Turnstile check, runs the same reading, checks and Resend send as a visitor // does, but sends the mail only to the test address t-@didmyformsend.com (built // here from the signed test id, never read from the request), sends no heartbeat, and // answers with Resend's result. A wrong signature answers 401 and a test sent more than // 5 minutes from this server's clock answers 400; neither sends anything. const HEARTBEAT_URL = "https://didmyformsend.com/api/v1/heartbeat"; const TEST_DOMAIN = "didmyformsend.com"; const RESEND_URL = "https://api.resend.com/emails"; const TURNSTILE_URL = "https://challenges.cloudflare.com/turnstile/v0/siteverify"; export default { async fetch(request, env, ctx) { if (request.method !== "POST") { return new Response("Method not allowed", { status: 405, headers: { allow: "POST" } }); } // Only a request with the test headers is checked as a test; a visitor's never is. const test = request.headers.has("webhook-id") ? await monitorTest(request.clone(), env) : null; if (test && test.reply) return test.reply; let form; try { form = await request.formData(); } catch { if (test) return testReply(400, { id: test.id, error: "form_refused" }); return new Response("Could not read the form", { status: 400 }); } const field = (name, max) => String(form.get(name) ?? "").trim().slice(0, max); const name = field("name", 200); const email = field("email", 254); const message = field("message", 10000); if (!test && !(await turnstileOk(field("cf-turnstile-response", 2048), request, env))) { return new Response("Bot check failed", { status: 400 }); } if (!message) { if (test) return testReply(400, { id: test.id, error: "form_refused" }); return new Response("Please write a message", { status: 400 }); } const mail = { from: env.MAIL_FROM, // Always from your settings, never from the form. A test goes to the test address only. to: [test ? `t-${test.id}@${TEST_DOMAIN}` : env.OWNER_TO], subject: name ? `New enquiry from ${name.replace(/\s+/g, " ")}` : "New enquiry", text: `Name: ${name}\nEmail: ${email}\n\n${message}`, }; if (/^[^\s@<>,;"]+@[^\s@<>,;"]+\.[^\s@<>,;"]+$/.test(email)) mail.reply_to = email; const report = await sendWithResend(env.RESEND_API_KEY, mail); if (test) { // A test reports its own result and sends no heartbeat. return testReply(200, { id: test.id, result: report.result, provider: report.provider, provider_status: report.provider_status, provider_message_id: report.event_id, }); } const key = env.DIDMYFORMSEND_HEARTBEAT_KEY; if (typeof key === "string" && key !== "") { try { ctx.waitUntil(sendHeartbeat(key, report)); } catch { // The report is optional: never let it change the visitor's answer. } } // Real submissions only from here on: CRM, sheets, autoresponders. return report.result === "sent" ? new Response("Thanks, your message was sent.", { status: 200 }) : new Response("Sorry, your message could not be sent. Please try again later.", { status: 502 }); }, }; // Checks a request that carries the test headers. Returns { id } for a valid test, // { reply } with the answer to send at once (setup check, wrong signature, clock off), // or null when the headers are not a well-formed test (then it is handled as a visitor). async function monitorTest(request, env) { const secret = env.DIDMYFORMSEND_TEST_SECRET; const raw = await request.text(); // the signature covers these exact bytes const check = await checkMonitorTest(request.headers, raw, typeof secret === "string" ? secret : []); if (check === null) return null; // the headers are not a test's: the normal path runs, bot check included if (!check.ok && check.error === "clock_skew") { return { reply: testReply(400, { id: check.id, error: "clock_skew", handler_time: check.handler_time }) }; } if (!check.ok) return { reply: testReply(401, { error: "bad_signature" }) }; let body = null; try { body = JSON.parse(raw); } catch { // A test posts the form fields; only the setup check posts JSON. } if (body && typeof body === "object" && "monitor_handshake" in body) { return { reply: testReply(200, { id: check.id, handshake: "ok", proof: await setupProof(secret, check.id) }) }; } return { id: check.id }; } // The setup check's proof: base64 HMAC-SHA256 of "proof." with the test secret. async function setupProof(secret, id) { const bytes = Uint8Array.from(atob(String(secret).replace(/^whsec_/, "")), (c) => c.charCodeAt(0)); const key = await crypto.subtle.importKey("raw", bytes, { name: "HMAC", hash: "SHA-256" }, false, ["sign"]); const sig = new Uint8Array(await crypto.subtle.sign("HMAC", key, new TextEncoder().encode(`proof.${id}`))); return btoa(String.fromCharCode(...sig)); } function testReply(status, fields) { const body = { monitor_test: "v1" }; for (const [k, v] of Object.entries(fields)) if (v !== undefined && v !== null) body[k] = v; return new Response(JSON.stringify(body), { status, headers: { "content-type": "application/json" } }); } async function turnstileOk(token, request, env) { if (!token || !env.TURNSTILE_SECRET) return false; try { const res = await fetch(TURNSTILE_URL, { method: "POST", body: new URLSearchParams({ secret: env.TURNSTILE_SECRET, response: token, remoteip: request.headers.get("cf-connecting-ip") ?? "", }), }); const out = await res.json(); return out.success === true; } catch { return false; } } // Sends the mail and returns the report: Resend's real answer, read from its body. async function sendWithResend(apiKey, mail) { const report = { result: "failed", provider: "resend", occurred_at: Math.floor(Date.now() / 1000) }; let res; try { res = await fetch(RESEND_URL, { method: "POST", headers: { authorization: `Bearer ${apiKey}`, "content-type": "application/json" }, body: JSON.stringify(mail), signal: AbortSignal.timeout(10000), }); } catch (err) { report.provider_status = err && err.name === "TimeoutError" ? "timeout" : "network_error"; return report; } report.http_status = res.status; let body = null; try { body = await res.json(); } catch { report.provider_status = "non_json_response"; return report; } const ok = res.ok && body && typeof body.id === "string" && body.id !== "" && !body.error; if (ok) { report.result = "sent"; report.provider_status = String(res.status); const id = safe(body.id, /^[A-Za-z0-9_-]{1,64}$/); if (id) report.event_id = id; return report; } // Only Resend's short error code goes in the report, never its error sentence. const code = body && (body.name ?? (body.error && body.error.name)); report.provider_status = safe(code, /^[A-Za-z0-9_.:-]{1,64}$/) ?? (res.ok ? "no_message_id" : "unknown_error"); return report; } function safe(value, pattern) { return typeof value === "string" && pattern.test(value) ? value : undefined; } async function sendHeartbeat(key, report) { try { await fetch(HEARTBEAT_URL, { method: "POST", headers: { authorization: `Bearer ${key}`, "content-type": "application/json" }, body: JSON.stringify(report), signal: AbortSignal.timeout(3000), }); } catch { // Ignored on purpose: one attempt, no retry. } } // ---- The signed test check (the same code as the monitor's reference verifier) ---- // Checks the signed test request your form monitor sends to this handler. // Each handler snippet carries a copy of this code, pasted in when the code is shown. // // Format: Standard Webhooks (https://www.standardwebhooks.com), symmetric "v1": // webhook-id the test id: 24 characters, a to z and 2 to 7 // webhook-timestamp unix seconds when the test was sent // webhook-signature one or more "v1," separated by spaces // (two while a secret is being rotated, one per secret) // The signature covers "..", keyed with the bytes of your // test secret ("whsec_" followed by base64). Read the raw body before parsing the form: // the signature covers those exact bytes. // // Plain Web Crypto, no dependency: Cloudflare Workers, Deno, Supabase, Vercel Edge, Node 20+. // // checkMonitorTest(request.headers, rawBody, secret) returns: // null not a test: run your normal path, bot check included // { ok: true, id } a valid test // { ok: false, id, error: "clock_skew", handler_time } sent more than 5 minutes from your clock: answer 400, send nothing // { ok: false, id, error: "bad_signature" } no signature matches your secret: answer 401, send nothing // secret may be one secret or a list of them. const TEST_ID = /^[a-z2-7]{24}$/; const TIMESTAMP = /^[1-9][0-9]{0,11}$/; const TOLERANCE_SECONDS = 300; async function checkMonitorTest(headers, rawBody, secret, now = Math.floor(Date.now() / 1000)) { const id = headers.get("webhook-id"); const timestamp = headers.get("webhook-timestamp"); const signature = headers.get("webhook-signature"); if (!id || !TEST_ID.test(id) || !timestamp || !TIMESTAMP.test(timestamp) || !signature) return null; if (Math.abs(now - Number(timestamp)) > TOLERANCE_SECONDS) { return { ok: false, id, error: "clock_skew", handler_time: now }; } if (await signatureMatches(secret, id, timestamp, rawBody, signature)) return { ok: true, id }; return { ok: false, id, error: "bad_signature" }; } // True when at least one "v1," signature in the header matches one of the secrets. // Checks no id format and no time: checkMonitorTest does that. async function signatureMatches(secret, id, timestamp, rawBody, signatureHeader) { const given = String(signatureHeader ?? "").split(" ") .filter((s) => s.startsWith("v1,")) .map((s) => base64Bytes(s.slice(3))) .filter((b) => b !== null && b.length === 32); if (given.length === 0) return false; const data = new TextEncoder().encode(`${id}.${timestamp}.${rawBody}`); let match = false; for (const s of [].concat(secret)) { const keyBytes = typeof s === "string" ? base64Bytes(s.startsWith("whsec_") ? s.slice(6) : s) : null; if (!keyBytes || keyBytes.length === 0) continue; const key = await crypto.subtle.importKey("raw", keyBytes, { name: "HMAC", hash: "SHA-256" }, false, ["sign"]); const want = new Uint8Array(await crypto.subtle.sign("HMAC", key, data)); for (const sig of given) if (sameBytes(want, sig)) match = true; } return match; } // Constant time for equal lengths: every byte is compared, whatever the first difference. function sameBytes(a, b) { if (a.length !== b.length) return false; let diff = 0; for (let i = 0; i < a.length; i++) diff |= a[i] ^ b[i]; return diff === 0; } function base64Bytes(text) { if (text.length === 0 || text.length % 4 !== 0 || !/^[A-Za-z0-9+/]+={0,2}$/.test(text)) return null; try { return Uint8Array.from(atob(text), (c) => c.charCodeAt(0)); } catch { return null; } } ``` ### Supabase Edge Function (stack "supabase") File: supabase/functions/contact/index.js Secrets: - RESEND_API_KEY: Your Resend API key. - TURNSTILE_SECRET: The secret key of your Turnstile widget. Needed only when the form uses Turnstile: without it the code refuses every visitor, unless you removed the Turnstile check as the setup says. - DIDMYFORMSEND_HEARTBEAT_KEY: This monitor's heartbeat key, shown once when the monitor was created or its key rotated. - DIDMYFORMSEND_TEST_SECRET: This monitor's test secret, shown once when the monitor was created or the secret rotated. Needed for signed tests only. Variables: - MAIL_FROM: The sender, on a domain you verified in Resend, for example "Website ". Set it with supabase secrets set like the secrets. - OWNER_TO: The address that receives the enquiries. Set it with supabase secrets set like the secrets. Setup: 1. The code is a complete form handler. It checks Cloudflare Turnstile and answers 400 "Bot check failed" to every submission without a valid Turnstile token, before any mail or heartbeat. 2. If your form has no Turnstile widget (for example it uses a honeypot field), delete the three lines from if (!test && !(await turnstileOk( to the closing brace after return text("Bot check failed", 400);, and the function turnstileOk. TURNSTILE_SECRET is then not needed. 3. If you already have a handler, keep it and copy in the constants HEARTBEAT_URL, TEST_DOMAIN, RESEND_URL, CORS and env and the functions monitorTest, setupProof, testReply, sendWithResend, safe, sendHeartbeat, checkMonitorTest, signatureMatches, sameBytes and base64Bytes. Call them in three places, as the code does: monitorTest first (return test.reply when it is set, and skip your bot check when test is set), sendWithResend for the mail (to the test address and answered with testReply when test is set), and sendHeartbeat in EdgeRuntime.waitUntil after the visitor has their answer. 4. Save the code as supabase/functions/contact/index.js in your Supabase project. 5. In supabase/config.toml add a [functions.contact] section with verify_jwt = false and entrypoint = "./functions/contact/index.js". Without verify_jwt = false Supabase turns away your form and our tests before the code runs, because neither sends a Supabase key. 6. Set each secret and both variables with supabase secrets set NAME=value, or all at once from a file with supabase secrets set --env-file . 7. Deploy it with supabase functions deploy contact. The function's URL is https://.supabase.co/functions/v1/contact. 8. Point your form at that URL, method POST: an HTML form's action, a fetch call, or supabase.functions.invoke("contact", { body }). The function sends the CORS headers a browser needs to call it from your site's pages. 9. The form sends the fields name, email and message, plus the cf-turnstile-response field the Turnstile widget adds. 10. Without DIDMYFORMSEND_HEARTBEAT_KEY the form still works and sends no reports. 11. Send one message through the form yourself. The monitor shows it as its first heartbeat. 12. For signed tests: set DIDMYFORMSEND_TEST_SECRET, save the function's URL as the monitor's handler address, and run the setup check. A test skips Turnstile and sends its mail only to the test address on didmyformsend.com. 13. Trying it locally with supabase functions serve: set policy = "per_worker" under [edge_runtime] in supabase/config.toml, or the local server stops the function as soon as it answers and the heartbeat never leaves. ```javascript // Contact form handler for Supabase Edge Functions. // It checks Turnstile, sends the message to you through Resend, answers the visitor, // and then reports the outcome of the send to your monitor. // // Save it as supabase/functions/contact/index.js and add this to supabase/config.toml: // [functions.contact] // verify_jwt = false // entrypoint = "./functions/contact/index.js" // verify_jwt = false lets a plain HTML form and the monitor's signed test reach the // function without a Supabase key. Turnstile guards visitors, the signature guards tests. // // Secrets (set each with: supabase secrets set NAME=value): // RESEND_API_KEY your Resend API key // TURNSTILE_SECRET your Turnstile widget's secret key // DIDMYFORMSEND_HEARTBEAT_KEY your monitor's heartbeat key // DIDMYFORMSEND_TEST_SECRET your monitor's test secret (for signed tests) // MAIL_FROM sender address on a domain you verified in Resend, for example "Website " // OWNER_TO the address that receives the enquiries // // The form sends the fields name, email and message, plus the Turnstile widget's // cf-turnstile-response field, as a normal form post or as JSON (supabase.functions.invoke // sends JSON). Calls from a browser page on another origin get the CORS headers they need. // // The report never holds the visitor's data or any address: only whether Resend // accepted the mail, Resend's status or error code, and Resend's message id. // It is sent after the visitor has their answer, once, with a 3 second limit, and its // result is ignored. EdgeRuntime.waitUntil keeps the function running until it settles. // If the monitor is slow or down, the form works as before. // Without DIDMYFORMSEND_HEARTBEAT_KEY no report is sent. // // Signed tests: your monitor can send a signed test request to this handler. A request // that carries well-formed test headers (webhook-id, webhook-timestamp, webhook-signature) // is checked against DIDMYFORMSEND_TEST_SECRET and never treated as a visitor. A valid test // skips the Turnstile check, runs the same reading, checks and Resend send as a visitor // does, but sends the mail only to the test address t-@didmyformsend.com (built // here from the signed test id, never read from the request), sends no heartbeat, and // answers with Resend's result. A wrong signature answers 401 and a test sent more than // 5 minutes from this server's clock answers 400; neither sends anything. const HEARTBEAT_URL = "https://didmyformsend.com/api/v1/heartbeat"; const TEST_DOMAIN = "didmyformsend.com"; const RESEND_URL = "https://api.resend.com/emails"; const TURNSTILE_URL = "https://challenges.cloudflare.com/turnstile/v0/siteverify"; // The headers supabase.functions.invoke may send, as Supabase's CORS guide lists them. const CORS = { "access-control-allow-origin": "*", "access-control-allow-methods": "POST, OPTIONS", "access-control-allow-headers": "authorization, x-client-info, apikey, content-type, x-retry-count, traceparent, tracestate, baggage", }; const env = (name) => Deno.env.get(name); Deno.serve(async (request) => { if (request.method === "OPTIONS") return new Response("ok", { headers: CORS }); if (request.method !== "POST") { return text("Method not allowed", 405, { allow: "POST, OPTIONS" }); } // Only a request with the test headers is checked as a test; a visitor's never is. const test = request.headers.has("webhook-id") ? await monitorTest(request.clone()) : null; if (test && test.reply) return test.reply; let get; try { get = await readFields(request); } catch { if (test) return testReply(400, { id: test.id, error: "form_refused" }); return text("Could not read the form", 400); } const field = (name, max) => { const value = get(name); return (typeof value === "string" || typeof value === "number" ? String(value) : "").trim().slice(0, max); }; const name = field("name", 200); const email = field("email", 254); const message = field("message", 10000); if (!test && !(await turnstileOk(field("cf-turnstile-response", 2048), request))) { return text("Bot check failed", 400); } if (!message) { if (test) return testReply(400, { id: test.id, error: "form_refused" }); return text("Please write a message", 400); } const mail = { from: env("MAIL_FROM"), // Always from your settings, never from the form. A test goes to the test address only. to: [test ? `t-${test.id}@${TEST_DOMAIN}` : env("OWNER_TO")], subject: name ? `New enquiry from ${name.replace(/\s+/g, " ")}` : "New enquiry", text: `Name: ${name}\nEmail: ${email}\n\n${message}`, }; if (/^[^\s@<>,;"]+@[^\s@<>,;"]+\.[^\s@<>,;"]+$/.test(email)) mail.reply_to = email; const report = await sendWithResend(env("RESEND_API_KEY"), mail); if (test) { // A test reports its own result and sends no heartbeat. return testReply(200, { id: test.id, result: report.result, provider: report.provider, provider_status: report.provider_status, provider_message_id: report.event_id, }); } const key = env("DIDMYFORMSEND_HEARTBEAT_KEY"); if (typeof key === "string" && key !== "") { try { const pending = sendHeartbeat(key, report); // Supabase keeps the function running until this settles; the visitor is not kept waiting. if (typeof EdgeRuntime !== "undefined") EdgeRuntime.waitUntil(pending); } catch { // The report is optional: never let it change the visitor's answer. } } // Real submissions only from here on: CRM, sheets, autoresponders. return report.result === "sent" ? text("Thanks, your message was sent.", 200) : text("Sorry, your message could not be sent. Please try again later.", 502); }); function text(body, status, headers = {}) { return new Response(body, { status, headers: { ...CORS, ...headers } }); } // A form post (urlencoded or multipart) or a JSON object. Returns a getter for one field. async function readFields(request) { if (/^application\/json\b/i.test(request.headers.get("content-type") ?? "")) { const body = await request.json(); if (!body || typeof body !== "object" || Array.isArray(body)) throw new Error("not an object"); return (name) => body[name]; } const form = await request.formData(); return (name) => form.get(name); } // Checks a request that carries the test headers. Returns { id } for a valid test, // { reply } with the answer to send at once (setup check, wrong signature, clock off), // or null when the headers are not a well-formed test (then it is handled as a visitor). async function monitorTest(request) { const secret = env("DIDMYFORMSEND_TEST_SECRET"); const raw = await request.text(); // the signature covers these exact bytes const check = await checkMonitorTest(request.headers, raw, typeof secret === "string" ? secret : []); if (check === null) return null; // the headers are not a test's: the normal path runs, bot check included if (!check.ok && check.error === "clock_skew") { return { reply: testReply(400, { id: check.id, error: "clock_skew", handler_time: check.handler_time }) }; } if (!check.ok) return { reply: testReply(401, { error: "bad_signature" }) }; let body = null; try { body = JSON.parse(raw); } catch { // A test posts the form fields; only the setup check posts JSON. } if (body && typeof body === "object" && "monitor_handshake" in body) { return { reply: testReply(200, { id: check.id, handshake: "ok", proof: await setupProof(secret, check.id) }) }; } return { id: check.id }; } // The setup check's proof: base64 HMAC-SHA256 of "proof." with the test secret. async function setupProof(secret, id) { const bytes = Uint8Array.from(atob(String(secret).replace(/^whsec_/, "")), (c) => c.charCodeAt(0)); const key = await crypto.subtle.importKey("raw", bytes, { name: "HMAC", hash: "SHA-256" }, false, ["sign"]); const sig = new Uint8Array(await crypto.subtle.sign("HMAC", key, new TextEncoder().encode(`proof.${id}`))); return btoa(String.fromCharCode(...sig)); } function testReply(status, fields) { const body = { monitor_test: "v1" }; for (const [k, v] of Object.entries(fields)) if (v !== undefined && v !== null) body[k] = v; return new Response(JSON.stringify(body), { status, headers: { ...CORS, "content-type": "application/json" } }); } async function turnstileOk(token, request) { const secret = env("TURNSTILE_SECRET"); if (!token || !secret) return false; try { const res = await fetch(TURNSTILE_URL, { method: "POST", body: new URLSearchParams({ secret, response: token, remoteip: (request.headers.get("x-forwarded-for") ?? "").split(",")[0].trim(), }), }); const out = await res.json(); return out.success === true; } catch { return false; } } // Sends the mail and returns the report: Resend's real answer, read from its body. async function sendWithResend(apiKey, mail) { const report = { result: "failed", provider: "resend", occurred_at: Math.floor(Date.now() / 1000) }; let res; try { res = await fetch(RESEND_URL, { method: "POST", headers: { authorization: `Bearer ${apiKey}`, "content-type": "application/json" }, body: JSON.stringify(mail), signal: AbortSignal.timeout(10000), }); } catch (err) { report.provider_status = err && err.name === "TimeoutError" ? "timeout" : "network_error"; return report; } report.http_status = res.status; let body = null; try { body = await res.json(); } catch { report.provider_status = "non_json_response"; return report; } const ok = res.ok && body && typeof body.id === "string" && body.id !== "" && !body.error; if (ok) { report.result = "sent"; report.provider_status = String(res.status); const id = safe(body.id, /^[A-Za-z0-9_-]{1,64}$/); if (id) report.event_id = id; return report; } // Only Resend's short error code goes in the report, never its error sentence. const code = body && (body.name ?? (body.error && body.error.name)); report.provider_status = safe(code, /^[A-Za-z0-9_.:-]{1,64}$/) ?? (res.ok ? "no_message_id" : "unknown_error"); return report; } function safe(value, pattern) { return typeof value === "string" && pattern.test(value) ? value : undefined; } async function sendHeartbeat(key, report) { try { await fetch(HEARTBEAT_URL, { method: "POST", headers: { authorization: `Bearer ${key}`, "content-type": "application/json" }, body: JSON.stringify(report), signal: AbortSignal.timeout(3000), }); } catch { // Ignored on purpose: one attempt, no retry. } } // ---- The signed test check (the same code as the monitor's reference verifier) ---- // Checks the signed test request your form monitor sends to this handler. // Each handler snippet carries a copy of this code, pasted in when the code is shown. // // Format: Standard Webhooks (https://www.standardwebhooks.com), symmetric "v1": // webhook-id the test id: 24 characters, a to z and 2 to 7 // webhook-timestamp unix seconds when the test was sent // webhook-signature one or more "v1," separated by spaces // (two while a secret is being rotated, one per secret) // The signature covers "..", keyed with the bytes of your // test secret ("whsec_" followed by base64). Read the raw body before parsing the form: // the signature covers those exact bytes. // // Plain Web Crypto, no dependency: Cloudflare Workers, Deno, Supabase, Vercel Edge, Node 20+. // // checkMonitorTest(request.headers, rawBody, secret) returns: // null not a test: run your normal path, bot check included // { ok: true, id } a valid test // { ok: false, id, error: "clock_skew", handler_time } sent more than 5 minutes from your clock: answer 400, send nothing // { ok: false, id, error: "bad_signature" } no signature matches your secret: answer 401, send nothing // secret may be one secret or a list of them. const TEST_ID = /^[a-z2-7]{24}$/; const TIMESTAMP = /^[1-9][0-9]{0,11}$/; const TOLERANCE_SECONDS = 300; async function checkMonitorTest(headers, rawBody, secret, now = Math.floor(Date.now() / 1000)) { const id = headers.get("webhook-id"); const timestamp = headers.get("webhook-timestamp"); const signature = headers.get("webhook-signature"); if (!id || !TEST_ID.test(id) || !timestamp || !TIMESTAMP.test(timestamp) || !signature) return null; if (Math.abs(now - Number(timestamp)) > TOLERANCE_SECONDS) { return { ok: false, id, error: "clock_skew", handler_time: now }; } if (await signatureMatches(secret, id, timestamp, rawBody, signature)) return { ok: true, id }; return { ok: false, id, error: "bad_signature" }; } // True when at least one "v1," signature in the header matches one of the secrets. // Checks no id format and no time: checkMonitorTest does that. async function signatureMatches(secret, id, timestamp, rawBody, signatureHeader) { const given = String(signatureHeader ?? "").split(" ") .filter((s) => s.startsWith("v1,")) .map((s) => base64Bytes(s.slice(3))) .filter((b) => b !== null && b.length === 32); if (given.length === 0) return false; const data = new TextEncoder().encode(`${id}.${timestamp}.${rawBody}`); let match = false; for (const s of [].concat(secret)) { const keyBytes = typeof s === "string" ? base64Bytes(s.startsWith("whsec_") ? s.slice(6) : s) : null; if (!keyBytes || keyBytes.length === 0) continue; const key = await crypto.subtle.importKey("raw", keyBytes, { name: "HMAC", hash: "SHA-256" }, false, ["sign"]); const want = new Uint8Array(await crypto.subtle.sign("HMAC", key, data)); for (const sig of given) if (sameBytes(want, sig)) match = true; } return match; } // Constant time for equal lengths: every byte is compared, whatever the first difference. function sameBytes(a, b) { if (a.length !== b.length) return false; let diff = 0; for (let i = 0; i < a.length; i++) diff |= a[i] ^ b[i]; return diff === 0; } function base64Bytes(text) { if (text.length === 0 || text.length % 4 !== 0 || !/^[A-Za-z0-9+/]+={0,2}$/.test(text)) return null; try { return Uint8Array.from(atob(text), (c) => c.charCodeAt(0)); } catch { return null; } } ``` ## Signed tests - The setup check (kind "setup") proves the handler holds the test secret. No mail is sent. A test needs a passed setup check at the current handler_url. - A test (kind "manual") is one request signed with Standard Webhooks headers (webhook-id, webhook-timestamp, webhook-signature) made with the monitor's test secret. The handler skips its bot check, sends the mail through its real send path to t-@didmyformsend.com instead of its usual recipient, and answers with the provider's result. - Tests are sent from the IPv4 address 167.233.49.68. If the site is behind Cloudflare with Bot Fight Mode on and a test is reported as challenged by Cloudflare, add an IP Access rule that allows 167.233.49.68 (action Allow, this website). A WAF custom rule does not skip Bot Fight Mode. - A test passes when its mail reaches our mailbox within 15 minutes. This shows the mail left your handler and what our receiver saw; where your usual recipient's copy landed is not something the test can see. - When our own system was not processing while we were waiting for a test's mail, the test is not judged: status failed with failure_code receiver_outage. It does not count as a failed test, the monitor's state does not change, no alert is sent, and we send one new test in its place. - The handler must answer within 15 seconds; a failed request is tried once more after 10 minutes. - At most 10 tests and 3 setup checks an hour per monitor. ## States Every monitor has a health block: {"status", "state", "since", "message", "problems": [{"code", "message", "fix"}]}. status is ok, waiting, paused or attention. The state codes, most urgent first (a test's failure_code is one of these too, apart from receiver_outage above): - paused (status paused): Nothing is watched while the monitor is paused. Fix: Resume the monitor when you want it watched again. - send_failed (status attention, emails the owner): Your handler reported that the provider refused the email for a form submission, so that email was not sent. We never see the submission itself. Fix: Check the API key and the sending domain in your mail provider. The visitor's submission is wherever your handler stores it, if it stores it. - test_not_recognised (status attention, emails the owner): Tests cannot run. If your handler answered with a 2xx status, it may have sent one labelled test message to its usual recipient. Fix: Put the test check code back in your handler, deploy, and run the setup check again. - test_bad_signature (status attention, emails the owner): Tests cannot run: the handler does not accept the signature made with this monitor's test secret. Fix: Put this monitor's current test secret in the handler's DIDMYFORMSEND_TEST_SECRET (or rotate it and put in the new one), and deploy if your platform needs it. Then run a test. - test_clock_skew (status attention, emails the owner): Tests cannot run: a handler accepts a test only within 5 minutes of its own clock. Fix: Fix the server's time sync. Most hosts do this for you; on your own server, turn on NTP. - test_request_failed (status attention, emails the owner): The test did not get through to your handler, so nothing about its mail could be checked. Visitors may be getting the same error. Fix: Open the form and send a message yourself. Check your host's status and logs, and that the handler address is right. - test_mail_missing (status attention, emails the owner): Our receiver refuses mail that fails both SPF and DKIM, or fails your domain's DMARC policy, so a sending-domain setup problem is one possible cause; a provider delay is another, and so is a fault on our receiving side. We cannot see which. Fix: Look up the message id in your mail provider's logs, and check your domain's SPF and DKIM records. If both look right, run the test again. - below_minimum (status attention, emails the owner): The minimum you set was missed. That can mean the handler stopped sending, or that fewer people used the form. Fix: Send a message through the form yourself. If that works and the form is fine, lower the minimum. - auth_weak (status attention, emails the owner): The mail left your handler and reached our mailbox. Where your usual recipient's copy went is not something we can see. Fix: Add the DKIM record your mail provider gives you for your sending domain, and a DMARC record for it. - waiting_for_first_signal (status waiting): Not watching yet: no heartbeat has arrived from your handler. Fix: Deploy the code we gave you, then send one message through the form yourself. - healthy (status ok): The provider accepted the mail your handler sent. A heartbeat cannot show where the mail went after that. Fix: Nothing to do. ## MCP server https://didmyformsend.com/mcp (Streamable HTTP, POST). Authorization: Bearer : an API key from the dashboard, or the setup_key above once the owner activated the monitor. Claude Code: claude mcp add --transport http didmyformsend https://didmyformsend.com/mcp --header "Authorization: Bearer KEY" Tools: - add_monitor: Start watching one form handler: you get its heartbeat_key and test_secret (shown in this answer only) and the code for its stack, with the heartbeat call and the test check already in it. Once deployed, every mail send the handler reports is recorded, and the owner gets an email when the mail provider refuses a send or the expected minimum is missed. Needs a full API key: a setup key already has its one monitor. Each monitor adds to the owner's bill (GET https://didmyformsend.com/api/v1/pricing). - list_monitors: Every monitor this key reaches, newest first, each with its health block: status (ok, waiting, paused or attention), the state code, a message saying what was measured, and each current problem with its fix. Also the last heartbeat (what the mail provider answered), the last signed test and today's counts. With monitor_id, that one monitor. Add include to get more: "history" (daily counts and state changes, monitor_id needed), "activity" (every change, each with the id update_monitor can undo), "code" (the handler code for the stack, monitor_id needed) and "alert_addresses" (where alert emails go; full API keys only). Keys and secrets never appear here. - run_test: Proves the handler you wrote still gets mail out. Sends one signed request to the monitor's handler_url from 167.233.49.68; the handler sends the test mail through its real send path to our mailbox at didmyformsend.com instead of its usual recipient. The answer says whether the mail left the handler, whether it reached our mailbox within 15 minutes, how long it took, and what our receiver read (From domain, SPF, DKIM, DMARC). It cannot show where the usual recipient's copy lands. kind "setup" first: the setup check, no mail sent, needed once per handler_url. Then kind "manual" for a test. wait holds the answer up to 60 seconds for the result. With test_id: read that test, or cancel it with cancel true while it is not sent yet. At most 10 tests and 3 setup checks an hour per monitor. - update_monitor: One kind of change per call. Settings: name, stack, the expected minimum (expected_min_count and expected_min_days together; null for both turns it off), handler_url, or paused true or false (pausing never sends an alert). Every settings change answers with an activity_id; undo with that id puts the old values back. rotate "heartbeat" or "test" returns a new heartbeat key or test secret once, while the old one keeps working for a while so you can deploy first. add_alert_address sends alert emails to one more address once its owner confirms the link we email it; remove_alert_address stops that. Alert addresses count for every monitor on the account and need a full API key. Send monitor_id for settings and rotate. - remove_monitor: Stops watching a handler that is gone: send confirm with the monitor's exact name. It and its history can be brought back for 7 days with restore true; the answer says until when, then they are removed for good. The bill counts one monitor fewer. Ask the site owner first. Full API keys only. ## REST API Same keys as Authorization: Bearer . Index: https://didmyformsend.com/api. OpenAPI spec: https://didmyformsend.com/api/v1/openapi.json. Every error: {"ok": false, "errors": [{"code", "field", "message"}]}. - GET https://didmyformsend.com/api: List the API endpoints - GET https://didmyformsend.com/api/v1/openapi.json: Get the OpenAPI spec - POST https://didmyformsend.com/api/v1/heartbeat: Report one mail send - GET https://didmyformsend.com/api/v1/monitors: List your monitors - POST https://didmyformsend.com/api/v1/monitors: Create a monitor - GET https://didmyformsend.com/api/v1/monitors/{monitor}: Get one monitor - PATCH https://didmyformsend.com/api/v1/monitors/{monitor}: Change a monitor - DELETE https://didmyformsend.com/api/v1/monitors/{monitor}: Delete a monitor - POST https://didmyformsend.com/api/v1/monitors/{monitor}/restore: Restore a deleted monitor - POST https://didmyformsend.com/api/v1/monitors/{monitor}/keys/rotate: Replace the heartbeat key or the test secret - GET https://didmyformsend.com/api/v1/monitors/{monitor}/code: Get the handler code for a stack - GET https://didmyformsend.com/api/v1/monitors/{monitor}/history: Get a monitor's history - POST https://didmyformsend.com/api/v1/monitors/{monitor}/tests: Run a setup check or a signed test - GET https://didmyformsend.com/api/v1/monitors/{monitor}/tests/{test}: Read one test - DELETE https://didmyformsend.com/api/v1/monitors/{monitor}/tests/{test}: Cancel a test not sent yet - GET https://didmyformsend.com/api/v1/activity: List changes - POST https://didmyformsend.com/api/v1/activity/{activity}/undo: Undo a settings change - GET https://didmyformsend.com/api/v1/alert-targets: List alert addresses - POST https://didmyformsend.com/api/v1/alert-targets: Add an alert address - DELETE https://didmyformsend.com/api/v1/alert-targets/{target}: Remove an alert address - POST https://didmyformsend.com/api/v1/start: Reserve a monitor without an account - GET https://didmyformsend.com/api/v1/start/{claim}: Check whether the owner activated a reserved monitor - GET https://didmyformsend.com/api/v1/pricing: Get the price list ## Pages - Home: https://didmyformsend.com - Pricing: https://didmyformsend.com/pricing