如何通过电子邮件发送php表单的结果?

时间:2017-03-21 00:09:33

标签: php html forms email

我在php中进行了测验,并尝试通过电子邮件发送单击提交按钮后看到的结果。我知道我需要使用电子邮件功能,但我不确定如何将整个页面放入电子邮件正文中。

这是html

<?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'];
$answer6 = $_POST['question-6-answers'];
$answer7 = $_POST['question-7-answers'];
$answer8 = $_POST['question-8-answers'];
$answer9 = $_POST['question-9-answers'];
$answer10 = $_POST['question-10-answers'];
$answer7 = strtolower(trim($answer7));
$answer8 = strtolower(trim($answer8));
$answer9 = strtolower(trim($answer9));
$answer10 = strtolower(trim($answer10));
$totalCorrect = 0;

if ($answer1 == "B") { $totalCorrect++; echo "Question 1 was Correct: The Chinese zodiac associates a sign with each month. Answer: False <br />\n"; }
else echo "Question 2 was incorrect. This is the correct answer:  The Chinese zodiac associates a sign with each month.  Answer: False <br />\n"; 

if ($answer2 == "A") { $totalCorrect++; echo "Question 2 was Correct:  Chinese zodiac signs represent different types of personalities. Answer: Ture <br />\n"; }
else echo "Question 2 was incorrect. This is the correct answer: Chinese zodiac signs represent different types of personalities.  Answer: True <br />\n";

if ($answer3 == "B") { $totalCorrect++; echo "Question 3 was Correct: The Chinese zodiac signs each have an equivalent constellations, like those of the occidental zodiac. Answer: False <br />\n";}
else echo"Question 3 was incorrect. This is the correct answer: Question 3: The Chinese zodiac signs each have an equivalent constellations, like those of the occidental zodiac.  Answer: False <br />\n";

if ($answer4 == "B") { $totalCorrect++; echo "Question 4 was Correct: Which sign is not part of the Chinese zodiac? Answer: Fox <br />\n";}
else echo "Question 4 was incorrect. This is the correct answer: Which sign is not part of the Chinese zodiac?   Answer: Fox <br />\n";

if ($answer5 == "A") { $totalCorrect++; echo "Question 5 was Correct:  The Chinese zodiac traditionally begins with which sign? Answer: Rat<br />\n";}
else echo"Question 5 was incorrect. This is the correct answer: The Chinese zodiac traditionally begins with which sign?   Answer: Rat <br />\n";

if ($answer6 == "C") { $totalCorrect++; echo "Question 6 was Correct: The Chinese zodiac traditionally ends with which sign? Answer: Pig <br />\n";}
else echo"Question 6 was incorrect. This is the correct answer: The Chinese zodiac traditionally ends with which sign?    Answer: Pig <br />\n";

if ($answer7 == "12" ||  $answer7 == "twelve") { $totalCorrect++; echo "Question 7 was Correct: How many signs are in the Chinese zodiac? Answer: 12 <br />\n";}
else echo"Question 7 was incorrect. This is the correct answer: How many signs are in the Chinese zodiac?    Answer: 12 <br />\n";

if ($answer8 == "Snake" || $answer8 == "snake") { $totalCorrect++; echo "Question 8 was Correct: Which is the only reptile that is a sign in the Chinese zodiac? Answer: Snake <br />\n";}
else echo "Question 8 was incorrect. This is the correct answer: Which is the only reptile that is a sign in the Chinese zodiac? Answer: Snake <br />\n";

if ($answer9 == "Dragon" || $answer9 == "dragon") { $totalCorrect++; echo "Question 9 was Correct: Which is the only imaginary animal that is a sign in the Chinese zodiac? Answer: Dragon <br />\n";}
else echo "Question 9 was incorrect. This is the correct answer: Which is the only imaginary animal that is a sign in the Chinese zodiac?   Answer: Dragon <br />\n";

if ($answer10 == "Rooster" ||  $answer10 == "rooster") { $totalCorrect++; echo "Question 10 was Correct: Which is the only bird that is a sign in the Chinese zodiac? Answer: Rooster <br />\n";}
else echo "Question 10 was incorrect. This is the correct answer: Which is the only bird that is a sign in the Chinese zodiac?    Answer: Rooster <br />\n";

echo "<div id='results'>$totalCorrect / 10 correct</div>";
$percent = $totalCorrect;
echo "You got a ", "$percent", "0%";
?>

和php

{{1}}

1 个答案:

答案 0 :(得分:-2)

我强烈建议在提交,发布,存储或发送之前验证输入发布数据。

但是为了完成所请求的任务,请查看此注册功能,该功能应该提供清晰度:

<textarea id="text_area_id" onclick="naa(this)"></textarea>

<script>
function naa(input) {
  var comment = $(input).val();
}
</script>

mail()是内置的PHP函数http://php.net/manual/en/function.mail.php

bool mail(string $ to,string $ subject,string $ message [,string $ additional_headers [,string $ additional_parameters]]);