0

我尝试通过 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@gmail.com',
            From: "Test",
            Subject: "Sending Email using javascript",
            Body: body
        })
        .then(function (message) {
          alert(nome)
        });
    }
  </script>

电子邮件已发送,但作为我得到的价值

通过警报 ADN 电子邮件

nome: [object HTMLInputElement],cognome: [object HTMLInputElement],email: [object HTMLInputElement],città: [object HTMLInputElement],telefono: [object HTMLInputElement]

所以我在变量声明中 添加了.value ,但是现在我得到了empty string。我是否声明了错误的变量?我必须将它们直接传递给函数吗?如果可以,请提供帮助或建议

4

0 回答 0