I am working on a new security assessment web page in which I am using HTML, Java Script and PHP For some reason, the code is not working properly. The way the page supposed to work is by having the user answer Yes or No questions, and when the user is done they click submit. Then the page would display the number of questions answered yes, and a message if the user passed or failed the assessment. Also send an email to the manager with the assessment result. But when I click submit, I only see the result and the message, but the email is not sent.
$('.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.";
}
?>
<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>
Any feedback would be appreciated.