I have an online quiz where people answer true or false to a number of questions, when the form is submitted the next page says 'you got X correct out of 12' and where they got an answer wrong it gives them the correct answer and an explanation.
All this is working correctly, but what I want to do next is if the user wants a record of this they can fill a field on the original form with their e-mail address and get a copy of their results sent to them by e-mail.
I know how to set up a mail to line of code with e-mail address, subject line and body/message, but how do I specify what the body is going to be when the output is dependant on If / Else variables from the user input in the form?
my code so far is
if (!isset($_POST['submit']))
{
$answers = array(
1 => 'false',
2 => 'false',
3 => 'false',
4 => 'false',
5 => 'false',
6 => 'false',
7 => 'false',
8 => 'false',
9 => 'false',
10 => 'false',
11 => 'false',
12 => 'false'
);
echo '<br><br>Thank You, Here are your results:<br><br>';
$i = 0;
foreach ($answers as $key => $value)
{
if ($value == $_POST['q'][$key]) {$i++;}
}
echo '<br>';
echo '<br>You got ' . $i . ' out of ' . count($answers) . ' correct. <br><br>';
}
IF ($value != $_POST['q'][1])
{echo "Question 1 The right answer was False. <br>A good leader------. <br>
xxxxxxxxx ";}
ELSE
{echo "Question 1 - You got this correct. A good leader ---------.";}
echo '<p></p>-----------------------------<p></p>';
IF ($value != $_POST['q'][2])
{echo "Question 2 The right answer was False. <br>The person in charge of a unit ----------. <br>
xxxxxxxxxxxxxx. ";}
ELSE
{echo "Question 2 - You got this correct. The person in charge of a unit ------------.";}
// and so on for 12 questions