Reputation: 45
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: </p> </td><td>" . strip_tags($_POST['name']) . "</td></tr>";
$message .= "<tr style='background: #eee;'><td><p style='color: #2c3e50; font-weight:bold'>Surname: </p> </td><td>" . strip_tags($_POST['last_name']) . "</td></tr>";
$message .= "<tr style='background:#2ecc71;'><td><p style='color: #2c3e50; font-family: Calibri;'>Subject: </p> </td><td style='font-family:Calibri;'>" . strip_tags($_POST['subject']) . "</td></tr>";
$message .= "<tr><td><p style='color: #2c3e50; font-weight:bold'>Email: </p> </td><td>" . strip_tags($_POST['email']) . "</td></tr>";
$message .= "<tr style='background: #71bdf4;'><td><p style='color: #ffffff'>Message: </p> </td><td>" . strip_tags($_POST['message']) . "</td></tr>";
$message .= "<tr style='background: #34495e;'><td><p style='color: #ffffff'>Consultation Info: </p> </td><td style='color: #ffffff'>" . strip_tags($_POST['cons']) . "</td></tr>";
$message .= "<tr><td><p style='color: #2c3e50; font-weight:bold'>Password: </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
Reputation: 676
header('Location: COMINGSOON.html');
Don't use whitespace in your file name!
Upvotes: 0
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
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
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