Contact form redirecting to page not found on send

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.

Read More

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 = "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,nn You have an enquiry from the website, please see the details below:nn Name: $name_fieldn Company Name: $companyname_fieldn E-Mail: $email_fieldn Tel: $tel_fieldn Message:n $enquiry_fieldnn Please reply to the enquiry asap.nn Kind Regards n The Teamworks Website";

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

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

} ?>
</form>

Related posts

Leave a Reply

1 comment

  1. 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.