DEV Community

Cover image for Send HTML form to email without PHP: mailto breaks + and &
Vitalii Nemyrovskyi
Vitalii Nemyrovskyi

Posted on Fully Autonomous

Send HTML form to email without PHP: mailto breaks + and &

Your site has no PHP behind it. Maybe it's a page on GitHub Pages, Netlify or Cloudflare, or something you built in Lovable or Framer. There's a contact form on it, and you want whatever visitors type to land in your inbox. Search for how to do that and the same advice comes back again and again: a mailto form, a form service, EmailJS, or a Google Apps Script.

We wanted to see what each of those does when a real visitor uses it. On 26 November 2026 we ran them with Playwright 1.63.0 on Linux, in Chromium 153, Firefox 155 and WebKit 26.6 (the engine behind Safari). The one people copy most, mailto, quietly changes what the visitor wrote. The others can work once they're set up, though without accounts we could only test how they fail.

The short answer

To send an HTML form to email without PHP, point the form's action at something that sends the mail for you: a hosted form backend, a small serverless function that calls an email API, EmailJS, or a Google Apps Script. Each of them still runs on a server somewhere; you just don't write that server in PHP. The only route with no server at all is action="mailto:", and it doesn't send anything by itself. It hands the text to the visitor's mail app, if they have one, and in two of the three browsers it changes the text on the way.

The mailto form from the top answer

This is the form people copy from the Stack Overflow thread that sits first in Google for this question. One of its answers adds enctype="text/plain" so the email comes out readable.

<form action="mailto:owner@example.com" method="post" enctype="text/plain">
  <input name="name">
  <input name="email">
  <textarea name="message"></textarea>
  <button>Send</button>
</form>
Enter fullscreen mode Exit fullscreen mode

We filled it in the way a real visitor might. The name was Tom & Jerry, the address tom+site@example.com, and the message had two lines: Hi! Do you have 2 + 2 rooms? and Grüße, Zoë. Then we pressed Send in each browser, caught the mailto: URL it hands to the mail app, and decoded it the way RFC 6068 tells a mail app to.

Firefox kept every character:

name=Tom & Jerry
email=tom+site@example.com
message=Hi! Do you have 2 + 2 rooms?
Grüße, Zoë
Enter fullscreen mode Exit fullscreen mode

Chromium and WebKit handed over this:

name=Tom
 Jerry
email=tom site@example.com
message=Hi! Do you have 2   2 rooms?
Grüße, Zoë
Enter fullscreen mode Exit fullscreen mode

The ampersand turned into a line break, so the name is split across two lines. Every plus sign turned into a space, and that includes the one in the visitor's address. You'd reply to tom site@example.com, and the reply would go nowhere. RFC 6068 even warns about this case, because plus signs are a common way to tag an address. The German letters came out as mojibake: the browser read the UTF-8 bytes as if they were in the old Windows-1252 encoding.

The reason is in WebKit's source. The function that builds a mailto body (appendMailtoPostFormDataToURL in FormSubmission.cpp) has this comment on the text/plain branch: "Convention seems to be to decode, and s/&/\r\n/." That code treats the body as URL-encoded data. So it swaps every & for a line break and every + for a space, then decodes it. A text/plain body isn't URL-encoded, which means those swaps hit the characters your visitor typed. Chrome's engine started out as a fork of WebKit, and Chromium gave us the same three changes plus one extra blank line at the end.

Firefox does one more thing of its own. If your action has no subject, it adds one: Form Post from followed by the browser's short name, which in a normal install is "Form Post from Firefox". Our Playwright build is branded Nightly, so we got "Form Post from Nightly".

Without text/plain it's broken in all three

Drop the enctype and the browsers agree with each other, but the body is encoded one more time than a mail app decodes. The whole message lands on one line:

name=Tom+%26+Jerry&email=tom%2Bsite%40example.com&message=Hi%21+Do+you+have+2+%2B+2+rooms%3F%0D%0AGr%C3%BC%C3%9Fe%2C+Zo%C3%AB
Enter fullscreen mode Exit fullscreen mode

