Next.js contact form not sending emails: SendGrid causes and fixes

By Nayan Kyada · · 6 min read

If your Next.js contact form shows a success message but no email ever lands in the inbox, you are losing enquiries without knowing it. That is the worst kind of bug on a marketing site, because nothing looks broken. This post walks through the five causes I see most often when a form that uses SendGrid goes quiet, in the order I check them.

Why a Next.js contact form stops sending emails

The form itself is rarely the problem. There are three separate hops: the browser calls your route handler, the route handler calls SendGrid, and SendGrid hands the message to the recipient's mail server. A failure at any hop can still end with the visitor seeing a green tick. Your first job is to find which hop dropped the message.

Open two places before changing any code: your Vercel function logs for the route, and the Activity feed in the SendGrid dashboard. If SendGrid shows no activity at all, the problem is in your code or environment. If it shows the message as processed but not delivered, the problem is authentication or the recipient.

Cause 1: the send is never awaited

This is the classic. On serverless hosting, a function can be frozen the moment the response is returned. A promise you did not await may never finish, and a swallowed catch hides the error.

// app/api/contact/route.ts (broken)
import sgMail from "@sendgrid/mail";
 
export async function POST(req: Request) {
  const data = await req.json();
  sgMail.setApiKey(process.env.SENDGRID_API_KEY!);
 
  sgMail
    .send({
      to: "hello@example.com",
      from: data.email,
      subject: "New enquiry",
      text: data.message,
    })
    .catch(() => {});
 
  return Response.json({ ok: true });
}

Three problems are packed in here. The send is not awaited, the error is thrown away, and the from address is whatever the visitor typed. The route always says ok.

// app/api/contact/route.ts (fixed)
import sgMail from "@sendgrid/mail";
 
const apiKey = process.env.SENDGRID_API_KEY;
 
export async function POST(req: Request) {
  if (!apiKey) {
    console.error("SENDGRID_API_KEY is not set");
    return Response.json({ ok: false }, { status: 500 });
  }
  sgMail.setApiKey(apiKey);
 
  const { name, email, message } = await req.json();
 
  try {
    await sgMail.send({
      to: "hello@example.com",
      from: "forms@example.com", // an address on your authenticated domain
      replyTo: email,
      subject: `New enquiry from ${name}`,
      text: message,
    });
    return Response.json({ ok: true });
  } catch (err) {
    const detail = (err as { response?: { body?: unknown } }).response?.body;
    console.error("SendGrid send failed", detail ?? err);
    return Response.json({ ok: false }, { status: 502 });
  }
}

Now a failure is a real failure, the client can show an honest error, and the SendGrid error body lands in your logs. If you want the response to return faster, Next.js has an after function in next/server for work that runs post-response. For a contact form I would not bother: awaiting is simpler and the visitor should know whether it worked.

Cause 2: the environment variable is missing in production

The form works on your laptop because .env.local has the key. On Vercel the variable may be missing, set only for Preview, or added after the last deployment. Vercel applies environment variable changes to new deployments only, so you need to redeploy.

Check the project settings for the variable in the Production environment, redeploy, and confirm with the log line from the fixed handler above. Also check that the key was not created with restricted permissions that exclude Mail Send. A restricted key without that permission returns a 403.

It is also worth confirming the key is only ever read on the server. If it has a NEXT_PUBLIC_ prefix, it is shipped to the browser, and you should rotate it. I cover that check in Sanity API token exposed in a Next.js site, and the same logic applies to any secret.

Cause 3: the from address is not verified or authenticated

SendGrid will not send from an address you have not proven you control. Depending on your setup that means either Single Sender Verification or, properly, Domain Authentication. A 202 response from the API only means SendGrid accepted the request. It does not mean the mail was delivered.

For a business site, use domain authentication. SendGrid gives you DNS records to add at your registrar, usually CNAMEs for DKIM. Until they validate, mail may be rejected or land in spam. Using the visitor's address as the from field, as in the broken example, breaks this entirely. Send from your own domain and put the visitor in replyTo.

Cause 4: the mail was delivered, then filtered

If the SendGrid Activity feed shows delivered, look at the recipient side. Check spam and quarantine folders, and any rule on the mailbox that moves messages from the sender. Large mailbox providers now expect proper authentication from senders, so a missing SPF, DKIM, or DMARC setup on your domain is a common reason messages vanish.

Send a test to a personal mailbox you control as well as the business one. If one receives and the other does not, the issue is on that mail server, not in your code.

Cause 5: spam bots burned your sending reputation

An unprotected form endpoint gets found. Bots post thousands of junk submissions, your account hits a limit or gets flagged, and genuine enquiries stop. Signs are a spike in Activity, bounces to nonsense addresses, or a warning email from SendGrid.

Add a honeypot field that real users never fill, validate the payload on the server, and rate limit by IP. A CAPTCHA service is an option if the bot traffic persists. Validation matters even without bots: check that email is a valid address and the message length is sane before calling the API.

How to verify the fix

  1. Submit the form on the live production URL, not a preview.
  2. Confirm a log line or a 200 response in the Vercel function logs.
  3. Find the message in the SendGrid Activity feed and confirm it shows delivered.
  4. Confirm it arrives in the real inbox, not spam, and that replying goes to the visitor.
  5. Force a failure by temporarily removing the key on a preview deployment, and confirm the form shows an error instead of a false success.

That last step is the one people skip, and it is the one that stops this happening silently again. A form that cannot fail loudly will eventually fail quietly.

If you want a second pair of eyes on a whole site rather than one form, the checklist in Next.js website audit: what a paid one covers is a good way to judge scope. If a developer has left and you cannot tell where the keys and DNS records live, start with taking over a Next.js project after your developer disappears. Slow third-party code on the same page is another common culprit, covered in third-party scripts slowing your Next.js site.

This is work I do: tracing lost form submissions, fixing email delivery, and hardening forms on Next.js and Sanity sites. A Performance & Sanity audit starts from $800, and you can see the details on the services and packages page.

Frequently asked questions

Why does my Next.js contact form say success but no email arrives?

Usually the route returns success before SendGrid has been awaited, or SendGrid accepted the message (a 202) and the receiving mailbox then rejected or filtered it. Check the SendGrid Activity feed to see which one happened.

Why did my SendGrid emails work locally but fail on Vercel?

The most common reasons are an environment variable that is not set for the Production environment, or a deployment that was not redeployed after the variable was added. Vercel only applies environment variable changes to new deployments.

Why do SendGrid emails from my contact form go to spam?

The sending domain is probably not authenticated, or the from address is the visitor's own email, which fails SPF and DKIM alignment. Authenticate your domain in SendGrid and send from an address on that domain.