Skip to content
Sign inJoin waitlist

Forms — Denzel Astro

The one form of this Astro template, the newsletter box in the footer of every page, works as soon as you run it.

It takes an e-mail address, checks that it looks like one, shows “…” on its button while sending, then “Thank you!” or “Something went wrong”, and clears the field. A hidden honeypot field drops spam.

Out of the box it runs in demo mode: nothing is sent, and the address is logged in the browser console. That’s fine while you build, but useless once you publish, so pick a destination before launch.

You want Mode Hosting
An email for every sign-up, with no server to run Static: a form service (Formspree, Web3Forms, Getform, Basin) Any static host
Sign-ups in your mailing tool, a spreadsheet, Slack… Static: a webhook (Zapier, Make, n8n, Pipedream) Any static host
Resend or Mailchimp directly, with no third party in between Server: the site’s own route (below) A host with an Astro adapter

Most sites want static mode: it keeps the site 100% static and takes two minutes.

  1. Create a form at your service and copy its endpoint URL (Formspree: https://formspree.io/f/<id>).

  2. Copy the example settings and paste the URL:

    Terminal window
    cp .env.example .env
    PUBLIC_FORM_ENDPOINT=https://formspree.io/f/abcdwxyz

    Web3Forms also needs PUBLIC_FORM_ACCESS_KEY.

  3. Restart npm run dev and sign up from the footer.

  4. If your host builds the site, put the same variable in its dashboard before deploying: .env stays on your computer (it is not in Git). The value is written into the pages when the site builds, so rebuild after changing it.

The endpoint is public (it is in the page), which is how these services are designed to work; they filter spam on their side. The form posts email, with form (newsletter) and subject (“New newsletter subscriber”) next to it, as multipart/form-data, and expects a 2xx answer. Details for each service are in Forms reference.

For Resend or Mailchimp without a third-party service, the form posts to a route on your own site:

  1. Add the adapter for your host: npx astro add vercel (or netlify, node, …).

  2. Set PUBLIC_FORM_MODE=server, and choose where sign-ups go with FORM_PROVIDER:

    You want Set
    The subscriber in a Mailchimp audience FORM_PROVIDER=mailchimp + MAILCHIMP_API_KEY, MAILCHIMP_AUDIENCE_ID; MAILCHIMP_STATUS is optional
    An email for every sign-up FORM_PROVIDER=resend + RESEND_API_KEY, FORM_EMAIL_TO, FORM_EMAIL_FROM
    It in your mailing tool, Slack, a spreadsheet… FORM_PROVIDER=webhook + FORM_WEBHOOK_URL (Zapier, Make, n8n, Formspree, your own API); FORM_WEBHOOK_SECRET is optional
    The server log only, while you test FORM_PROVIDER=console (the default)

    Several at once work: FORM_PROVIDER=resend,mailchimp.

  3. Restart npm run dev and send a test. The form now posts to /api/forms/newsletter (src/lib/forms/route.ts, added by src/integrations/forms.ts); every page stays static, only that route runs on the server, and it checks the address again.

  4. Put the same variables in your host’s dashboard before deploying, and redeploy after changing them.

Details for each provider, what it receives, the webhook payload, Mailchimp consent settings and how to write your own provider are in Forms reference.

The newsletter box (form newsletter, title “New newsletter subscriber”):

Field Name it arrives under Required
Email email yes, and it must look like an address

In server mode, Resend sends the title as the email’s subject; Mailchimp adds or updates the subscriber in your audience and tags them “New newsletter subscriber”; a webhook receives the field with its label.

The box’s words are content: footer.newsletter in src/content/site.json holds its title, the line above the field (“Join 89,000 subscribers!”), the placeholder, the button (“Sign Up”), the two messages the button shows after sending (success, error) and the note under it. The note says “By signing up, you agree to our Privacy Policy” but links nowhere: write your own, and put your privacy page’s address in it if you have one.

The form’s definition (its fields, the required one, the e-mail check, the title of each sign-up) is src/lib/forms/definitions.ts; the box is src/design-system/components/actions/NewsletterForm.astro and its script src/design-system/scripts/newsletter.ts. Keep the field named email: Resend and Mailchimp use it.

  • Sign up from the footer of your own site after deploying, with a real address.
  • Check the destination (inbox, spreadsheet, audience).
  • Try a failure on purpose: point PUBLIC_FORM_ENDPOINT at a wrong URL in a test build (or set a wrong API key in server mode), submit, and confirm the button says “Something went wrong”.

The honeypot stops the usual bots: the form carries a hidden field named fax that a person never sees; a bot that fills it is shown “Thank you!” and nothing is sent. If you start getting spam anyway, use a form service in static mode (Formspree, Web3Forms and Basin all include spam filtering), or a provider with double opt-in (MAILCHIMP_STATUS=pending).

Sign-ups go only where you point them; nothing is sent anywhere else. An e-mail address is personal data, and most countries expect you to say what happens to it: link your privacy policy from the note under the box, and choose a form service or provider that keeps the data where the law where you work allows. The box has no consent checkbox.

Mailchimp’s MAILCHIMP_STATUS decides what you may send: transactional (the default) adds contacts who can’t receive campaigns, pending sends them a confirmation e-mail first (double opt-in), and subscribed is for addresses that gave explicit consent. For a newsletter, pending is the usual choice.