With method="get", the fields stop being the body. Each field becomes a header named after it, so the URL reads mailto:owner@example.com?name=Tom+%26+Jerry&email=...&message=.... Email has no name or message header, and RFC 6068 leaves it to the mail app whether to show unknown headers at all. You can rename the fields subject and body to get a real email out of it. All three browsers still write spaces as +, though, so our subject went out as Quote+request. RFC 6068 asks for %20 for exactly this reason, since a mail app can't tell a plus that means a space from a plus the visitor typed.

Our test box had no real mail apps. How Outlook, Apple Mail or Gmail show these drafts is outside what we measured.

With no mail app, the page still says thanks

Most mailto forms come with a few lines of JavaScript that show a thank-you message. We added the usual kind:

form.addEventListener("submit", () => {
  setTimeout(() => { msg.textContent = "Thanks! We got your message."; }, 0);
});
Enter fullscreen mode Exit fullscreen mode

The test machine had no mail app registered, which is also the case for anyone who reads email in a browser tab and never set a handler. In all three browsers, three seconds after the click, the page said "Thanks! We got your message." No error fired. Chromium and WebKit showed nothing else, and Chromium went as far as firing beforeunload and pagehide, as if the visitor had left the page. Firefox put its own box over the page, "Choose an application to open the mailto link", offering Gmail or another app, and the thank-you sat behind it. In Playwright's log, Chromium recorded the mailto request as aborted, WebKit recorded the request and nothing after it, and Firefox recorded nothing.

The page has no way to find out whether a mail app opened, or whether anyone pressed Send in it, so the thank-you shows up whether or not a draft was ever written.

If you keep mailto, build the link yourself

The text breaks at the moment the browser turns form fields into a mailto: URL, so you can take that job away from it. Stop the submit, join the fields into a body yourself, and encode the subject and body with encodeURIComponent. It writes a space as %20 and a plus as %2B, which is what RFC 6068 asks for. After that, the page should say only what it knows: a mail app ought to open, and if one didn't, here is the address.

<form id="contact">
  <label>Name <input name="name" required></label>
  <label>Email <input name="email" type="email" required></label>
  <label>Message <textarea name="message" rows="4" required></textarea></label>
  <button>Open in my mail app</button>
</form>
<p id="note" hidden>
  Your mail app should open with this message. Nothing is sent until you press Send there.
  If it didn't open, write to <b id="to">owner@example.com</b>
  <button type="button">Copy address</button>
</p>

<style>
  #contact { display: grid; gap: .75rem; max-width: 28rem; }
  #contact label { display: grid; gap: .25rem; }
  #contact :is(input, textarea, button), #note button { font: inherit; padding: .4rem .6rem; }
  #note { max-width: 28rem; padding: .75rem 1rem; border-left: 3px solid #2563eb; background: #eff6ff; }
</style>

<script>
  const form = document.querySelector("#contact");
  const note = document.querySelector("#note");
  const to = document.querySelector("#to").textContent;

  form.addEventListener("submit", (e) => {
    e.preventDefault();
    const data = new FormData(form);
    const subject = "Message from " + data.get("name");
    const body = [...data].map(([k, v]) => `${k}: ${v}`).join("\n").replace(/\r?\n/g, "\r\n");
    location.href = `mailto:${to}?subject=${encodeURIComponent(subject)}&body=${encodeURIComponent(body)}`;
    note.hidden = false; // no "thanks": the page can't see what happens next
  });

  note.querySelector("button").addEventListener("click", async (e) => {
    try {
      await navigator.clipboard.writeText(to);
      e.target.textContent = "Copied";
    } catch {
      getSelection().selectAllChildren(document.querySelector("#to"));
      e.target.textContent = "Selected. Press Ctrl+C or Cmd+C";
    }
  });
</script>
Enter fullscreen mode Exit fullscreen mode

We ran it with the same input as before, caught the URL the same way and decoded it by RFC 6068:

Browser Subject and body after decoding What the page showed with no mail app
Chromium 153 Every character as typed Our note, no thank-you
Firefox 155 Every character as typed (caught through a test webmail handler) Firefox's "Choose an application" box on top of our note; Copy worked after Escape closed it
WebKit 26.6 Every character as typed Our note, no thank-you

Swapping the location.href line for "?" + new URLSearchParams({ subject, body }) failed the same check in all three browsers, because it writes every space as +.

