title: Failed to load resource 405 (Method Not Allowed)
body: <p>//i write a code to send message from form to my gmail but i get the following error failed to load resource the server responded with a status of 405</p>
  <p>//(method not allowed)</p>
  <p><strong>HTML</strong></p>
  <pre><code>&lt;form  class=&quot;contact-form&quot;&gt;
  &lt;input type=&quot;text&quot; name=&quot;&quot; id=&quot;name&quot; /&gt; &lt;br /&gt;
  &lt;input type=&quot;email&quot; name=&quot;&quot; id=&quot;email&quot; /&gt; &lt;br /&gt;
  &lt;input type=&quot;text&quot; name=&quot;&quot; id=&quot;subject&quot; /&gt; &lt;br /&gt;
  &lt;textarea name=&quot;&quot; id=&quot;message&quot; cols=&quot;30&quot; rows=&quot;10&quot;&gt;&lt;/textarea&gt; &lt;br /&gt;
  &lt;input type=&quot;submit&quot; class=&quot;submit&quot; value=&quot;Submit&quot; /&gt;
  &lt;/form&gt;
  </code></pre>
  <p><strong>JS</strong></p>
  <pre><code>  const contactForm = document.querySelector(&quot;.contact-form&quot;);
  let fullName = document.getElementById(&quot;name&quot;);
  let email = document.getElementById(&quot;email&quot;);
  let subject = document.getElementById(&quot;subject&quot;);
  let message = document.getElementById(&quot;message&quot;);
  
   contactForm.addEventListener(&quot;submit&quot;, (e) =&gt; {
     e.preventDefault();
  
  let formData = {
    name: fullName.value,
    email: email.value,
    subject: subject.value,
    message: message.value,
  };
  
  let xhr = new XMLHttpRequest();
  
   xhr.open(&quot;POST&quot;, &quot;/&quot;);
   xhr.setRequestHeader(&quot;content-type&quot;, &quot;application/json&quot;);
  
  
   xhr.onload = function () {
  </code></pre>
  <p><strong>// error happens here</strong><br />
  <strong>console.log(xhr.responseText);</strong></p>
  <pre><code>if (xhr.responseText == &quot;success&quot;) {
    alert(&quot;email sent&quot;);
    fullName.value = &quot;&quot;;
    email.value = &quot;&quot;;
    subject.value = &quot;&quot;;
    message.value = &quot;&quot;;
  } else {
    alert(&quot;Something went wrong!&quot;);
  }
  </code></pre>
  <p>};</p>
  <pre><code> xhr.send(JSON.stringify(formData));
  });
  </code></pre>