title: How Can Submit Button of HTML Form send email to webmaster without opening user's email client and redirect to another page afterwards?
body: <p>I have a very basic HTML Form:</p>
  
  <pre><code>&lt;form method="post" action="http://someurl.com" target="_new"&gt;
      &lt;input name="name" value="" type="text" placeholder="Your First Name"  /&gt;
      &lt;input name="from" value="" type="text"  placeholder="Your Best Email" /&gt;
      &lt;input type="image" name="image" src="images/submit.gif" type="submit" /&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>Upon form submit, I'd like for it to redirect to the URL indicated in the form action above AND also for it to send me an email WITHOUT OPENING USER'S MAIL CLIENT notifying of a user filling the form.</p>
  
  <p>For what I gathered online and from this site as well I'd need something like below in php form</p>
  
  <pre><code>&lt;?php
  ///subscribe form
  $recipient = "email@email.com"; ///  Your Email address
  if (isset($_POST['email']))
    {
    //Send Mail To Webmaster
    $email = $_POST['email'] ;
    $subject = 'New Subscriber';
    $message =  $email . ' has been subscribed to your website.';
    mail("$recipient", $subject,
    $message, "From:" . $recipient);
   ;}
   ?&gt;
  </code></pre>
  
  <p>However I'm not proficient enough to create AJAX code to combine the two of them?</p>
  
  <p>I APPRECIATE YOUR HELP, PLEASE BE SPECIFIC! I've seen tons of replies to similar questions with generic answers, if you know I have to use php, ajax etc. please indicate how and provide a sample code. ie. do I need to create a file with that code and how can I call the file and make it work from my HTML form? etc.</p>
  
  <p>UPDATE, ok I found script.js below which is what calls the above php file called mail.php
  IT WORKS! however ... it sends the email to myself with the email information of the person that filled the form, not the name.</p>
  
  <pre><code>$(function() {
          $(".submit-btn").click(function() {
          var x=$(".mail-input").val();
          var atpos=x.indexOf("@");
          var dotpos=x.lastIndexOf(".");
          var email = $(".mail-input").val();
          var dataString = 'email='+ email;
  
          if (atpos&lt;1 || dotpos&lt;atpos+2 || dotpos+2&gt;=x.length)
          {
          $(".mail-input").css({"background-color":"rgba(216, 70, 55, 0.64)"});
          }
          else
          {
          $.ajax({
          type: "POST",
          url: "mail.php",
          data: dataString,
              success: function(){
                  window.location.href = "http://someurl.com";
              }
          });
          }
          return false;
          });
  </code></pre>
  
  <p>CAN ANYONE TELL ME how to also capture the name field data of my form and send it in the email as well, looks like the code above is meant for a form with only an email field and sends that data to the webmaster, I need to add the name field from my form to the code. </p>
  
  <p>Thanks!</p>