php - Contact form redirecting to page not found on send

admin2025-06-03  0

I have a contact form that I used lot's of times before on other non WP sites but it doesn't seem to work on my current WP site, it just redirects you to a page not found.

I don't want to use any plugins to create it.

Here's the code:

<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 = "[email protected]";
$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>

I have a contact form that I used lot's of times before on other non WP sites but it doesn't seem to work on my current WP site, it just redirects you to a page not found.

I don't want to use any plugins to create it.

Here's the code:

<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 = "[email protected]";
$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>
Share Improve this question asked Jun 15, 2011 at 12:59 RobRob 1,42613 gold badges41 silver badges68 bronze badges 3
  • 3 try changing the field named name="name" to something else. – Bainternet Commented Jun 15, 2011 at 13:12
  • Brilliant, thanks. Frustrating when it's something so simple!! p.s I can't mark you as answered. – Rob Commented Jun 15, 2011 at 13:18
  • added it as an answer so you could mark this question as answered. – Bainternet Commented Jun 15, 2011 at 14:12
Add a comment  | 

1 Answer 1

Reset to default 25

When dealing with forms you need to make sure that your form doesn't have a few specific filed names like: name,day,month,year and I'm sure that a few more, so make your form fields names more specific like: contact_name,contact_day,contact_month,contact_year.

in your case change name="name" to anything else.

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1748882823a314512.html

最新回复(0)