How to build a Vue 3 contact form that sends email (no backend)

A complete Vue 3 contact form with the Composition API that delivers submissions by email and Telegram, with loading, success and error states, and no server code.

· 3 min read

Vue 3 single-file component for a contact form

Vue apps built with Vite are usually deployed as static files to Netlify, Vercel, Cloudflare Pages or a CDN. That keeps them fast, but leaves nothing on the server to send an email when someone fills in your contact form.

This guide builds a Vue 3 contact form using <script setup> that posts to a form backend. Submissions arrive in your inbox (and on Telegram if you like) without any backend code.

1. Get an access key

Create a free Formiz account, copy your access key and add your email under Channels → Email. Then add your key to .env:

bash
VITE_FORMIZ_KEY=fmz_your_key_here

Vite exposes variables that start with VITE_ to the browser. That is fine for this key: it can only send submissions to your own channels. To stop it being reused elsewhere, add your domain under Settings → Allowed domains.

2. The component

vue
<!-- src/components/ContactForm.vue -->
<script setup>
import { ref } from 'vue';

const status = ref('idle'); // idle | sending | sent | error
const error = ref('');

async function onSubmit(event) {
  const form = event.target;
  status.value = 'sending';
  error.value = '';

  const data = new FormData(form);
  data.append('access_key', import.meta.env.VITE_FORMIZ_KEY);

  try {
    const res = await fetch('https://api.formiz.app/submit', { method: 'POST', body: data });
    const json = await res.json();
    if (!res.ok || !json.success) throw new Error(json.message || 'Could not send your message');
    form.reset();
    status.value = 'sent';
  } catch (err) {
    error.value = err.message;
    status.value = 'error';
  }
}
</script>

<template>
  <p v-if="status === 'sent'" role="status">Thanks! We will get back to you shortly.</p>

  <form v-else @submit.prevent="onSubmit">
    <input type="checkbox" name="_honey" style="display:none" tabindex="-1" autocomplete="off" />

    <label for="cf-name">Name</label>
    <input id="cf-name" name="name" autocomplete="name" required />

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

    <label for="cf-message">Message</label>
    <textarea id="cf-message" name="message" rows="5" required></textarea>

    <button type="submit" :disabled="status === 'sending'">
      {{ status === 'sending' ? 'Sending…' : 'Send' }}
    </button>

    <p v-if="status === 'error'" role="alert">{{ error }}</p>
  </form>
</template>

Use it anywhere with <ContactForm />.

Why FormData instead of v-model?

You do not need a ref per field. new FormData(form) reads every input that has a name, so adding a phone field or a <select name="topic"> only means editing the template. Everything with a name is delivered to you.

If you already bind fields with v-model (for example for live validation), send JSON instead:

js
await fetch('https://api.formiz.app/submit', {
  method: 'POST',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify({ access_key: import.meta.env.VITE_FORMIZ_KEY, ...form.value }),
});

What happens after a submission

  • The message arrives by email within seconds. The visitor's address is the reply-to, so pressing Reply writes straight to them.
  • It is stored in your Formiz inbox, where you can move it from New to Contacted, Proposal, Won or Lost, add notes and assign it.
  • If you connected Telegram, you also get a push notification.

Using Nuxt?

Nuxt adds server rendering and its own runtime config. See the Nuxt contact form guide for the Nuxt-specific version.

Spam

The hidden _honey field silently drops most bots, and built-in rate limits stop bursts from one source. For more layers, read stop contact form spam without a CAPTCHA.

Get your form working in five minutes

Create a free Formiz key, add it to your form and receive submissions by email and Telegram. No server, no SMTP, no card.