php表单上的标题重定向无法正常工作

时间:2016-12-22 16:15:44

标签: php html forms redirect

我是PHP新手,只需要这个表单。我让它早点工作,但现在它决定不工作。非常感谢任何帮助。

PHP部分,标题转到同一目录中的页面

.html

和我在引导程序中的HTML。

<!-- PHP Form E-mailer -->

        <?php
    if (isset($_POST["submit"])) {
        $name = $_POST['name'];
        $phone = $_POST['phone'];
        $message = $_POST['message'];
        $from = 'Very Local';
        $to = 'myemail@gmail.com'; // BUSINESS EMAIL ADDRESS
        $subject = 'Message from Very Local';

        $body ="From: $name\n Number: $phone\n Message:\n $message";
        // Check if name has been entered
        if (!$_POST['name']) {
            $errName = 'Please enter your name';
        }

        // Check if email has been entered and is valid
        if (!$_POST['phone'] || !filter_var($_POST['phone'])) {
            $errphone = 'Please enter a valid phone number';
        }

        //Check if message has been entered
        if (!$_POST['message']) {
            $errMessage = 'Please enter your message';
        }

// If there are no errors, send the email
if (!$errName && !$errPhone && !$errMessage) {
    if (mail ($to, $subject, $body, $from)) {
         header("Location: success.html");
    } else {
        header("Location: fail.html");
    }
}
    }
?>

表单发送正常但重定向不起作用。

提前致谢。

1 个答案:

答案 0 :(得分:1)

尝试在标题重定向后添加退出;