我使用smtpjs将表单发送到我的电子邮件中,但是当我单击“仅提交其电子邮件”时,正文为空,表单中不包含该电子邮件。
<html>
<head>
<script src="https://smtpjs.com/v3/smtp.js"></script>
<script type="text/javascript">
function sendEmail() {
Email.send({
Host: "smtp.gmail.com",
Username : "test@test.com",
Password : "test@test.com",
To : '<test@test.com>',
From : "<test@test.com>",
Subject : "INSTRUMEN SELF ASSESSMENT RISIKO COVID-19",
Body : "<email body>",
})
.then(function(message){
alert("mail sent successfully")
});
}
</script>
</head>
<body>
<div class="testbox">
<form method="post">
<h1>INSTRUMEN SELF ASSESSMENT RISIKO COVID-19
</h1>
<div>
<h4>How often do you meet in person with teachers at your child's school?</h4>
<div class="question-answer">
<label><input type="radio" value="none" name="meet" />Almost never</label>
<label><input type="radio" value="none" name="meet" />Once or twice per year</label>
<label><input type="radio" value="none" name="meet" />Every few months</label>
<label><input type="radio" value="none" name="meet" />Monthly</label>
<label><input type="radio" value="none" name="meet" />Weekly or more</label>
</div>
</div>
<div> <input type="button" value="Send Email" onclick="sendEmail()"/> </div>
</form>
</div>
</body>
</html>
答案 0 :(得分:0)
您不包含要发送给该函数的任何值,您也无法检测到任何输入,因为它们没有任何ID,所以我建议使用此解决方案?
<html>
<head>
<script src="https://smtpjs.com/v3/smtp.js"></script>
<script type="text/javascript">
function sendEmail() {
let body = "";
if(document.getElementById('never').checked)
body += document.getElementById('never').value;
// same thing for the other radio inputs...
Email.send({
Host: "smtp.gmail.com",
Username : "test@test.com",
Password : "test@test.com",
To : '<test@test.com>',
From : "<test@test.com>",
Subject : "INSTRUMEN SELF ASSESSMENT RISIKO COVID-19",
Body : body,
})
.then(function(message){
alert("mail sent successfully")
});
}
</script>
</head>
<body>
<div class="testbox">
<form method="post">
<h1>INSTRUMEN SELF ASSESSMENT RISIKO COVID-19
</h1>
<div>
<h4>How often do you meet in person with teachers at your child's school?</h4>
<div class="question-answer">
<label><input type="radio" id='never' value="Almost
never" name="meet" />Almost
never</label>
<label><input type="radio" id='onceOrTwice' value="Once or
twice per year" name="meet" />Once or
twice per year</label>
<label><input type="radio" id='evFewMonths' value="Every
few months" name="meet" />Every
few months</label>
<label><input type="radio" id='Monthly' value="Monthly" name="meet"
/>Monthly</label>
<label><input type="radio" id='weekly' value="Weekly or
more" name="meet" />Weekly or
more</label>
</div>
</div>
<div> <input type="button" value="Send Email" onclick="sendEmail()"/> </div>
</form>
</div>
</body>
</html>
希望这对您有帮助