On my website, I use a contact form, which causes me a lot of trouble. I already spent some time on actually getting the mail() PHP function working on 64bit Debian with exim4, but I finally did it, and mails are sent.
Now I am experiencing another problem, which I can’t figure out how to solve. First of all the code.
<?php
$your_email = 'blahblah@gmail.com';
session_start();
$errors = '';
$name = '';
$visitor_email = '';
$user_message = '';
if (isset($_POST['submit'])) {
$name = $_POST['name'];
$visitor_email = $_POST['email'];
$user_message = $_POST['message'];
///------------Do Validations-------------
if (empty($name) || empty($visitor_email)) {
$errors .= "\n Name and Email are required fields. ";
}
if (IsInjected($visitor_email)) {
$errors .= "\n Bad email value!";
}
if (empty($_SESSION['6_letters_code']) || strcmp($_SESSION['6_letters_code'], $_POST['6_letters_code']) != 0) {
//Note: the captcha code is compared case insensitively.
//if you want case sensitive match, update the check above to
// strcmp()
$errors .= "\n The captcha code does not match!";
}
if (empty($errors)) {
//send the email
$to = $your_email;
$subject = "New form submission";
$from = $your_email;
$body = "A user $name submitted the contact form:\n" . "Name: $name\n" . "Email: $visitor_email \n" . "Message: \n " . "$user_message\n";
$headers = "From: $from \r\n";
$headers .= "Reply-To: $visitor_email \r\n";
if (mail($to, $subject, $body, $headers)) {
header('Location: http://www.lolstreamgallery.net/thank-you.html');
} else {
$errors .= "\n E-Mail coulnd be sent!";
}
}
}
The problem is that that the header redirection is not working. The mail() does work, so the header should be executed. When I test the file locally, the redirection does occur.
If you wanna test the contact form, you can do it here.
Here is the whole file code:
EDIT2:
I’m now using the function of Ian Brindley which made the redirect work, but not the header function. It seems there is some output before the header.
At first glance I cannot see any output before the header() call.
If there is no better alternative, here is a function I found a while ago which I now user for pretty much all of my redirects.
I know the non server side redirect is not ideal.