通过javascript发送邮件

问题描述

我尝试通过 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,但是现在我得到了空字符串。 我是否声明了错误的变量?我必须将它们直接传递给函数吗?如有帮助或建议,谢谢

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)