My PHP code always returns HTTP/1.1 500 internal server error. This is being accessed from some AJAX code, and is a serperate file. It is most likely something obvious, any help would be appreciated. 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("[email protected]","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);
}
}
?>
There is probably a php error. Put this to the header of your php file for seeing the error:
ini_set('display_errors', 1);
error_reporting(E_ALL);
Thanks to @bwoebi I can add that exactly in the case of parse errors to display the error text instead of 500 error you should put this to your .htaccess:
php_flag display_errors 1
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With