gpt4 book ai didi

PHP 表单给出内部错误

转载 作者:可可西里 更新时间:2023-11-01 00:46:32 28 4
gpt4 key购买 nike

我的 PHP 代码总是返回 HTTP/1.1 500 内部服务器错误。这是从一些 AJAX 代码访问的,是一个 serperate 文件。这很可能是显而易见的事情,我们将不胜感激。PHP:

<?php  
if( isset($_POST) ){

//form validation vars
$formok = true;
$errors = array();

//submission data
$ipaddress = $_SERVER['REMOTE_ADDR'];
$date = date('d/m/Y');
$time = date('H:i:s');

//form data
$fname = $_POST['fname'];
$lname = $_POST['lname'];
$aemail = $_POST['aemail'];
$year = $_POST['year'];
$position = $_POST['position'];
$club = $_POST['club'];

//validate email address is not empty
if(empty($email)){
$formok = false;
$errors[] = "You have not entered an email address";
//validate email address is valid
}elseif(!filter_var($aemail, FILTER_VALIDATE_EMAIL)){
$formok = false;
$errors[] = "You have not entered a valid email address";
}

//send email if all is ok
if($formok){
$headers = "From: " $aemail . "\r\n";
$headers = "Reply-To: " . $email_from . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

$emailbody = "<p>You have received a new message from the enquiries form on your website.</p>
<p><strong>First Name: </strong> {$fname} </p>
<p><strong>Last Name: </strong> {$fname} </p>
<p><strong>Email Address: </strong> {$email} </p>
<p><strong>School Year: </strong> {$year} </p>
<p><strong>Club: </strong> {$club} </p>
<p><strong>Position: </strong> {$position} </p>
<p>This message was sent from the IP Address: {$ipaddress} on {$date} at {$time}</p>";

ini_set("sendmail_from", $email_from);

$sent = mail("name@domaain.co.uk","New Enquiry",$emailbody,$headers, "-f" . $email_from);

}

//what we need to return back to our form
$returndata = array(
'posted_form_data' => array(
'fname' => $fname,
'lname' => $fname,
'aemail' => $aemail,
'year' => $year,
'position' => $position,
'club' => $club
),
'form_ok' => $formok,
'errors' => $errors
);


//if this is not an ajax request
if(empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) !== 'xmlhttprequest'){
//set session variables
session_start();
$_SESSION['cf_returndata'] = $returndata;

//redirect back to form
header('location: ' . $_SERVER['HTTP_REFERER'].' 500 Internal Server Error', true, 500);
}
}
?>

最佳答案

可能是 PHP 错误。把它放到你的 php 文件的标题中以查看错误:

ini_set('display_errors', 1);
error_reporting(E_ALL);

感谢@bwoebi,我可以准确地在解析错误的情况下添加显示错误文本而不是 500 错误,你应该把它放到你的 .htaccess 中:

php_flag display_errors 1

关于PHP 表单给出内部错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17135903/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com