Your Contact Form Says Thanks, Then Loses the Lead. Here Is a Next.js Handler That Cannot Drop One
Picture the failure mode that worries me most on a service business site. A homeowner fills out the contact form, clicks Submit, and sees a green "Thanks, we will be in touch." Behind that message, the handler called a third party email or form service, the call failed or got throttled, and nobody logged it. The owner sees an empty inbox and concludes the site is dead. The visitor waits for a…
In the world of service-based websites, there is one crucial piece of code that can make or break a potential lead: the contact form. Imagine a homeowner filling out the contact form, clicking the Submit button, and seeing a reassuring "Thanks, we will be in touch." message. However, behind the scenes, the handler called a third-party email or form service to process the submission.
Unfortunately, if the call to the email service fails or gets throttled, the lead is lost forever, with no trace left behind. This scenario is the worst kind of bug a developer can encounter, as it leaves both the owner and the visitor with false expectations. To prevent such a disaster, the recommended approach is to store the submission first and then attempt to notify anyone afterwards.
This change in order, rather than relying on a specific vendor, ensures that the lead is never lost silently. The handling process should begin by storing the submission in a durable storage system that the developer controls, before proceeding to notify the third-party service. This way, even if the email provider is down, slow, or throttled, the lead is still saved and can be retried later.
The HTTP 200 response sent to the browser should indicate that the submission has been successfully stored, and the notification side effect is allowed to fail independently. By storing the lead data first, developers can ensure that valuable leads are not lost silently, providing a crucial safeguard for service-based businesses.
Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.