Grow your CSS skills. Land your dream job.

How do I get PHP Quiz Results emailed after being graded?

  • # August 10, 2012 at 8:14 pm

    Hi,
    I created a PHP Quiz using the tutorial at http://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:

    < !DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">














    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?



































    # August 10, 2012 at 8:14 pm

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

    < !DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">














    TRIVIA #1



    < ?php

    $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
    ";
    ?>
    < ?php
    // Set up parameters
    $to = "admin@spongebob-fanclub.com,'Email Address'";
    $subject = "Your Trivia Results";
    $message = "Here are your Trivia Results:";
    $from = "me@example.com";
    $headers = "From: $from";

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







Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.

*May or may not contain any actual "CSS" or "Tricks".