ปัญหาแบบฟอร์มติดต่อ - ฉันได้รับข้อความ แต่ไม่มีเนื้อหา (หน้าว่าง)

ฉันมีแบบฟอร์มติดต่อบนเว็บไซต์ซึ่งเคยใช้งานได้ แต่เนื่องจากไม่กี่เดือนที่ผ่านมาหยุดทำงานอย่างถูกต้อง อาจเป็นเพราะข้อผิดพลาดในการเขียนโค้ดบางอย่างซึ่งฉันไม่สามารถเข้าใจได้ สิ่งที่เกิดขึ้นคือฉันได้รับข้อความที่ส่งไป แต่ข้อความเหล่านั้นว่างเปล่าโดยไม่มีเนื้อหาเลย มีปัญหาอะไรบ้าง?

ฉันกำลังแนบส่วนหน้าก่อนแล้วจึงแนบส่วนหลัง

ตัวอย่าง contact.php โค้ดส่วนหน้า:-

<div id="content">
     <h2 class="newitemsxl">Contact Us</h2>

<div id="contactcontent">
        <form method="post" action="contactus.php">
Name:<br />
<input type="text" name="Name" /><br />
Email:<br />
<input type="text" name="replyemail" /><br />
Your message:<br />
<textarea name="comments" cols="40" rows="4"></textarea><br /><br />

<?php require("ClassMathGuard.php"); MathGuard::insertQuestion(); ?><br /> 
  <input type="submit" name="submit" value="Send" />
* Refresh browser for a different question. :-)

</form>
</div>

</div>

ตัวอย่าง contactus.php (โค้ดแบ็กเอนด์):-

<?php

/* first we need to require our MathGuard class */
require ("ClassMathGuard.php");
/* this condition checks the user input. Don't change the condition, just the body within the curly braces */
if (MathGuard :: checkResult($_REQUEST['mathguard_answer'], $_REQUEST['mathguard_code'])) {
    $mailto="[email protected]";
$pcount=0;
$gcount=0;
$subject = "A Stylish Goods Enquiry";
$from="[email protected]";
echo ("Great, you're message has been sent !"); //insert your code that will be executed when user enters the correct answer
} else {
    echo ("Sorry, wrong answer, please go back and try again !"); //insert your code which tells the user he is spamming your website
}


while (list($key,$val)=each($HTTP_POST_VARS))
{
$pstr = $pstr."$key : $val \n ";
++$pcount;
}
while (list($key,$val)=each($HTTP_GET_VARS))
{
$gstr = $gstr."$key : $val \n ";
++$gcount;
}
if ($pcount > $gcount)
{
$comments=$pstr;
mail($mailto,$subject,$comments,"From:".$from);
}
else
{
$comments=$gstr;
mail($mailto,$subject,$comments,"From:".$from);
}
?>

person nitbuntu    schedule 28.01.2010    source แหล่งที่มา


คำตอบ (2)


อาจมีการอัพเกรด PHP บนเซิร์ฟเวอร์และ $HTTP_POST_VARS เลิกใช้แล้ว ใช้ $_POST และ $_GET สำหรับสิ่งเหล่านั้น

person Pentium10    schedule 28.01.2010
comment
ดังนั้นไม่ว่าจะเขียนไว้ที่ไหน:- '$HTTP_POST_VARS' ฉันควรแทนที่ด้วย '$_POST' และเมื่อใดก็ตามที่เขียนว่า '$HTTP_GET_VARS' ฉันควรแทนที่ด้วย '$_GET' หรือไม่ - person nitbuntu; 28.01.2010

เป็นไปได้ไหมที่เวอร์ชัน php ของคุณเปลี่ยนไป? ใน php5 อาร์เรย์ HTTP_POST_VARS ไม่สามารถใช้งานได้อีกต่อไป

คุณสามารถลองทำสิ่งต่อไปนี้เพื่อรับค่าของคุณก่อนที่จะเริ่มการวนซ้ำ while:

$HTTP_POST_VARS   = !empty($HTTP_POST_VARS)   ? $HTTP_POST_VARS   : $_POST;
person opHASnoNAME    schedule 28.01.2010
comment
บรรทัดนี้ที่คุณพูดถึง ฉันควรเพิ่มไว้เหนือ while loop หรือไม่ - person nitbuntu; 28.01.2010
comment
ใช่ หรือแทนที่ $HTTP_POST_VARS ด้วย $_POST ในซอร์สโค้ดของคุณ - person opHASnoNAME; 28.01.2010