Good day all,
Well, my problem is:
When I click submit on my contact form, I want it to send the email (which i’ve managed to do) but then at the end of the php I want it to go back to the page it came from. Or the REFERER.
So I have this code:
[php]//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']);
}[/php]
But I get this response when submitting the form. Which, I understand, it isn’t able to execute due to the location already being set at a point before this request.
Notice: Undefined index: HTTP_X_REQUESTED_WITH in /customers/3/8/a/care2pets.co.uk/httpd.www/enquiry.php on line 29 Warning: Cannot modify header information - headers already sent by (output started at /customers/3/8/a/care2pets.co.uk/httpd.www/enquiry.php:29) in /customers/3/8/a/care2pets.co.uk/httpd.www/enquiry.php on line 31Here's the full code snippet. [php] <?php
$ipaddress = $_SERVER['REMOTE_ADDR'];
$date = date('d/m/Y');
$time = date('H:i:s');
error_reporting(E_ALL);
ini_set('error_reporting', E_ALL);
ini_set('display_errors',1);
$name = $_POST['name'];
$telephone = $_POST['telephone'];
$email = $_POST['email'];
$location = $_POST['location'];
$enquiry = $_POST['enquiry'];
$from = 'From: '.$email;
$to = '[email protected]';
$subject = 'Care2Pets Website Enquiry';
$message = "From: $name\n E-Mail: $email\n Telephone: $telephone\n Location: $location\n Message:\n $enquiry\n This message was sent from the IP Address: {$ipaddress} on {$date} at {$time}";
$headers = 'From: [email protected]' . "\r\n" .
'Reply-To: [email protected]' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
if (!empty($_POST['name'])) {
mail ($to, $subject, $message, $from);
}
//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']);
}
?>
[/php]
Any help or other solutions would be greatly appreciated…