This version still can't tell whether the visitor pressed Send in their mail app, and for someone with no mail app it can't do more than show the address.

The other routes, and what a visitor sees when they fail

Every other route needs an account somewhere, and we didn't sign up for anything, so we couldn't test the success path. The failure path we could test with made-up IDs: an Apps Script URL that doesn't exist, the EmailJS browser SDK (@emailjs/browser 5.0.3) with a fake public key, and our own backend with a fake key. Same three browsers, same day.

Route What you set up What the visitor saw when it failed
mailto: form Nothing Our own "Thanks!" message, in all 3 browsers
Apps Script, plain form post A Google account, the script, a public deployment Google's "page not found" page on script.google.com
Apps Script, fetch with no-cors The same Our "Thanks!" again: the fetch resolved with status 0
EmailJS SDK An account, an email service, a template, a public key Nothing, unless your code shows the error (400, "The Public Key is invalid.")
Your own serverless function The function, an email API key in its secrets, DNS for the sending domain, a spam check Whatever your function returns (not tested)
Formgong (ours) A form key in a hidden field A page that says "The submission was not accepted"

On the plain form post, the visitor has left your site and is looking at a Google Drive error page.

The no-cors line that hides Apps Script errors

A normal fetch to the dead Apps Script URL failed in every browser, each with its own wording: Failed to fetch in Chromium, NetworkError when attempting to fetch resource. in Firefox, Load failed in WebKit. That's a CORS error, and the fix people pass around for it is mode: "no-cors".

With no-cors, the same request to the same dead URL resolved in all three browsers. The response was opaque with status 0. We also pointed it at a local server that answers every request with a 500, and got the same opaque response with status 0. An opaque response looks the same whether the script saved the row or doesn't exist, so a .then(showThanks) thanks the visitor either way.

That line is easy to find. We took the first 30 GitHub code search results for files that contain an Apps Script URL and no-cors, and all 30 really had both. One of them is a file called CORS_FIX.md that labels no-cors as the solution. A TROUBLESHOOTING.md in another repo tells you an empty response is normal and to go check your Google Sheet.

If you stay with Apps Script, drop no-cors so a failure at least shows up as an error you can handle. Whether your deployed script answers a normal fetch with the headers it needs is something to check on your own deployment; we couldn't without a Google account. Keep the quota in mind too. Google's quotas page (last updated 3 September 2026) allows 100 email recipients a day for a free Google account.

EmailJS behaved better. With the fake key, its API answered 400 with a CORS header, so the SDK's promise rejected with {"status":400,"text":"The Public Key is invalid. ..."} in all three browsers. Your code can read that and tell the visitor. If your submit handler has no error branch, though, the visitor sees nothing at all.

A hosted form backend

We make Formgong, a hosted form backend, so here's ours as one example of this route. You change the action and add a hidden key:

<form action="https://formgong.com/submit" method="POST">
  <input type="hidden" name="access_key" value="YOUR_FORM_KEY">
  <input type="hidden" name="_redirect" value="https://your-site.example/thanks/">
  <input type="text" name="botcheck" tabindex="-1" autocomplete="off" style="display:none">
  <input name="name" required>
  <input name="email" type="email" required>
  <textarea name="message" required></textarea>
  <button>Send</button>
</form>
Enter fullscreen mode Exit fullscreen mode

With our fake key, the plain form took the browser to a page that said "The submission was not accepted. That access key does not exist." A fetch with Accept: application/json got a 404 and {"success":false,"code":"unknown_access_key","message":"That access key does not exist."}, so a script can tell the visitor what went wrong instead of thanking them. With a real key, the message is kept in your inbox and sent to your email, and to Telegram if you connect it. The botcheck field catches simple bots. The same account also gives you site templates with the form already wired. The setup for a plain HTML page is on the Formgong site.

Test your own form with three strings

Whatever route you end up with, send one message from the live page with Tom & Jerry as the name, you+test@example.com as the address and Grüße in the message. Then compare what arrived with what you typed, character by character.

We had no real mail app in the test box, and that's the part we'd like help with. If you run the mailto form above on a machine where Outlook, Apple Mail or Gmail opens mailto links, what did the draft look like? Put it in the comments. And if you tried Formgong and something in it got in your way, we want to hear about that too.

Top comments (0)