'Axios Error : Request Failed with status code 500 - More Details on error below (React and Node.js and Nodemailer)

I am trying to submit data from a form on my page to a node.js api using axios but i get the following error.

Error: Request failed with status code 500
    at createError (createError.js:16:1)
    at settle (settle.js:17:1)
    at XMLHttpRequest.onloadend

This is my onSubmit function where I use axios

const formSubmit = (e) => {
    e.preventDefault();

    let data = {
        firstname: firstName,
        secondname: secondName,
        email: email,
        industry: industry,
        message: message,
        number: number,
        website: website
    }

    axios.post('/api/forma' , data)
    .then(res => {
        setSent(true)
    },resetForm()
    ).catch(error => {
        console.log(error)
    })

}

This is the node.js part of the api

app.post('/api/forma' , (req , res) => {
    let data = req.body
    let smtpTransport = nodemailer.createTransport({
        host: 'mail.privateemail.com',
        port: 993,
        secure: false,
        auth: {
            user:'[email protected]',
            pass: '88WRHMMmmm'
        }
    });

    let mailOptions = {
        from: data.email,
        to: 'hzdigitalagency.com',
        subject: `HZ Agency Customer -  ${data.firstname} `,
        html: 
        "<h1>Hello </h1> <ul> <li> <li> Hello <ul>"
          
        
    }

    smtpTransport.sendMail(mailOptions, (error , response) => {
        if(error) {
            res.send(error)
        }
        else {
            res.send("Success")
        }
    })

    smtpTransport.close();
})

I am kind of a beginner to this so would really appreciate any help , Thanks in advance !

And It also shows this error

POST http://localhost:3000/api/forma 500 (Internal Server Error)

My node.js backend is running on server 5000 and frontend on 3000



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source