I try to send data entered in a form via javascript.
HTML
<form class="pix-form-style pixfort-form pix-padding-top-20 pix-form-light-white-bg" method="post">
<div class="form-group">
<input id="nome" type="text" class="form-control" placeholder="Nome">
</div>
<div class="form-group">
<input id="cognome" type="text" class="form-control" placeholder="Cognome">
</div>
<div class="form-group">
<input id="email" type="email" class="form-control" placeholder="Email">
</div>
<div class="form-group">
<input id="citta" type="text" class="form-control" placeholder="Città">
</div>
<div class="form-group">
<input id="telefono" type="text" class="form-control" placeholder="Numero telefono">
</div>
<input type="button" value="Richiedi informazioni" class="btn yellow-bg small-text btn-lg pix-white btn-block" style="background-color: #eedc1c;" onclick="sendEmail()" />
<div class="form-group" style="color:white; display: flex;">
<input type="checkbox" id="checkbox" value="" style="margin-left: 10px; margin-right: 5px;height:auto !important;" required><p>Dichiaro di aver letto ed accettato l'informativa</p>
</div>
</form>
JS
<!-- Javascript -->
<script src="https://smtpjs.com/v3/smtp.js"></script>
<script type="text/javascript">
function sendEmail() {
var nome = document.getElementById("nome").value;
var cognome = document.getElementById("cognome").value;
var email = document.getElementById("email").value;
var citta = document.getElementById("citta").value;
var telefono = document.getElementById("telefono").value;
var body = 'nome: ' + nome + ',cognome: ' + cognome + ',email: ' + email + ',città: ' + citta + ',telefono: ' + telefono;
Email.send({
Host: "host",
Username: "username",
Password: "password",
To: '[email protected]',
From: "Test",
Subject: "Sending Email using javascript",
Body: body
})
.then(function (message) {
alert(nome)
});
}
</script>
the email is sent, but as value I get
VIA ALERT ADN EMAIL
nome: [object HTMLInputElement],cognome: [object HTMLInputElement],email: [object HTMLInputElement],città: [object HTMLInputElement],telefono: [object HTMLInputElement]
So I added .value in the variable declaration, however now I get empty string. Did I declare the variables wrong? do I have to pass them directly to the function? help or suggestions if you can thanks