Using jQuery Ajax with node.js and express to validate sending an email
Go to solution
Solved by Person_125,
I solved it by sending a response in my index.js file like so:
router.post("/home", (req, res) => { let { firstName, lastName, email, website, company, message } = req.body; console.log("Data: ", req.body); let mailOptions = { from: email, to: "myemail@email.com", subject: "No Subject", html: "<h3>First Name: " + firstName + "</h3>" + "<h3>Last Name: " + lastName + "</h3>" + "<h3>Email: " + email + "</h3>" + "<h3>Company: " + company + "</h3>" + "<h3>Website: " + website + "</h3>" + "<h3>Message: " + message + "</h3>" } smtpTransport.sendMail(mailOptions, (error, response) => { if (error) { console.log(error); res.status(500).send('false'); // <----- HERE } else { console.log("Successfully sent email."); res.send("OK"); // <------------- HERE } }) });
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now