【问题标题】:Contact form problem - I do receive messages, but no contents (blank page)联系表格问题 - 我确实收到消息,但没有内容(空白页)
【发布时间】:2011-01-10 09:13:43
【问题描述】:

我在现场有一个曾经可以使用的联系表,但从最近几个月开始就停止了正常工作。这可能是由于一些我无法弄清楚的编码错误。发生的情况是我收到了发送的消息,但它们完全是空白的,根本没有内容。可能是什么问题?

我先附上前端页面,再附上后端。

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="questions@stylishgoods.com";
$pcount=0;
$gcount=0;
$subject = "A Stylish Goods Enquiry";
$from="DO_NOT_reply@stylishgoods.com";
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);
}
?>

【问题讨论】:

    标签: php email forms hosting contact


    【解决方案1】:

    服务器上可能有 PHP 升级,$HTTP_POST_VARS 已被弃用。 使用$_POST$_GET

    【讨论】:

    • 所以无论写在哪里:- '$HTTP_POST_VARS',我都应该用 '$_POST' 替换,而无论在哪里写 '$HTTP_GET_VARS',我都应该替换为 '$_GET'?
    【解决方案2】:

    你的 php 版本有没有可能发生了变化?在 php5 中,HTTP_POST_VARS 数组不再可用。

    在开始 while 循环之前,您可以尝试以下方法来获取您的值:

    $HTTP_POST_VARS   = !empty($HTTP_POST_VARS)   ? $HTTP_POST_VARS   : $_POST;
    

    【讨论】:

    • 你提到的这一行,我应该将它添加到while循环的上方吗?
    • yepp ,或者在你的源代码中用 $_POST 替换 $HTTP_POST_VARS
    猜你喜欢
    • 2020-10-28
    • 1970-01-01
    • 2018-05-16
    • 1970-01-01
    • 2020-11-25
    • 1970-01-01
    • 2013-09-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多