Contact forms / SvelteKit
SvelteKit contact form without a mail server
One +page.svelte with a real HTML form. It posts without JavaScript, and shows the result in place once the page is hydrated.
Why SvelteKit needs a form backend
The usual SvelteKit contact form is a form action in +page.server.js that calls a mail provider. That needs a server adapter, an API key in a private environment variable, your own validation and your own spam checks, for a page that could be prerendered.
With Wrenform the form posts straight from the browser to your endpoint. There is no form action and no +server.js, so the route can use export const prerender = true and adapter-static. We store each submission, filter spam and email your recipients.
The prompt
Replace YOUR_FORM_ID with the ID of your form. The form keeps action and method, so it still posts as plain HTML before hydration or with JavaScript off; once hydrated, onsubmit sends it with fetch and shows the result in place.
<!-- src/routes/contact/+page.svelte (Svelte 5) -->
<script>
const endpoint = "https://wrenform.com/f/YOUR_FORM_ID";
let status = $state("idle");
async function onsubmit(e) {
e.preventDefault();
const form = e.currentTarget;
status = "sending";
try {
const res = await fetch(endpoint, {
method: "POST",
headers: { Accept: "application/json" },
body: new FormData(form),
});
status = res.ok ? "sent" : "error";
if (res.ok) form.reset();
} catch {
status = "error";
}
}
</script>
<form action={endpoint} method="POST" {onsubmit}>
<label>Name <input type="text" name="name" autocomplete="name" required /></label>
<label>Email <input type="email" name="email" autocomplete="email" required /></label>
<label>Message <textarea name="message" required></textarea></label>
<input type="text" name="_honey" style="display:none" tabindex="-1" autocomplete="off" />
<button type="submit" disabled={status === "sending"}>Send</button>
<p role="status">
{#if status === "sent"}Thanks, your message was sent.{/if}
{#if status === "error"}Something went wrong. Please try again.{/if}
</p>
</form>Steps
- Create a form (free) and copy its form ID. No account yet? Ask your AI tool to create a quick form with
framework: "svelte": one request returns your endpoint and a ready snippet. Click Confirm in the email from Wrenform, and messages start arriving. - Save the snippet as
src/routes/contact/+page.svelteand replaceYOUR_FORM_ID, or read it fromPUBLIC_WRENFORM_IDin$env/static/public. - Optional: add
export const prerender = trueinsrc/routes/contact/+page.js. - Build, deploy, and add your site to Allowed origins.
Spam handling
Spam filtering is on for every form, with no CAPTCHA: a hidden honeypot field, a timing check, rate limits per visitor, and a content score for links, keywords and gibberish. Spam goes to a separate tab and is never emailed. See how spam filtering works.
Without JavaScript the visitor lands on our thank-you page after sending. To bring them back to your site, set Redirect to in the form's settings, or add a hidden _redirect field with a full URL such as https://example.com/thanks. See redirects.
Deployment notes
- Netlify. Deploy as usual. Netlify only processes forms that carry its own
netlifyordata-netlifyattribute, so it leaves this form alone and the browser posts it to Wrenform. Add yournetlify.appaddress and your custom domain to Allowed origins. - Vercel. Nothing to configure. The SvelteKit build stays static; you don't need a serverless function for the form. Add your production domain to Allowed origins. Preview deployments get their own addresses, so leave the list empty while you test them, or add each one.
- Cloudflare Pages. No Pages Function needed. Add your
pages.devaddress and your custom domain to Allowed origins. If you set a Content-Security-Policy header, addform-action https://wrenform.com. - GitHub Pages. GitHub Pages serves static files only, which is all this form needs. Add
https://<user>.github.io(or your custom domain) to Allowed origins. The origin is the host only, without the repository path.
FAQ
Do I need a SvelteKit form action to send email?
Can I use use:enhance?
Does it work with adapter-static and prerendering?
Does it work on Svelte 4?
Does it work with npm run dev?
Next steps
- The full SvelteKit guide: every option, testing, and common problems.
- Contact form for Astro without a backend
- React contact form without a backend
- Pricing: free for 250 submissions a month.