Connect Next.js forms to email
Connect a contact form in the Next.js App Router to GlueForms. This example works as a Server Component without a client directive or an API route.
Add a native form
- In GlueForms, open Forms, choose your form and copy its receiving URL. Select your form above, or replace
YOUR_FORM_URLin the example. - Create
app/contact/page.tsx, orsrc/app/contact/page.tsxif your project usessrc. Add this page component.
React
export default function ContactPage() {
return (
<main>
<h1>Contact us</h1>
<form action="YOUR_FORM_URL" method="POST">
<label>
Name
<input name="name" autoComplete="name" />
</label>
<label>
Email
<input name="replyto" type="email" autoComplete="email" required />
</label>
<label>
Message
<textarea name="message" rows={4} required></textarea>
</label>
<button type="submit">Send message</button>
</form>
</main>
);
}Use the native lowercase <form> for this POST request. The Form component from next/form uses GET when its action is a string.
After acceptance, the browser opens the thank-you page with status 200, or follows a 303 redirect to the HTTPS URL saved in your form’s settings. With JavaScript, request JSON and show your own confirmation after accepted: true. JSON receipts do not redirect automatically. The replyto field explicitly sets the address for replies to the notification.
Publish the page, submit the form and open the saved message in GlueForms to check the fields and email notification.