title: Send email with PHP from html form on submit with the same script
body: <p>I want to send an email with PHP when a user has finished filling in an HTML form and then emailing information from the form. I want to do it from the same script that displays the web page that has the form.</p>
  
  <p>I found this code, but the mail does not send.</p>
  
  <pre><code>&lt;?php 
  
  if (isset($_POST['submit'])) {
      $to = $_POST['email']; 
      $subject = $_POST['name'];
      $message = getRequestURI();
      $from = "zenphoto@example.com";
      $headers = "From:" . $from;
  
      if (mail($to, $subject, $message, $headers)) {
          echo "Mail Sent.";
      }
      else {
          echo "failed";
      }
  }
  
  ?&gt;
  </code></pre>
  
  <p>What is the code to send an email in PHP?</p>