Menu

My Cloudflare Pages contact form could not send email, and nothing on the page ever said so
📰

My Cloudflare Pages contact form could not send email, and nothing on the page ever said so

DEV Community: javascript·Ankit Gupta·9 days ago
#VRRreEJP
#devtojavascript#devto#dev#contact#form
Reading 0:00
15s threshold

I run a small static site on Cloudflare Pages. Its contact page had a plain HTML form that posted to a Pages Function. This week I checked whether that form actually worked. It did not, and nothing a visitor could see would have told me why.

How the form was built

functions/api/contact.js reads the POST body, validates the email address and the message length, and sends the message through Brevo’s transactional email API. Whatever happens, it answers with a 303 redirect back to the contact page and carries the result in the query string: ?sent=ok , or ?sent=error&why=<reason> . The page reads that and shows a short status line.

The send step starts like this:

if ( ! env . BREVO_API_KEY ) { console . error ( ' contact: BREVO_API_KEY is not set on this Pages project ' ); return back ( url , ' error ' , ' config ' ); }

Enter fullscreen mode

Exit fullscreen mode

That branch is reasonable.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.