Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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 = "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>
share|improve this question
2  
try changing the field named name="name" to something else. –  Bainternet Jun 15 '11 at 13:12
    
Brilliant, thanks. Frustrating when it's something so simple!! p.s I can't mark you as answered. –  Rob Jun 15 '11 at 13:18
    
added it as an answer so you could mark this question as answered. –  Bainternet Jun 15 '11 at 14:12

1 Answer 1

up vote 7 down vote accepted

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.