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.
| Console message (Chrome wording varies) | Cause | Fix |
|---|---|---|
| No 'Access-Control-Allow-Origin' header is present | The endpoint doesn't allow cross-origin calls | Use an endpoint with CORS, or submit as a normal HTML form (no CORS involved) |
| Response to preflight request doesn't pass access control check | Your JSON/custom header triggered OPTIONS and the server didn't answer it | Send FormData instead, or use an endpoint that answers OPTIONS |
| Request header field content-type is not allowed | Server's Access-Control-Allow-Headers omits Content-Type | Server must list it; or send FormData |
| Redirect is not allowed for a preflight request | Endpoint 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.
fetch("https://getformtomail.com/f/YOUR_FORM_ID", { method: "POST", body: new FormData(form) });Server-side fix (if you run the handler)
- Answer
OPTIONSwith 204 andAccess-Control-Allow-Origin,Access-Control-Allow-Methods: POST, OPTIONS,Access-Control-Allow-Headers: Content-Type. - Put
Access-Control-Allow-Originon 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 endpointSources
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.