我根据本教程制作了一个联系表单:http: //blog.teamtreehouse.com/create-ajax-contact-form
我在我的服务器上使用PHP版本5.3.10-1ubuntu3.4,我遇到http_response_code();了上述链接中的示例教程使用的问题.我http_response_code();只读过PHP 5.4.所以相反,我已经恢复使用header();.
我的表单工作得很好,当我提交时它显示成功消息,而不是我使用时的错误,http_response_code();但我的PHP不是很好,我想知道我所做的是否可以接受或者我应该是以不同的方式做到这一点?如果是这样,请更正我的代码.
这是我的mailer.php文件的内容,你可以看到我已经注释掉http_response_code();并且正在使用它header();.
if ($_SERVER["REQUEST_METHOD"] == "POST") {
// Get the form fields and remove whitespace.
$name = strip_tags(trim($_POST["name"]));
$name = str_replace(array("\r","\n"),array(" "," "),$name);
$email = filter_var(trim($_POST["email"]), FILTER_SANITIZE_EMAIL);
$phone = trim($_POST["phone"]);
$company = trim($_POST["company"]);
$minbudget = trim($_POST["minbudget"]);
$maxbudget = trim($_POST["maxbudget"]);
$message = trim($_POST["message"]);
$deadline = trim($_POST["deadline"]);
$referred = trim($_POST["referred"]);
// Check that data was sent to the mailer.
if ( empty($name) …Run Code Online (Sandbox Code Playgroud) php ×1