title: Send PHP mail on html button click using JavaScript onClick then redirect to new html page
body: <p>I am trying to send an email when an html button is clicked then redirect to an html confirmation page. All my code is in the same php file except for the confirmation page. It redirects with no problem just doesn't send email on button click. It was working at one point but it would send the email as soon as the page loaded. I've searched the internet for days and here is what I'm currently trying:</p>
  
  <pre><code>&lt;form action="confirm.html" method="post" name= "confirm"&gt;
  &lt;?php
  
  echo('&lt;input type="button" value="Submit" onclick="this.form.submit();"&gt;');
  
  ?&gt;
  &lt;/form&gt;
  
  &lt;?php
  
  $to="mail@hello.com";
  $subject= "New Application";
  $message= "Name: ".$Name;
  $headers= "";
  mail($to, $subject, $message, $headers);
  
  echo "&lt;body onload=\"self.close();\"&gt;";
  
  
  ?&gt;
  </code></pre>