I am building a contact form with multiple input lines, and would like information from the form to be sent to my email address. For instance, I have a line for the user's email address, a line for the user's budget, and a line for the user's city. These variables are denoted by "email", "budget", and "city", respectively. As a result, I am using req.body.email as the text in nodemailer.
The issue is that I am only able to put one of the variables in the text section of the email. Here is my code to better explain what I mean.
const mailOptions = {
from: req.body.email,
to: 'fakeemail@gmail.com',
subject: 'New message from Ogma',
text: req.body.email
}
What is the syntax I have to use in order to also put req.body.budget and req.body.city in the text section?
Thank you!
Edit: Here is the rest of my JS code because I'm not sure what's wrong
const form = document.getElementById('login');
let subject = document.getElementById('subject');
let level = document.getElementById('level');
let inperson = document.getElementById('inperson');
let where = document.getElementById('where');
let details = document.getElementById('details');
let email = document.getElementById('email');
form.addEventListener('submit', (e)=>{
e.preventDefault();
console.log('submit clicked')
let formData = {
subject: subject.value,
level: level.value,
inperson: inperson.value,
where: where.value,
details: details.value,
email: email.value
}
let xhr = new XMLHttpRequest();
xhr.open('POST', '/');
xhr.setRequestHeader('content-type', 'application/json');
xhr.onload = function() {
console.log(xhr.responseText);
if (xhr.responseText == 'success'){
alert('Email sent');
subject.value = '';
level.value = '';
inperson.value = '';
where.value = '';
details.value = '';
email.value = '';
}else{
alert('Invalid login')
}
}
xhr.send(JSON.stringify(formData));
})