Support » Fixing WordPress » Contact Form 404 Error

  • Resolved skunkbad


    I have a simple contact form, and it could send email before my WP installation. The site didn’t used to be a WP site.

    The contact form is on the contact page, and the action of the form is set to ../send_email.

    I get a 404 error when I get to the send_email page, but only if the script checks or tries to get anything from the $_POST array. I need help, because I can’t go to sleep until I get this working, and it’s 2:21AM!

    I have this on page.php:

    if(is_page('send_email') && !empty($_POST))
    		$to = '';
    		$from = (empty($_POST['email']))? '':$_POST['email'];
    		$message = (!isset($_POST['message']))? 'Request For More Information':$_POST['message'];
    		$headers = "From: $from\r\n";
    		$headers .= "Reply-To: $from\r\n";
    		$headers .= "Return-Path: $from\r\n";
    		$headers .= "X-Mailer: PHP mail on\r\n";
    		$message = "
    		Name: {$_POST['name']}
    		Phone: {$_POST['phone']}
    		Email: {$_POST['email']}
    		$success = mail($to,'Contact From Website',$message,$headers);

Viewing 7 replies - 1 through 7 (of 7 total)
  • esmi


    Forum Moderator

    Have you considered using a contact form plugin instead?

    Secure, Accessible Contact Form

    Contact Form 7



    Actually, the contact form plugins seem pretty restrictive, and I came up with a super easy solution to my problem. It doesn’t get any easier:

    1) Change action of form to outside WordPress
    2) Process the $_POST array and redirect user back into WordPress

    The .htaccess file in the root directory specifies that files that ARE located in the root directory, or directories that are located in the root directory, are accessible without being pushed through index.php

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d

    This was the key to setting up the form processing script. It just had to be located in the root directory. Simple, and because I’m not a WordPress genius, I did it with standard PHP. The sad thing is, it was so late at night when I was trying to figure this out, that I was losing sleep due to my foggy headedness.

    It was pretty amazing to see that this is a fairly common problem among WordPress users. A simple search through the forum for “$_POST problem” or similar will show this, but an easy solution is never offered, or at least not that I could find. This is the solution as far as I’m concerned. I’m not sure what WordPress is doing to the $_POST array, but I’m imagining that it has something to do with security.

    I am aware that this is resolved, but there may be a more simple solution to this issue.

    I too decided to make my own form class in my theme, for extendability. I had this exact same issue, and then worked it out:

    Do not use the value ‘name’ as a value for the name attribute in a form field. So, if you have an input tag that has name=”name”, try instead using something like name=”username”…

    Having changed that, by 404 errors disappeared on validation…


    @spankmarvin is a genius. Works like a charm.

    +1 SpankMarvin is a genius. I had a “name” problem too. Thought I was gonna go nuts.

    @spankmarvin Thank you thank you thank you!!!

    I spent two days trying to solve this error and even did a clean wordpress install until I found this thread. Bless your heart, SpankMarvin!

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Contact Form 404 Error’ is closed to new replies.