PHP URL重定向

PHP URL重定向,php,forms,url,Php,Forms,Url,我在本地的一个网站上工作,我正在尝试向它添加一个联系人表单 我在http:localhost:8888/testsite/contact.php上添加了一个简单的表单,当用户单击submit按钮时,我希望他们被重定向到另一个带有消息的页面。我希望用户在提交表单后进入的页面:contact\u message.php 我已经创建了这两个文件,它们在url上都显示OK-http:localhost:8888/testsite/contact.php和http:localhost:8888/tests

我在本地的一个网站上工作,我正在尝试向它添加一个联系人表单

我在http:localhost:8888/testsite/contact.php上添加了一个简单的表单,当用户单击submit按钮时,我希望他们被重定向到另一个带有消息的页面。我希望用户在提交表单后进入的页面:
contact\u message.php

我已经创建了这两个文件,它们在url上都显示OK-
http:localhost:8888/testsite/contact.php
http:localhost:8888/testsite/contact message.php
但是表单不起作用,因为当您单击submit时url更改为:
http:localhost:8888/testsite/contact.php/contact message.php
,如果它显示
contact message.php
内容就可以了,但是它没有

表格前的代码为:

<form method="post" action="contact-message.php">
    <table>
        <tr>
            <th>
                <label for="name">Name</label>
            </th>
            <td>
                <input type="text" name="name" id="name">
            </td>
        </tr>
        <tr>
            <th>
                <label for="email">Email</label>
            </th>
            <td>
                <input type="text" name="email" id="email">
            </td>
        </tr>
        <tr>
            <th>
                <label for="message">Message</label>
            </th>
            <td>
                <textarea type="text" name="message" id="message"></textarea>
            </td>
        </tr>

    </table>

    <input type="submit" value="Send">

</form>

名称
电子邮件
消息

有人有什么想法吗?

如果发送邮件功能返回true,请尝试使用此代码:

标题(“位置:http://localhost:8888/testsite/contact_message.php");

PHP标题文档:

尝试将表单标记替换为:

<form method="post" action="./contact-message.php">


这将调用位于同一文件夹中的contact-message.php文件。点是从当前位置开始的相对路径的起点

您需要在表单操作中将完整路径或相对路径添加到正确的文件中。目前,您正在告诉表单提交到当前url和contact-message.php。相反,尝试

<form method="post" action="http:localhost:8888/testsite/contact-message.php">

或者干脆

<form method="post" action="/contact-message.php">


这告诉它使用基本URL+/contact-message.php

您确定contact-message.php脚本实际工作吗?语法错误可能会在执行任何输出之前终止脚本,使您的浏览器处于空白状态。e、 g.自己做一些基本的调试…如果我使用:
,那么url就变成了
http://localhost:8888/contact-message.php
而不是
http://localhost:8888/testsite/contact-message.php
我无法知道您的基本url是localhost:8888还是localhost:8888/testsite,因为可以配置其中一个。在这种情况下,您只需将其更改为action=“/testsite/contact message.php”