Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Back End How do I get PHP Quiz Results emailed after being graded?

  • This topic is empty.
Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #39288
    chicago123
    Member

    Hi,
    I created a PHP Quiz using the tutorial at https://css-tricks.com/building-a-simple-quiz/
    I need to get the quiz results emailed to me and the user, and graded. It already grades the quiz and displays a score.
    I’m really a beginner so I don’t know how to get the results emailed. Someone suggested using the mail() function, with a link to this page, http://php.net/manual/en/function.mail.php, but I don’t know how to use it at all. Could someone please give me detailed instructions – not just a link please.
    Help would be greatly appreciated!
    Here is the code for my quiz:







    Welcome to the Spongebob Fanclub! | Trivia #1








    TRIVIA #1









    1. In the KRUSTY TOWERS episode, what does Patrick say after Squidward says 'How can you have bags when you just found out this is a hotel?'











      .













    2. In ROCK BOTTOM, what was the name of the Candy Bar Spongebob wanted out of the vending machine?






















    3. In ROCK BOTTOM, what is Spongebob's number in line at the Bus Station?





      386


















    4. In KARATE ISLAND, what does Udan want Spongebob to buy?






      Condo


















    5. In MRS. PUFF, YOU'RE FIRED, when Spongebob takes apart the boat, what does he build when he puts it back together?



































    #107711
    chicago123
    Member

    And here is the code for the grade.php file that is used to grade the quiz (go to ‘https://css-tricks.com/building-a-simple-quiz/” for more info):







    PHP Quiz








    TRIVIA #1




    $answer1 = $_POST;
    $answer2 = $_POST;
    $answer3 = $_POST;
    $answer4 = $_POST;
    $answer5 = $_POST;

    $totalCorrect = 0;

    if ($answer1 == "A") { $totalCorrect++; }
    if ($answer2 == "C") { $totalCorrect++; }
    if ($answer3 == "B") { $totalCorrect++; }
    if ($answer4 == "A") { $totalCorrect++; }
    if ($answer5 == "C") { $totalCorrect++; }

    echo "
    $totalCorrect / 5 correct
    ";
    echo "
    You earned $totalCorrect 0 SpongeCash
    ";
    ?>
    // Set up parameters
    $to = "[email protected],'Email Address'";
    $subject = "Your Trivia Results";
    $message = "Here are your Trivia Results:";
    $from = "[email protected]";
    $headers = "From: $from";

    // Send email
    mail($to,$subject,$message,$headers);
    ?>







Viewing 2 posts - 1 through 2 (of 2 total)
  • The forum ‘Back End’ is closed to new topics and replies.