title: Trying to send an email with PHP from HTML form resulting in an HTTP Error 405
body: <p>So I wanted to make a contact form for a website that can actually send emails, but ended up with this error : <a href="https://i.stack.imgur.com/UWRwY.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/UWRwY.png" alt="error" /></a></p>
  <p>Here's my html code:</p>
  <pre><code>&lt;div class=&quot;contact-fast&quot;&gt;
        &lt;div class=&quot;contact-form&quot;&gt;
          &lt;form id=&quot;contact-form&quot; method=&quot;POST&quot; action=&quot;contact-form-handler.php&quot;&gt;
            &lt;input name=&quot;name&quot; type=&quot;text&quot; class=&quot;form-control&quot; placeholder=&quot;Your Name&quot; required&gt; &lt;br&gt;
            &lt;input name=&quot;email&quot; type=&quot;email&quot; class=&quot;form-control&quot; placeholder=&quot;Your Email&quot; required&gt; &lt;br&gt;
            &lt;textarea name=&quot;message&quot; class=&quot;form-control&quot; placeholder=&quot;Message&quot; rows=&quot;8&quot; required&gt;&lt;/textarea&gt; &lt;br&gt;
            &lt;input type=&quot;submit&quot; class=&quot;form-control submit&quot; value=&quot;SEND MESSAGE&quot;&gt;
  
          &lt;/form&gt;
        &lt;/div&gt;
      &lt;/div&gt;
  </code></pre>
  <p>And here's my PHP code:</p>
  <pre><code>    &lt;?php 
  
    $name = $_POST['name'];
    $visitor_email = $_POST['email'];
    $message = $_POST['message'];
  
    $email_from = 'skeremobiel@gmail.com';
  
    $email_subject = 'New Mail From Website';
  
    $email_body = &quot;Username: $name.\n&quot;.
                  &quot;User Email: $visitor_email.\n&quot;.
                  &quot;User Message: $message.\n&quot;;
  
    
    $to = &quot;said444b@gmail.com&quot;;
    $headers = &quot;From: $email_from \r\n&quot;;
    $headers .= &quot;Reply-To: $visitor_email \r\n&quot;;
  
  
    if ($visitor_email!=NULL) {
      mail($to,$email_subject,$email_body,$headers);
    }
    
  
    header(&quot;Location: http://127.0.0.1:5500/social.html&quot;);
    die()
    
  
  ?&gt;
  </code></pre>
  <p>Here's how my page looks like before and after submitting the form:</p>
  <p><a href="https://i.stack.imgur.com/CRZvy.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/CRZvy.png" alt="page before submitting" /></a></p>
  <p><a href="https://i.stack.imgur.com/VlK3q.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/VlK3q.png" alt="page after submitting" /></a></p>
  <p>I think the problem is that when i click on the submit button i get directed to 127.0.0.1:5500/contact-form-handler.php (as you can see in the last image in my question). It doesn't execute the php file, but it just opens it.
  Any help would be appreciated!</p>