[英]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
; 提交表单后,页面不会重定向到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 = "pixiedustmed@yahoo.com";
$msg = "Please fill in the required fields*";
$to = 'pixiedustmed@yahoo.com';
$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: avedis@avedis.ga\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... 这是我的网页: Avedis.Ga ,在页面的最后尝试一下,让我知道您对设计和所有内容的看法。
Your $name
, $surname
and $email
variables are always null at the moment of checking whether to redirect, or not. 在检查是否重定向时, $name
, $surname
和$email
变量始终为null。
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. 另外,我不建议您在Web的文件名中使用空格。
header('Location: COMINGSOON.html');
不要在文件名中使用空格!
The page of redirect can't have blank space. 重定向页面不能有空格。 Also you should do an exit() after header: 另外,您还应该在标头之后执行exit():
if(empty($name) || empty($surname) || empty($email)){
return false;
} else {
header('Location: COMING_SOON.html');
exit();
}
您需要对重定向进行URL编码,否则地址中的空格将不起作用:
header('Location: COMING%20SOON.html');
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.