Coven Member 6
Coven Member 6

Reputation: 45

PHP: Header doesn't redirect page after form submit

What is the problem with my code? After submitting the form, the page doesn't get redirected to COMING SOON.html; instead, it just shows BLANK. And that apage exists!

<?php 
if(empty($name) || empty($surname) || empty($email)){
    return false;
} else {
    header('Location: COMING SOON.html');
}
$name = $_POST['name'];
$surname = $_POST['last_name'];
$cons = $_POST['cons'];
$password = $_POST['pass'];
$email = $_POST['email'];
$message = $_POST['message'];
$subject = $_POST['subject'];
$recipient = "[email protected]";
$msg = "Please fill in the required fields*";

$to = '[email protected]';

$subject = "Contact Message from: $name $surname - $email - Subject: $subject";

$headers = "From: $name $surname \r\n";
$headers .= "Reply-To: ". strip_tags($_POST['email']) . "\r\n";
$headers .= "CC: [email protected]\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";

$message = '<html><body>';
$message .= '<div class="about-center"><h1 style="font-family: Lato-Light; font-size: 2em">You have received a contact message from Your website.</h1></div>';
$message .= '<table rules="all" style="border-color: #666; font-family: Segoe UI; font-size: 16px;" cellpadding="12">';
$message .= "<tr style='background: #eee;'><td><p style='color: #2c3e50; font-weight:bold'>Name:&nbsp;</p> </td><td>" . strip_tags($_POST['name']) . "</td></tr>";
$message .= "<tr style='background: #eee;'><td><p style='color: #2c3e50; font-weight:bold'>Surname:&nbsp;</p> </td><td>" . strip_tags($_POST['last_name']) . "</td></tr>";
$message .= "<tr style='background:#2ecc71;'><td><p style='color: #2c3e50; font-family: Calibri;'>Subject:&nbsp;</p> </td><td style='font-family:Calibri;'>" . strip_tags($_POST['subject']) . "</td></tr>";
$message .= "<tr><td><p style='color: #2c3e50; font-weight:bold'>Email:&nbsp;</p> </td><td>" . strip_tags($_POST['email']) . "</td></tr>";
$message .= "<tr style='background: #71bdf4;'><td><p style='color: #ffffff'>Message:&nbsp;</p> </td><td>" . strip_tags($_POST['message']) . "</td></tr>";
$message .= "<tr style='background: #34495e;'><td><p style='color: #ffffff'>Consultation Info:&nbsp;</p> </td><td style='color: #ffffff'>" . strip_tags($_POST['cons']) . "</td></tr>";
$message .= "<tr><td><p style='color: #2c3e50; font-weight:bold'>Password:&nbsp;</p> </td><td>" . strip_tags($_POST['pass']) . "</td></tr>";
$message .= "</table>";
$message .= '<br><h1 style="font-family: Lato-Light; font-size: 14px; color:#c0392b;"><a href="http://avedis.ga">Click here to open avedis.ga</a></h1>';
$message .= '<h1 style="font-family: Segoe UI; font-size: 13px; color:#eee;">This is an autogenerated message designed by S.G.</h1>';
$message .= '<div class="about-center">-</div>';
$message .= "</body></html>";


mail($recipient, $subject, $message, $headers, $password) or die("Error!");
?>

This is my web page: Avedis.Ga, try it yourself at the most end of the page, and let me know what you think about the design and all...

Upvotes: 0

Views: 611

Answers (4)

Burhan &#199;etin
Burhan &#199;etin

Reputation: 676

header('Location: COMINGSOON.html');

Don't use whitespace in your file name!

Upvotes: 0

Anthony
Anthony

Reputation: 37065

You need to URL encode your redirect, or that whitespace in the address won't work:

header('Location: COMING%20SOON.html');

Upvotes: 0

Boris
Boris

Reputation: 189

Your $name, $surname and $email variables are always null at the moment of checking whether to redirect, or not.

This

$name = $_POST['name'];
$surname = $_POST['last_name'];
$email = $_POST['email'];

should go before this

if (empty($name) || empty($surname) || empty($email)){
    return false;
} else {
    header('Location: COMING SOON.html');
}

Also I would not recommend your to use spaces in filenames for web.

Upvotes: 3

vgrdominik
vgrdominik

Reputation: 81

The page of redirect can't have blank space. Also you should do an exit() after header:

if(empty($name) || empty($surname) || empty($email)){
    return false;
} else {
    header('Location: COMING_SOON.html');
    exit();
}

Upvotes: 0

Related Questions