php联系人表单使用location.href


php contact form using location.href

我已经使用html和php创建了一个联系人表单来发送电子邮件,当用户填写表单时,它只显示空白屏幕

//让我们发送电子邮件。

if(!$error) {
        //$messages="From: $email <br>";
        $messages.="Company Name: $name <br>";
        $messages.="Email: $email <br>";
        $messages.="Message: $message <br>";
        $emailto=$to;
        $mail = mail($emailto,$subject,$messages,"from: $from <$Reply>'nReply-To: $Reply 'nContent-type: text/html");   
        if($mail) {
            $url = 'index.php?page=process&token=101'; 
                        echo "<script language='"javascript'">
                        location.href='"$url'";
                        </script>";
                        exit; 
        }
    } else {
        echo '<div class="error">'.$error.'</div>';
    }
}

想要如果用户输入了所有字段,那么应该将它们发送到index.php吗?page=进程&token=101

试试这个。当您可以在PHP中重定向部分HTML页面时,回显其中包含脚本标记是没有意义的。

header("Location: $url");

试试这个,

echo "<script>
    window.location = '$url';
</script>";

我建议使用header(),而不是java脚本。

在这种情况下,JavaScript的最佳实践是使用php函数进行重定向。试试这个

header("Location: index.php?page=process&token=101");