我的代码有什么问题?
提交表单后,页面不会重定向到COMING SOON.html
;相反,它只显示BLANK。那个apage存在!
<?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!");
?>
这是我的网页:Avedis.Ga,请在页面的最末端自行尝试,让我知道您对设计的看法以及所有内容......
答案 0 :(得分:3)
在检查是否重定向时,您的$name
,$surname
和$email
变量始终为空。
此
$name = $_POST['name'];
$surname = $_POST['last_name'];
$email = $_POST['email'];
应该在此之前
if (empty($name) || empty($surname) || empty($email)){
return false;
} else {
header('Location: COMING SOON.html');
}
另外,我不建议你在web文件名中使用空格。
答案 1 :(得分:0)
header('Location: COMINGSOON.html');
不要在文件名中使用空格!
答案 2 :(得分:0)
重定向页面不能有空格。你也应该在标题之后做一个exit():
if(empty($name) || empty($surname) || empty($email)){
return false;
} else {
header('Location: COMING_SOON.html');
exit();
}
答案 3 :(得分:0)
您需要对您的重定向进行URL编码,或者地址中的空格无法正常工作:
header('Location: COMING%20SOON.html');