title: Execute PHP from HTML form without redirecting to PHP
body: <p>I have a mail form on my HTML that calls a PHP. 
  When I click Submit, It redirects to the PHP and shows various alerts about the form. </p>
  
  <p>I want it not to redirect to the PHP and show alerts on HTML. 
  I tried to redirect back from PHP but in that case it didn't show any alerts.</p>
  
  <p>I couldn't manage to do that. I've read may similar posts but they didn't help. </p>
  
  <p>Can anyone help?</p>
  
  <p>HTML Form:</p>
  
  <pre><code>&lt;form method="post" action="sendmail.php"&gt;
  &lt;input name="id" type="hidden" value="1775"&gt;
  &lt;table cellpadding="10px" border="0"&gt;
  &lt;tr&gt;
     &lt;td align="right"&gt;&lt;iletisimmetni&gt;ad soyad :&lt;/iletisimmetni&gt;&lt;/td&gt;
     &lt;td&gt;&lt;input class="yuvarlak" name="sender_name" type="text"&gt;&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
     &lt;td align="right"&gt;&lt;iletisimmetni&gt;e-posta :&lt;/iletisimmetni&gt;&lt;/td&gt;
     &lt;td&gt;&lt;input class="yuvarlak" name="sender_email" type="email"&gt;&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
     &lt;td align="right"&gt;&lt;iletisimmetni&gt;konu :&lt;/iletisimmetni&gt;&lt;/td&gt;
     &lt;td&gt;&lt;input class="yuvarlak" name="subject" type="text"&gt;&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
     &lt;td align="right" valign="top"&gt;&lt;iletisimmetni&gt;mesaj :&lt;/iletisimmetni&gt;&lt;/td&gt;
     &lt;td&gt;&lt;textarea class="yuvarlak" rows="10" cols="40" name="message" 
     onkeyup="textLimit(this, 250);"&gt;&lt;/textarea&gt;&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
     &lt;td colspan="2" align="right"&gt;&lt;input class="urunbutton" value="Gönder" name="send"  
     type="submit" id="send"&gt;&lt;/td&gt;
  &lt;/tr&gt;
  &lt;/table&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>Here is the PHP:</p>
  
  <pre><code>&lt;?php
  function spamcheck($field)
  {
  $field=filter_var($field, FILTER_SANITIZE_EMAIL);
  if(filter_var($field, FILTER_VALIDATE_EMAIL))
  {
  return TRUE;
  }
  else
  {
  return FALSE;
  }
  }
  if (isset($_REQUEST['sender_email']) &amp;&amp; !empty($_REQUEST['sender_name']) &amp;&amp;    
  !empty($_REQUEST['subject']) &amp;&amp; !empty($_REQUEST['message']))
  {
  
  $mailcheck = spamcheck($_REQUEST['sender_email']);
  if ($mailcheck==FALSE)
  {
  echo "&lt;script&gt;alert('Lütfen geçerli bir e-posta adresi girin.')&lt;/script&gt;";
  //  $URL="http://pantuff.com/testing/iletisim.html"; 
  //  header ("Location: $URL"); 
  }
  else
  {//send email
  $sender_name = $_REQUEST['sender_name'] ;
  $sender_email = $_REQUEST['sender_email'] ;
  $subject = $_REQUEST['subject'] ;
  $message = $_REQUEST['message'] ;
  $headers = "From: ".$sender_name." &lt;".$sender_email."&gt;\r\n";
  $headers .= "MIME-Version: 1.0\r\n";
  $headers .= "Content-Type: text/html; charset=utf-8\r\n";
  mail("info@pantuff.com", "$subject", "$message" . " " . "$sender_name", $headers);
  echo "&lt;script&gt;alert('Mesajınız alınmıştır. Teşekkür ederiz.')&lt;/script&gt;";
  //  $URL="http://pantuff.com/testing/iletisim.html"; 
  //  header ("Location: $URL"); 
  }
  }
  else
  {
  echo "&lt;script&gt;alert('Lütfen tüm alanları doldurun.')&lt;/script&gt;";
  //  $URL="http://pantuff.com/testing/iletisim.html"; 
  //  header ("Location: $URL"); 
  }
  ?&gt;
  </code></pre>
  
  <p>Thanks.</p>