title: Contact form not working in wordpress
body: <p>I am trying to create a contact form in php. But the problem I am facing is that when ever I try to submit the form it shows 404 exception rather than the actual file which has the contact form. The theme is custom made. I have added my code below</p>
  
  <pre><code>&lt;?php
  if(isset($_POST)) {
      if(trim($_POST["name"]) === "") {
          $nameError = "Please enter your name.";
          $hasError = true;
      } else {
          $name = trim($_POST["name"]);
      }
  
      if(trim($_POST["email"]) === "")  {
          $emailError = "Please enter your email address.";
          $hasError = true;
      } else if (!preg_match("/^[[:alnum:]][a-z0-9_.-]*@[a-z0-9.-]+\.[a-z]{2,4}$/i", trim($_POST["email"]))) {
          $emailError = "You entered an invalid email address.";
          $hasError = true;
      } else {
          $email = trim($_POST["email"]);
      }
      if(trim($_POST["phone"]) === "")  {
          $phoneError = "Please enter your phone address.";
          $hasError = true;
      } else {
          $phone = trim($_POST["phone"]);
      }
      if(trim($_POST["comments"]) ==="") {
          $commentError = "Please enter a message.";
          $hasError = true;
      } else {
          if(function_exists("stripslashes")) {
              $comments = stripslashes(trim($_POST["comments"]));
          } else {
              $comments = trim($_POST["comments"]);
          }
      }
  
      if(!isset($hasError)) {
          $emailTo = get_option("tz_email");
          if (!isset($emailTo) || ($emailTo == "") ){
              $emailTo = get_option("admin_email");
          }
          $subject = "[PHP Snippets] From ".$name;
          $body = "Name: $name \n\nEmail: $email \n\nPhone:$phone\n\nComments: $comments";
          $headers = "From: ".$name." &lt;".$emailTo."&gt;" . "\r\n" . "Reply-To: " . $email;
  
          wp_mail($emailTo, $subject, $body, $headers);
          $emailSent = true;
      }
  } 
  ?&gt;
  &lt;?php get_header(); ?&gt;
  
  &lt;div class="row" style="margin-top:150px;"&gt;
              &lt;div class="bg-container"&gt;&lt;/div&gt;
              &lt;div class="col-md-4"&gt;
                  &lt;div class="card contact-form-card"&gt;
                      &lt;form action="&lt;?php esc_url(the_permalink());?&gt;" method="post"&gt;
                          &lt;fieldset&gt;
                              &lt;legend&gt;Give us your details&lt;/legend&gt;
                              &lt;div class="form-group label-floating"&gt;
                                &lt;label class="control-label" for="user-name"&gt;Enter your full name&lt;/label&gt;
                              &lt;input class="form-control" id="user-name" name="name" type="text"&gt;
                              &lt;/div&gt;
                              &lt;div class="form-group label-floating"&gt;
                                &lt;label class="control-label" for="user-email"&gt;Enter your email id&lt;/label&gt;
                              &lt;input class="form-control" id="user-email" name="email" type="text"&gt;
                              &lt;/div&gt;
                              &lt;div class="form-group label-floating"&gt;
                                &lt;label class="control-label" for="user-phone"&gt;Enter your phone number&lt;/label&gt;
                              &lt;input class="form-control" id="user-phone" name="phone" type="text"&gt;
                              &lt;/div&gt;
                              &lt;div class="form-group label-floating"&gt;
                                &lt;label class="control-label" for="commenets"&gt;Comments&lt;/label&gt;
                              &lt;textarea class="form-control" id="commenets" name="comments" type="text"&gt;&lt;/textarea&gt;
                              &lt;/div&gt;
                              &lt;button type="submit" name="submit" class="btn btn-primary btn-raised col-xs-12"&gt;Submit&lt;/button&gt;
                          &lt;/fieldset&gt;
                      &lt;/form&gt;
                  &lt;/div&gt;
              &lt;/div&gt;
  
              &lt;div class="col-md-8"&gt;
                  &lt;h1 class="text-center"&gt;We are currently maintaining over 1000 properties in north Bangalore&lt;/h1&gt;
              &lt;div class="owl-carousel"&gt;
                &lt;div class="item card"&gt;
                  &lt;p class="statement"&gt;"Poorna is an immaculate real estate consulting professional, and possess several unique skills up his sleeves like property consulting report writing that are rare to find in a professional framework."&lt;/p&gt;
                          &lt;p class="by"&gt;Shariq Saleem, Director, Armchair Solutions India&lt;/p&gt;
                &lt;/div&gt;
                &lt;div class="item card"&gt;
                  &lt;p class="statement"&gt;"Square Capital Assets understands your needs clearly and they are very easy to work with. Once they taken over managing my property, it was a smooth ride"&lt;/p&gt;
                          &lt;p class="by"&gt;Manoj&lt;/p&gt;
                &lt;/div&gt;
              &lt;/div&gt;
              &lt;/div&gt;
              &lt;/div&gt;
                  &lt;div class="row" style="margin-top:15px;"&gt;
                      &lt;div class="col-sm-2"&gt;
                          &lt;div class="col-xs-12 feature-tile text-center"&gt;
                              &lt;img src=&lt;?php echo get_template_directory_uri()."/img/sign_the_agreement.png";?&gt; alt="Sign the agreement"&gt;
                              &lt;h5&gt;Sign with us&lt;/h5&gt;
                          &lt;/div&gt;
                      &lt;/div&gt;
                      &lt;div class="col-sm-2"&gt;
                          &lt;div class="col-xs-12 feature-tile text-center"&gt;
                              &lt;img src=&lt;?php echo get_template_directory_uri()."/img/choose_your_tenants.png";?&gt; alt="Choose your tenants"&gt;
                              &lt;h5&gt;We will find reliable tenants.&lt;/h5&gt;
                          &lt;/div&gt;
                      &lt;/div&gt;
                      &lt;div class="col-sm-2"&gt;
                          &lt;div class="col-xs-12 feature-tile text-center"&gt;
                              &lt;img src=&lt;?php echo get_template_directory_uri()."/img/collect_security_deposit.png";?&gt; alt="Collect Security Deposit"&gt;
                              &lt;h5&gt;Rental Agreement&lt;/h5&gt;
                          &lt;/div&gt;
                      &lt;/div&gt;
                      &lt;div class="col-sm-2"&gt;
                          &lt;div class="col-xs-12 feature-tile text-center"&gt;
                              &lt;img src=&lt;?php echo get_template_directory_uri()."/img/rent_assured.png";?&gt; alt="Rent Assured"&gt;
                              &lt;h5&gt;Collecting rent and keeping your home safe&lt;/h5&gt;
                          &lt;/div&gt;
                      &lt;/div&gt;
                      &lt;div class="col-sm-2"&gt;
                          &lt;div class="col-xs-12 feature-tile text-center"&gt;
                              &lt;img src=&lt;?php echo get_template_directory_uri()."/img/repairs_under_2000.png";?&gt; alt="Repairs Under Rs.2,000"&gt;
                              &lt;h5&gt;Regular check up and maintenance&lt;/h5&gt;
                          &lt;/div&gt;
                      &lt;/div&gt;
                      &lt;div class="col-sm-2"&gt;
                          &lt;div class="col-xs-12 feature-tile text-center"&gt;
                              &lt;img src=&lt;?php echo get_template_directory_uri()."/img/property_tax.png";?&gt; alt="Property Taxes?"&gt;
                              &lt;h5&gt;Managing taxes and bills&lt;/h5&gt;
                          &lt;/div&gt;
                      &lt;/div&gt;
          &lt;/div&gt;
  
  
  &lt;?php get_footer(); ?&gt;
  </code></pre>