私の 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);
}
}
?>