October 22, 2024
Chicago 12, Melborne City, USA
PHP

Trouble Getting My React Contact Form to Send Emails via Backend


I’ve been trying to set up a contact form using React to send emails, and I’ve encountered several issues. Here’s what I’ve tried so far:

React Form Setup: Built a multi-page React app where Welcome.js handles the contact form submission.

Backend Setup: Used server.js with Express and Nodemailer to send emails via a /send-email endpoint. Nodemailer is configured with Gmail SMTP.

Form Submission: Made a POST request from Welcome.js to /send-email. Confirmed server.js is running and listening on port 5000.

Issues Faced:

Email not sending: Nodemailer configuration seems correct, but emails aren’t being delivered.

CORS Errors: Had to add CORS middleware to server.js.

Fetching Errors: Sometimes getting Failed to fetch errors, despite server running.

I’d appreciate any help on what might be causing these issues, specifically:

Are there common misconfigurations with Nodemailer/Gmail?

How can I ensure my backend is properly linked to the frontend for sending emails?

Current Code:

Welcome.js: Handles the form and sends POST requests to /send-email.

server.js: Uses Express and Nodemailer for handling the email logic.

Any advice would be helpful. Thanks!

my contact form can be viewed here https://contact.jamieparishooper.com



You need to sign in to view this answers

Leave feedback about this

  • Quality
  • Price
  • Service

PROS

+
Add Field

CONS

+
Add Field
Choose Image
Choose Video