我正在开发一个新的安全评估网页,我在其中使用HTML,Java脚本和PHP由于某些原因,代码无法正常工作。页面的工作方式是让用户回答“是”或“否”问题,当用户完成后,单击“提交”。然后页面将显示回答是的问题的数量,以及如果用户通过或未通过评估的消息。同时向评估结果发送电子邮件给经理。但是当我点击提交时,我只看到结果和消息,但是没有发送电子邮件。
$('.calc').change(function() {
calcscore();
});
$('#submitted').click(function() {
sumInputs();
result();
});
function sumInputs() {
var inputs = $('.calc:checked'),
result = $('#total').val(),
sum = 0;
for (var i = 0; i < inputs.length; i++) {
sum += parseInt(inputs[i].value);
}
$('#total').val(sum);
}
function result() {
var text;
var score = (($('#total').val()) / 57) * 100;
var score = score.toFixed(1);
if (score < 60) {
alert(text = "Total " + score + ": You have failed the Assessment");
} else {
alert(text = "Total " + score + ": You have passed the Assessment");
}
$('#demo').text(text);
}
function calcscore() {
var score = 0;
$('.calc:checked').each(function() {
score += parseInt($(this).val(), 10);
});
$('#total').val(score);
}
<!-- begin snippet: js hide: false console: true babel: false -->
<?php
if(isset($_POST['submit'])){
$to = "email@example.com";
$from = $_POST['email'];
$subject = "Security Assessment Result";
$message = $first_name . " " . $last_name . " Recived :" . "\n\n" . $('#total').val(sum);
mail($to,$subject,$message);
echo "Mail Sent. Thank you for taking the assessment.";
}
?>
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<!DOCTYPE html>
<html>
<body>
<h1>Security Assessment </h1>
<table>
<tr>
<th>PERSONNEL SECURITY</th>
</tr>
<tr>
<td>1. Does your staff wear ID badges?
<form>
Yes
<input class="calc" type="radio" name="radio1" value="1" /> No
<input class="calc" type="radio" name="radio1" value="0" /><br />
</form>
</td>
</tr>
<tr>
<td>2. Is a current picture part of the ID badge?
<form>
Yes
<input class="calc" type="radio" name="radio2" value="1" /> No
<input class="calc" type="radio" name="radio2" value="0" /><br />
</form>
</td>
</tr>
<tr>
<td>3. Are authorized access levels and type (employee, contractor, visitor) identified on the Badge?
<form>
Yes
<input class="calc" type="radio" name="radio3" value="1" /> No
<input class="calc" type="radio" name="radio3" value="0" /><br />
</form>
</td>
</tr>
</table>
Total : <input type="text" name="total" id="total" />
<input id="submitted" type="Submit" value="Submit"><br><br>
<p id="demo"></p>
</body>
</html>
任何反馈都将不胜感激。