title: Sending JS variables to PHP mailer
body: <p>I have a JS script that validates data from a contact form. I need, once the entered values have been validated, to send the data to the PHP file that will send the email. The PHP works correctly (verified without the JS pre-submission validation process)</p>
  <p>The JS:</p>
  <pre><code>// GET DATA
  const nameInput = document.querySelector(&quot;#name&quot;);
  const email = document.querySelector(&quot;#email&quot;);
  const phone = document.querySelector(&quot;#phone&quot;);
  const message = document.querySelector(&quot;#message&quot;);
  
  //......
  
  function sendEmail(){
      $.ajax({
         type: 'POST',
         url: 'sendmail.php',
         data: {
           'nameInput': nameInput,
            'email': email,
            'phone' : phone,
            'message' : message
         },
      });                   
  } 
  </code></pre>
  <p>The PHP:</p>
  <pre><code>&lt;?php
      $toEmail = &quot;mail@mail.com&quot;;
      $subject = &quot;Message from Whatever&quot;
      $mailHeaders = &quot;From: &quot; . $_POST[&quot;nameInput&quot;] . &quot;&lt;&quot;. $_POST[&quot;email&quot;] .&quot;&gt;\r\n&quot;;
  
      
      if(mail($toEmail, $_POST[&quot;subject&quot;], $_POST[&quot;message&quot;], $mailHeaders)) {
      print &quot;&lt;p class='success'&gt;Message Sent&lt;/p&gt;&quot;;
      } else {
      print &quot;&lt;p class='Error'&gt;Error! try again&lt;/p&gt;&quot;;
      }
  ?&gt;
  </code></pre>
  <p>The console says:</p>
  <p>Uncaught ReferenceError: ajax is not defined
  at sendEmail (script.js:57:5)</p>
  <p>57  $.ajax({</p>