🔥 All-Access Pass — $199 USD (Regular $499) · Unlock all 2,836 Astro themes ➔
komal.nakrani
Get All-Access Pass ($199)
ThemesCategoriesDocsBlogTips & TricksPricingGet All-Access Pass ($199)
Astro Themes••By Komal Nakrani

Make an Astro Theme Contact Form Actually Send

An Astro theme contact form is usually markup only. Connect it to a form service, Netlify Forms or an Astro Action so messages reach your inbox, minus spam.

#Astro#Astro Themes#Contact Form#Forms

An Astro theme contact form usually does nothing on submit, because static themes ship no server to receive it. To make it send, point the form’s action at a form service, turn on your host’s form handling (such as Netlify Forms), or add an adapter and handle the submission with an Astro Action that emails you.

Key Takeaways

  • Static output has no backend, so a form needs somewhere to post to.
  • A hosted form endpoint is the fastest fix: change action, keep the site static.
  • Netlify Forms works by adding one attribute, but only on Netlify.
  • Astro Actions give you full control, but need an adapter and on-demand rendering.
  • Every option needs field name attributes and some spam protection.

Check what the form does now

Open the contact component (search for <form):

# Terminal
grep -rn "<form" src/

A typical theme form looks like this:

---
// src/components/ContactForm.astro
---
<form action="#" method="post">
  <input type="text" placeholder="Name" />
  <input type="email" placeholder="Email" />
  <textarea placeholder="Message"></textarea>
  <button type="submit">Send</button>
</form>

Two problems: action="#" posts nowhere, and the fields have no name, so even a working endpoint would receive an empty submission. Fix the fields first in every option below: give each a name, a <label> and required where it applies.

Option 1: a hosted form endpoint

Form services give you a URL that accepts a POST and emails you the fields. Formspree, Web3Forms, Basin and similar services all work this way. Create a form in the service’s dashboard, copy its endpoint, and set it as the action:

---
// src/components/ContactForm.astro
const endpoint = import.meta.env.PUBLIC_FORM_ENDPOINT;
---
<form action={endpoint} method="post">
  <label for="name">Name</label>
  <input id="name" name="name" type="text" autocomplete="name" required />

  <label for="email">Email</label>
  <input id="email" name="email" type="email" autocomplete="email" required />

  <label for="message">Message</label>
  <textarea id="message" name="message" rows="6" required></textarea>

  <!-- Honeypot: real users never fill this -->
  <input type="text" name="_gotcha" tabindex="-1" autocomplete="off" hidden />

  <button type="submit">Send</button>
</form>

The endpoint is not a secret, but keeping it in .env as PUBLIC_FORM_ENDPOINT makes it easy to use a test form locally. Honeypot field names differ by service, so use the one your provider documents. The site stays fully static and deploys anywhere. Our form backends comparison covers the trade-offs between services.

Option 2: Netlify Forms

If you deploy on Netlify, add data-netlify="true" and a name to the form. Netlify detects the form in your built HTML and stores submissions in its dashboard, where you can turn on email notifications:

---
// src/components/ContactForm.astro
---
<form name="contact" method="post" action="/thanks/" data-netlify="true" netlify-honeypot="bot-field">
  <input type="hidden" name="form-name" value="contact" />
  <p hidden><label>Leave empty <input name="bot-field" /></label></p>
  <label for="email">Email</label>
  <input id="email" name="email" type="email" required />
  <label for="message">Message</label>
  <textarea id="message" name="message" required></textarea>
  <button type="submit">Send</button>
</form>

Create src/pages/thanks.astro for the redirect. This only works on Netlify, so moving hosts later means switching option. The Netlify deploy guide covers the rest of the setup.

Option 3: an Astro Action

For full control (your own email provider, a database, custom validation), handle the form on the server. That needs an adapter, because Actions run on demand:

# Terminal
npx astro add node

Then define the action:

// src/actions/index.ts
import { defineAction } from 'astro:actions';
import { z } from 'astro/zod';

export const server = {
  contact: defineAction({
    accept: 'form',
    input: z.object({
      name: z.string().min(1),
      email: z.email(),
      message: z.string().min(10),
    }),
    handler: async ({ name, email, message }) => {
      // Send with your email provider's SDK or API here.
      console.log('New message', { name, email, message });
      return { ok: true };
    },
  }),
};

And point the form at it from an on-demand page:

---
// src/pages/contact.astro
import { actions } from 'astro:actions';
export const prerender = false;
const result = Astro.getActionResult(actions.contact);
---
<form method="POST" action={actions.contact}>
  <input name="name" required />
  <input name="email" type="email" required />
  <textarea name="message" required></textarea>
  <button>Send</button>
</form>
{result?.data?.ok && <p role="status">Thanks, we will reply soon.</p>}

The rest of the site stays prerendered; only /contact/ runs on the server. Without an adapter the build stops with “Actions must be used with server output.” The full API is in our Astro Actions guide.

Test before you launch

  1. Submit the form on the deployed site, not only locally.
  2. Check the email arrives and is not in spam.
  3. Submit with an empty required field and confirm the browser blocks it.
  4. Confirm the success message or thank-you page appears.

Komal themes, like most in the Astro themes catalog, ship as static sites with no server, so Option 1 or 2 is usually the quickest way to get a theme’s form working; the deploy docs list host-specific notes. For more patterns, see contact forms on a static Astro site.

FAQ

Why doesn’t my Astro contact form send emails?

A static Astro site has no server to receive the submission. The form needs an action pointing at a form service, host form handling, or an on-demand Astro Action that sends the email.

Can an Astro contact form work without a server?

Yes. Post it to a hosted form endpoint or use your host’s built-in form handling. The site stays static, and the service delivers submissions to your inbox.

How do I stop spam on an Astro contact form?

Add a honeypot field, which most form services support, and turn on the service’s spam filtering. For heavier spam, add a CAPTCHA such as Cloudflare Turnstile and verify it on the server or through the service.

Do Astro Actions work on a static site?

Not on their own. Actions run on the server, so you need an adapter and export const prerender = false on the page that uses them. The rest of the site can stay static.