Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

156
Visualizações
How to send multiple req.body inputs in a nodemailer email?

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));

})
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

If something isn't very wrong, then req.body should be an object. Something like

{
    email: "some@mail.com",
    budget: 12345,
    city: "Paris"
}

which means you should be able to just do

text: req.body

That way you can then access the object either but using mailOptions.text and working with it as you would with an object, or reference it direcly since it's a nested object - mailOptions.text.budget.

It all depends on what you do with the mailOptions afterwards.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda