Skip to content
FormToMail

Fix errors & stop spam

Form backend returns a CORS error. How do I fix it?

By the FormToMail team · Checked against official sources · Updated

A CORS error means the browser blocked your fetch() because the endpoint's response didn't include an `Access-Control-Allow-Origin` header for your site. Sending JSON (Content-Type: application/json) also triggers a preflight `OPTIONS` request the server must answer. Fix it by using an endpoint that answers CORS for your origin, or send FormData / URL-encoded data, which is a simple request with no preflight.

CORS is enforced by browsers only. The same request from curl, a server or a mobile app works, which is why "it works in Postman" doesn't prove the endpoint is fine for a website.

CORS error messages and what they mean
Console message (Chrome wording varies)CauseFix
No 'Access-Control-Allow-Origin' header is presentThe endpoint doesn't allow cross-origin callsUse an endpoint with CORS, or submit as a normal HTML form (no CORS involved)
Response to preflight request doesn't pass access control checkYour JSON/custom header triggered OPTIONS and the server didn't answer itSend FormData instead, or use an endpoint that answers OPTIONS
Request header field content-type is not allowedServer's Access-Control-Allow-Headers omits Content-TypeServer must list it; or send FormData
Redirect is not allowed for a preflight requestEndpoint redirects (e.g. http → https, missing slash)Use the exact https URL

Client-side fix: avoid the preflight

A POST with FormData or URLSearchParams and no custom headers is a "simple request" in the CORS spec. The browser still checks the response's Allow-Origin header, but it doesn't send an OPTIONS first.

js
fetch("https://getformtomail.com/f/YOUR_FORM_ID", { method: "POST", body: new FormData(form) });

Server-side fix (if you run the handler)

  • Answer OPTIONS with 204 and Access-Control-Allow-Origin, Access-Control-Allow-Methods: POST, OPTIONS, Access-Control-Allow-Headers: Content-Type.
  • Put Access-Control-Allow-Origin on the POST response too, including error responses.
  • Don't redirect preflights.

FormToMail and CORS

FormToMail's endpoint answers preflights and allows every origin, so fetch() with JSON or FormData works from any domain, including localhost and preview URLs.

Quick answers

Form backend returns cors error, how do i fix it?

Use an endpoint that sends Access-Control-Allow-Origin, or send FormData without custom headers to avoid the preflight.

Does a form backend work on an intranet or localhost?

Yes for sending: the browser calls the public endpoint from any page, and FormToMail allows all origins.

Why does it work in Postman but not in the browser?

CORS is only enforced by browsers.

Can I just add mode: 'no-cors'?

The request is sent, but you can't read the answer, so you won't know if it failed. Fix the headers instead.

What to do next

Use an endpoint with CORS already handled.

Get your form endpoint

Sources

Checked: . Prices, limits and features of other services change: confirm current values at the official links above. Product names belong to their owners; we are not affiliated with them.