Hi,
I created a simple PHP Quiz using http://css-tricks.com/building-a-simple-quiz/
Then I edited the code of the php file so that the quiz results get emailed to myself using the mail() function.
After that I created a text field on the quiz page where the user can type in their email address.
Now I need the quiz results (the same message that gets emailed to me) to also be emailed to the user. Any suggestions?
I am a beginner, so please don't make it too complicated!
Any assistance would be greatly appreciated!
Here is the code so far:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>PHP Quiz</title>
<link rel="stylesheet" type="text/css" href="css/style.css" />
</head>
<body>
<div id="page-wrap">
<h1>TRIVIA #1</h1>
<?php
$answer1 = $_POST['question-1-answers'];
$answer2 = $_POST['question-2-answers'];
$answer3 = $_POST['question-3-answers'];
$answer4 = $_POST['question-4-answers'];
$answer5 = $_POST['question-5-answers'];
$totalCorrect = 0;
if ($answer1 == "Question 1 - Correct") { $totalCorrect++; }
if ($answer2 == "Question 2 - Correct") { $totalCorrect++; }
if ($answer3 == "Question 3 - Correct") { $totalCorrect++; }
if ($answer4 == "Question 4 - Correct") { $totalCorrect++; }
if ($answer5 == "Question 5 - Correct") { $totalCorrect++; }
echo "<div id='results'>$totalCorrect / 5 correct</div>";
echo "<div id='results'>You earned $totalCorrect 0 Coins</div>";
?>
<?php
$mailTo = "admin@mywebsite.com";
$msgSubject = "Your Trivia Results";
$msgBody = "Hi!\n\n";
$msgBody .= "On Trivia #1 you got ";
$msgBody .= $totalCorrect . " out of 5 correct!\n ";
$msgBody .= "You earned ";
$msgBody .= $totalCorrect . "0 Coins!\n\n";
$msgBody .= "Here are your Trivia Results:\n";
$msgBody .= $answer1 . "\n";
$msgBody .= $answer2 . "\n";
$msgBody .= $answer3 . "\n";
$msgBody .= $answer4 . "\n";
$msgBody .= $answer5 . "\n\n";
$msgBody .= "Thanks for Playing!\n\n";
$xHeaders = "From:";
mail ($mailTo, $msgSubject, $msgBody, $xHeaders);
?>
</div>
<script type="text/javascript">
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
</script>
<script type="text/javascript">
var pageTracker = _gat._getTracker("UA-68528-29");
pageTracker._initData();
pageTracker._trackPageview();
</script>
</body>
</html>