簡體   English   中英

PHP:表單提交后,頁眉不會重定向頁面

[英]PHP: Header doesn't redirect page after form submit

我的代碼有什么問題? 提交表單后,頁面不會重定向到COMING SOON.html 而是顯示空白。 並且該頁面存在!

<?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:&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!");
?>

這是我的網頁: Avedis.Ga ,在頁面的最后嘗試一下,讓我知道您對設計和所有內容的看法。

在檢查是否重定向時, $name$surname$email變量始終為null。

這個

$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的文件名中使用空格。

header('Location: COMINGSOON.html');

不要在文件名中使用空格!

重定向頁面不能有空格。 另外,您還應該在標頭之后執行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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM