联系人表单重定向到发送时找不到的页面


16

我以前在其他非WP网站上使用过很多次联系表格,但在我当前的WP网站上似乎不起作用,它只是将您重定向到未找到的页面。

我不想使用任何插件来创建它。

这是代码:

<form class="form" method="POST" action="<?php the_permalink(); ?>">
    <table border="0" style="float:left;">
        <tbody>
            <tr>
                <td>
                <p>Company Name:</p>
                </td>
                <td>&nbsp;</td>
                <td><input type="text" name="companyname" id="companyname" /></td>
            </tr>
            <tr>
                <td>
                <p>Your Name:</p>
                </td>
                <td>&nbsp;</td>
                <td><input type="text" name="name" id="name" /></td>
            </tr>
            <tr>
                <td>
                <p>E-mail:</p>
                </td>
                <td>&nbsp;</td>
                <td><input type="text" name="email" id="email" /></td>
                <td colspan="2">&nbsp;</td>
            </tr>
            <tr>
                <td>
                <p>Telephone:</p>
                </td>
                <td>&nbsp;</td>
                <td><input type="text" name="tel" id="tel" /></td>
                <td colspan="2">&nbsp;</td>
            </tr>
        </tbody>
    </table>

    <table border="0" style="float:left;" width="450">
        <tbody>
            <tr>
                <td valign="top"><p style="margin-left:42px;margin-right:10px;margin-top:7px;">Enquiry:</p></td>
                <td><textarea name="enquiry"></textarea></td>
            </tr>
            <tr>
                <td colspan="2"><button class="blue medium awesome awesomeforward" type="submit" name="submit">Send message</button></td>
            </tr>
        </tbody>
    </table>        

<? if(isset($_POST['submit'])) { 

$to = "rob@teamworksdesign.com";
$subject = "Teamworks contact enquiry";
$companyname_field = $_POST['companyname'];
$name_field = $_POST['name'];
$email_field = $_POST['email'];
$tel_field = $_POST['tel'];
$enquiry_field = $_POST['enquiry'];


$body = "Hello Teamworks,\n\n You have an enquiry from the website, please see the details below:\n\n Name: $name_field\n Company Name: $companyname_field\n E-Mail: $email_field\n Tel: $tel_field\n Message:\n $enquiry_field\n\n Please reply to the enquiry asap.\n\n Kind Regards \n The Teamworks Website";

mail($to, $subject, $body);

echo "</br>Thank you for getting in touch, we will contact you shortly.";

} ?>
</form>

3
尝试将命名字段更改为name="name"其他名称。
Bainternet 2011年

太好了,谢谢。简单到令人沮丧的时候!!ps我无法将您标记为已回答。
罗布

将其添加为答案,以便您可以将此问题标记为已回答。
Bainternet 2011年

Answers:


25

在处理表单时,您需要确保表单中没有几个特定的​​文件名,例如:name,day,month,year,而我确定还有更多特定的文件名,因此,使您的表单字段名称更具体,例如: contact_name,contact_day,contact_month,contact_year。

在您的情况下,请更改name="name"为其他任何内容。

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.