如果满足条件,我想重定向到网页。
如果不满足条件,我已经使用meta来重定向了。
<meta http-equiv="refresh" content="4; url=form3.html" />
<?php
$to = "example@example.at";
$subject = "School Info";
$headers = "From: Free Project Day";
$field_school = $_POST['school'];
$field_email = $_POST['email'];
$date = date('d/m/Y');
$forward = "1";
$forward2 ="0";
$location = "index.html";
if (empty($field_school) || empty($field_email) && empty($field_tel) ) {
echo 'Please correct the fields';
return false;
if ($forward == 1) {
header ("Location:$location");
}
}
$msg = "TEXT $date.'n'n";
foreach ($_POST as $key => $value) {
$msg .= ucfirst ($key) ." : ". $value . "'n";
}
mail($to, $subject, $msg, $headers);
if ($forward2 == 1) {
header ("Location:$location");
}
else {
echo ("TEXT>");
}
?>
我尝试使用$forward,但它不起作用。不使用Meta或$forward重定向的其他方法吗?
谢谢
检查这是否符合您发布的代码。我只做了一些修改。检查是否所有条件都如您所愿
if ((empty($field_school) || empty($field_email)) && empty($field_tel) )
{
echo 'Please correct the fields';
//return false; No need for this as there's not function here
if ($forward == 1)
{
header('refresh:4;url='.$location);
exit();
}
}
$msg = "TEXT $date.'n'n";
foreach ($_POST as $key => $value)
{
$msg .= ucfirst ($key) ." : ". $value . "'n";
}
mail($to, $subject, $msg, $headers);
if ($forward2 == 1)
{
header('refresh:4;url='.$location);
exit();
}
else {
echo "your messages here";
}
After:
header ("Location:$location");
您需要添加exit();
header ("Location:$location");
exit();