title: send data using ajax and then send email
body: <p>I am trying to create a script that will send a email to our company email when someone clicks a button. The html will be hosted on a static page and will do everything client side, whereas the php code will be hosted on another domain.</p>
  
  <p>What I have tried so far is.</p>
  
  <p><strong>HTML</strong> </p>
  
  <pre><code>&lt;head&gt;&lt;title&gt;Report Errors&lt;/title&gt;
  &lt;script src='https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js' type='text/javascript'&gt;&lt;/script&gt;&lt;/head&gt;
  &lt;script&gt;$(".c").click(function(){
  var href = this.href;
          $.ajax({
          url: 'http://example.com/m35.php',
          type: 'POST',
          data: { subject: href },
          success: function (data) {
                      setTimeout(function (){
                      $(".container").html(data)
                      }, 1000)
                  }
          });
      })
  &lt;/script&gt;
  
  &lt;a href="http://link-to-be-sent.example.com" class="c"&gt;send&lt;/a&gt;
  &lt;div class="container"&gt;success&lt;/div&gt;
  </code></pre>
  
  <p>And the code in m35.php file -</p>
  
  <pre><code>&lt;?php  
  
  $mailTo = "mail@example.com"; 
  $mailFrom = "no-reply@example.com";  
  $subject = $_POST["subject"];
  $message = "someone reported the content in subject doubtful.";  
  
  
  mail($mailTo, $subject, $message, "From: ".$mailFrom);  
  ?&gt;
  </code></pre>
  
  <p>EDIT : Based upon comments I want to clarify that it is even not working on same domain and directory,
  However this type of code is also working but how to do that without page reload with javascript/jquery.</p>
  
  <pre><code>&lt;form method="post" action="http://example.com/m35.php"&gt;
  &lt;input type="text" name="subject" id="subject" value=""&gt; &lt;input type="submit"&gt;
  &lt;/form&gt;
  </code></pre>