Vue contact form that sends email
Formgong team ·
A Vue contact form is a script setup component that posts FormData to Formgong with fetch. You do not add an API server, Axios, or SMTP. A browser cannot send email by itself. Telegram is instant. Email arrives for each submission, on the free plan too.
Vue component with fetch
Save this as ContactForm.vue. It uses script setup, one ref for the status, and one ref for the notice.
The handler calls preventDefault, checks the fields, and posts FormData. It does not set Content-Type.
status moves through idle, sending, sent and error. The button stays disabled while status is sending.
A 429 or the code rate_limited means the minute limit was hit. Wait and try again. Do not loop.
Show thanks only after response.ok and result.success are both true.
Free stores 250 submissions a month and emails each one right away to up to 3 verified addresses.
Telegram is instant on every plan, including Free. There is no auto-reply on Free.
Pro allows 5 email recipients.
<script setup>
import { ref } from "vue";
const status = ref("idle");
const notice = ref("");
const endpoint = "https://formgong.com/submit";
async function onSubmit(event) {
event.preventDefault();
const form = event.currentTarget;
if (!(form instanceof HTMLFormElement) || !form.reportValidity()) return;
status.value = "sending";
notice.value = "";
try {
const response = await fetch(endpoint, {
method: "POST",
headers: { Accept: "application/json" },
body: new FormData(form),
});
const result = await response.json();
if (response.status === 429 || result.code === "rate_limited") {
status.value = "error";
notice.value = "Too many submissions. Wait a minute and try again.";
return;
}
if (!response.ok || !result.success) {
status.value = "error";
notice.value = result.message || "Could not send. Try again.";
return;
}
form.reset();
status.value = "sent";
notice.value = result.message || "Thanks. We have your message.";
} catch {
status.value = "error";
notice.value = "Could not send. Check your connection and try again.";
}
}
</script>
<template>
<form @submit="onSubmit">
<input type="hidden" name="access_key" value="YOUR_ACCESS_KEY" />
<input type="hidden" name="_lang" value="en" />
<label>Name <input name="name" autocomplete="name" required /></label>
<label>Email <input name="email" type="email" autocomplete="email" required /></label>
<label>Message <textarea name="message" required></textarea></label>
<div aria-hidden="true" style="position:absolute;inset-inline-start:0;top:0;width:1px;height:1px;overflow:hidden;clip-path:inset(50%)">
<input name="botcheck" tabindex="-1" autocomplete="off" />
</div>
<button type="submit" :disabled="status === 'sending'">
{{ status === "sending" ? "Sending…" : "Send" }}
</button>
<p :role="status === 'error' ? 'alert' : 'status'">{{ notice }}</p>
</form>
</template>Can Vue send email directly?
No. Vue runs in the browser. The browser cannot open an SMTP connection to your mail host.
A library that claims to send mail from a component is calling someone else's HTTPS API. The secret for a real mailbox must not ship in the bundle.
Formgong is that HTTPS API for a contact form. The component posts the fields. Formgong stores the lead and delivers it.
Pick your own server when the submit must create an order or check a signed-in user. Pick this component for a contact form.
| SMTP from Vue | A browser email API | Formgong | |
|---|---|---|---|
| What you add | An SMTP library and a server, which the browser cannot be. | Their public key and a form that calls their API. | One public access key in the component. |
| Where mail is sent | It is not. Port 587 is not available to page script. | From their service, after you create an account. | From noreply@formgong.com. No DNS on your domain. |
| When email arrives | Never, on this path. | When their API accepts it. | Right away for each lead, on every plan. |
| Telegram | You build it. | You build it. | Instant on every plan, including Free. |
The Vue form guide, checked on 6 October 2026, covers v-model. It does not send email. SMTP is not a browser API.
Validation without a library
Native checks are enough for a contact form. required and type email block an empty post. reportValidity shows the browser message.
v-model keeps the same text in JavaScript. The trim modifier drops extra spaces. Vue's form guide documents both.
v-model ignores the initial value attribute. Set the starting text in the reactive object.
VeeValidate and Zod are optional. Use one when you already have it. This page does not add either package.
Call fetch only after the native check passes. A failed check should leave the typed text in place.
v-model and native checks
<script setup>
import { reactive, ref } from "vue";
const fields = reactive({ name: "", email: "", message: "" });
const notice = ref("");
const failed = ref(false);
async function onSubmit(event) {
const form = event.currentTarget;
if (!(form instanceof HTMLFormElement) || !form.reportValidity()) return;
event.preventDefault();
const body = new FormData();
body.set("access_key", "YOUR_ACCESS_KEY");
body.set("_lang", "en");
body.set("name", fields.name.trim());
body.set("email", fields.email.trim());
body.set("message", fields.message.trim());
body.set("botcheck", "");
failed.value = false;
try {
const response = await fetch("https://formgong.com/submit", {
method: "POST",
headers: { Accept: "application/json" },
body,
});
const result = await response.json();
if (!response.ok || !result.success) {
failed.value = true;
notice.value = result.message || "Could not send. Try again.";
return;
}
fields.name = "";
fields.email = "";
fields.message = "";
notice.value = result.message || "Thanks. We have your message.";
} catch {
failed.value = true;
notice.value = "Could not send. Check your connection and try again.";
}
}
</script>
<template>
<form @submit="onSubmit">
<label>Name <input v-model.trim="fields.name" name="name" required /></label>
<label>Email <input v-model.trim="fields.email" name="email" type="email" required /></label>
<label>Message <textarea v-model.trim="fields.message" name="message" required></textarea></label>
<button type="submit">Send</button>
<p :role="failed ? 'alert' : 'status'">{{ notice }}</p>
</form>
</template>Nuxt
A Nuxt contact form can use this same component. The submit handler runs in the browser, so SSR does not post twice.
Do not use useFetch for the click. Nuxt's docs keep useFetch for data the page needs while it renders.
A server route under server/api is the path that needs a running server. It is missing after nuxt generate.
The Nuxt-specific notes are on the Nuxt contact form.
Vite, the contact page, and a feedback form
Put the public key in a VITE_ variable, such as VITE_FORMGONG_KEY. Vite only exposes that prefix to the page.
The key is public either way. The variable only keeps it out of the component file.
A feedback form is the same component. Change the labels and keep name, email and message.
The Options API uses the same fetch inside methods. script setup is not required.
Disable the button while status is sending. A second click would store a second lead.
If the page sets a Content-Security-Policy, connect-src must include https://formgong.com or fetch is blocked.
Localhost is allowed until you turn the domain list on. With the list on, add localhost too.
A file field
Name the file input attachment and post FormData. Do not set Content-Type. The browser must set the multipart boundary.
Turn on attachments in the form settings. Verify the account email, and add your Turnstile site key under Protection.
The server accepts PDF, JPEG and PNG only. The cap is 3 files, 5 MiB each and 10 MiB combined.
Free stores 1.0 GiB of files. Pro stores 10.0 GiB. Files follow the form's retention period and are deleted with the submission.
Only the form owner can download a file, and only after signing in. The Telegram alert does not attach the file.
On the free plan the email also lists the file link. You sign in to download it. Telegram is instant.
File input and Turnstile
<label>File
<input name="attachment" type="file" accept=".pdf,.jpg,.jpeg,.png" />
</label>
<!-- Keep the fetch body as FormData. Do not set Content-Type.
Add the Turnstile widget only after attachments are enabled. -->
<script src="https://challenges.cloudflare.com/turnstile/v0/api.js" async defer></script>
<div class="cf-turnstile" data-sitekey="YOUR_TURNSTILE_SITE_KEY"></div>Error states
Treat the send as a success only when the HTTP status is OK and success is true.
Read code and message from the JSON. The message is already translated for _lang.
Leave botcheck empty. The same trap also answers to _gotcha, _honey and _honeypot.
A filled honeypot is stored as spam. It is not emailed, it is not sent to Telegram, and it does not use the monthly quota.
If the page sends _ts and the form arrives in under 1.5 seconds, that lead is scored as spam too.
Turnstile is optional on every plan. It is required when a file is attached. The secret stays in Formgong.
| Code | What it means | What to do |
|---|---|---|
| rate_limited | 429. More than 30 posts a minute for this form, or 20 from one IP. | Wait a minute. Show the message and leave the fields filled. |
| limit_exceeded | The account used its monthly submissions. Free is 250. | The lead is not stored or delivered: the account is over its limit and its held submissions are full. The owner upgrades the plan or buys a pack. |
| unknown_access_key | 404. That access key does not match a form. | Copy the key again from Formgong. A placeholder key always fails. |
| turnstile_missing | Turnstile is on, or a file is attached, and the token was not posted. | Add the widget only after you turn protection on. The field name is cf-turnstile-response. |
| turnstile_failed | Cloudflare rejected the token. | Load the widget again and submit once. Check the site key. |
| too_large | 413. The text body is over 64 KB, or a file is over the upload cap. | Shorten the message, or send fewer files. The cap is 3 files, 5 MiB each, 10 MiB total. |
| origin_not_allowed | A domain list is on, and this host is not in it. | Add the live host. Every plan, Free included, has the domain list. |
The same fetch pattern, without Vue, is on the JavaScript contact form. Why the browser cannot send mail itself is in send email from frontend JavaScript. Spam checks without a CAPTCHA are in contact form spam without CAPTCHA. Quotas are on the pricing page.
How forms work in Vue
A Vue app built with Vite runs in the browser, so a contact form needs somewhere to send its data. The usual answer is to add a small API server with an email library. Formgong replaces that server: the component posts to https://formgong.com/submit and shows the answer.
The snippet below is a single-file component with <script setup>. It reads the fields with FormData, so it works with or without v-model, and needs no extra packages: fetch is built into the browser.
Set it up in Vue
- Create a form in Formgong and copy the access key.
- Save the snippet as
ContactForm.vueand replace the key. If you prefer an environment variable, use one with theVITE_prefix, such asVITE_FORMGONG_KEY: Vite only exposes those to browser code. - Use the component in your page and translate the labels; set
_langto the page language. - Run the dev server and send a test. The lead is in the Formgong inbox. Telegram and email arrive right away.
Component package: npm install @formgong/vue (npm: @formgong/vue)
Add to an existing project: npx formgong init (npm: formgong)
Formgong or your own API server?
Your own server is worth it when the form changes data in your app, such as creating an order.
For contact and lead forms Formgong saves you the server, the email provider and the spam handling.
Questions and answers
Do I need Axios?
No. The browser's fetch is enough. If your project already uses Axios, send the same body and headers with it.
Can I use v-model and validation libraries?
Yes. Keep your validation and call fetch in the submit handler with the values you collected.
Is the key safe in a VITE_ variable?
Yes. The access key is public anyway; the variable only keeps it out of the component code.
Articles on this topic
Related pages
Guides
- Formgong for agencies
- Static website contact form
- Netlify Forms alternative
- GDPR-compliant contact form
- Formspree alternatives
- Formcarry alternatives
- Formspark alternatives
- Splitforms alternatives
- Formgrid alternatives
- FormBackend alternatives
- Formbold alternatives
- Formester alternatives
- HeroTofu alternatives
- KwesForms alternatives
- Sheet Monkey alternatives
- Slapform alternatives
- Static Forms alternatives
- ShipMyForm alternatives
- Contact Form 7 alternatives
- WPForms alternatives
- Zapier Forms alternatives
- Forminit alternatives
- Fillout alternatives
- Formstack alternatives
- Microsoft Forms alternatives
- Paperform alternatives
- Freedback alternatives
- Pageclip alternatives
- EmbedSocial alternative
- Trustindex alternative
- Senja alternative
- Shapo alternative
- Junip alternative
- Famewall alternative
- FormKeep alternatives
- Jotform alternatives
- Basin alternatives
- Getform alternatives
- FormSubmit alternatives
- Typeform alternatives
- Tally alternatives
- Wufoo alternatives
- Google Forms alternatives
- Formgong alternatives
- Formsite alternatives
- Form for photographers
- Form for restaurants
- Form for clinics
- Form for real estate
- Form for lawyers
- Best form backend services
- Form endpoint services tested
- Contact form APIs tested
- Web3Forms alternatives
- EmailJS alternatives
- Formspree vs Web3Forms
- Formspree vs EmailJS
- Formspree vs Getform (Forminit)
- Formspree vs Basin
- Formspree vs FormSubmit
- Web3Forms vs Netlify Forms
- Netlify Forms vs Formspree
- Jotform vs Typeform
- Judge.me vs Yotpo
- Judge.me vs CusRev: the WooCommerce question
- Best free form backends
- Free website templates
- Testimonial and rating widget
- Judge.me alternative
- Yotpo alternative
- Loox alternative
- Stamped alternative
- Okendo alternative
- Fera alternative
- CusRev alternative
- Trustpilot alternative
- Testimonial.to alternative
- Elfsight alternative
- Trustmary alternative
- Boast alternative
- REVIEWS.io alternative
- Endorsal alternative
- AI builder prompts
- Form checker
- AI form generator
- Form builder
- Tailwind form generator
- Bootstrap form generator
- Booking form generator
- Order form generator
- Registration form generator
- Contact form generator
- HTML form generator
- HTML form builder
- Survey form generator
- Feedback form generator
- Newsletter signup form generator
- RSVP form generator
- Job application form generator
- T-shirt order form
- Cake order form
- Custom order form
- Rental application form
- Time off request form
- Donation request form
- Volunteer form
- Daycare registration form
- Maintenance request form
- Prayer request form
- Emergency contact form
- Review schema generator
- Google review link generator
- Contact form examples
- HTML contact form code
- React contact form component
- Next.js contact form template
- Tailwind contact form template
- Shopify contact form Liquid
- Webflow contact form code
- Framer contact form component
- Astro contact form component
- Vue contact form component
- Ghost contact form
- WordPress contact page template
- Agent rules files
- Tools