У меня есть контактная форма на сайте, которая работала, но поскольку последние несколько месяцев перестали работать должным образом. Это могло быть связано с некоторой ошибкой кодирования, которую я не могу понять. Случается, что я получаю отправленные сообщения, но они полностью пусты, без содержимого. Какие могут быть проблемы?
Сначала я привязываюсь к первой странице, а затем к серверной части.
Пример 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 /* 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 /* 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, а $HTTP_POST_VARS
устарели. Для них используйте $_POST
и $_GET
.
возможно ли, что ваша версия php изменилась? В php5 массив HTTP_POST_VARS больше не доступен.
Вы можете попробовать следующее получить свои значения до начала цикла while:
$HTTP_POST_VARS = !empty($HTTP_POST_VARS) ? $HTTP_POST_VARS : $_POST;