title: PHP contract form, Message Sent
body: <p>I made a PHP contact form which sends an email to me.
  And I would like to inform the user that the message had been sent after refreshing the page.</p>
  <p>I was able to make a pop up only before refreshed the page, with this the problem was that if the user leaves the page before clicking ok, the message won't be sent.</p>
  <p>This is my current code:</p>
  <pre><code>&lt;?php
  if(isset($_POST['submit'])){
      $name = $_POST['name'];
      $subject=$_POST['subject'];
      $mailFrom=$_POST['mail'];
      $message=$_POST['message'];
  
      $mailTo = &quot;something@something.org&quot;;
      $headers = &quot;From: &quot;.$mailFrom;
      $txt =&quot;You have received an e-mail from&quot;.$name.&quot;.\n\n&quot; .$message;
  
  
      if ($name != '' &amp;&amp; $mailFrom != '') {
          if (mail ($mailTo, $subject, $message, $mailFrom)) {
              echo '&lt;p&gt;Your message has been sent.&lt;/p&gt;';
          } else { 
              echo '&lt;p&gt;Something went wrong, go back and try again.&lt;/p&gt;'; 
          }
      }  else {
          echo '&lt;p&gt;You need to fill in all required fields.&lt;/p&gt;';
      }
  }
  
  mail($mailTo,$subject,$txt,$headers);
  header(&quot;Location: index.php&quot;) ;
  
  
  ?&gt;
  </code></pre>
  <p>HTML:</p>
  <pre><code>&lt;div class=&quot;modal-bg&quot;&gt;
                  &lt;div class=&quot;modal&quot;&gt;
                      
                      &lt;form class=&quot;contact-form&quot; action=&quot;contactform.php&quot; method=&quot;post&quot;&gt;
                      &lt;h2&gt;Contact Us!&lt;/h2&gt;
                      &lt;label for=&quot;name&quot;&gt;Name: &lt;/label&gt; &lt;/br&gt;
                      &lt;input type=&quot;text&quot; name=&quot;name&quot; placeholder=&quot;Your name&quot;&gt; &lt;/br&gt;
                      &lt;label for=&quot;email&quot;&gt;E-mail&lt;/label&gt; &lt;/br&gt;
                      &lt;input type=&quot;text&quot; name=&quot;mail&quot; placeholder=&quot;Your e-mail&quot;&gt; &lt;/br&gt;
                      &lt;label for=&quot;subject&quot;&gt;Subject:   &lt;/label&gt; &lt;/br&gt;
                      &lt;input type=&quot;text&quot; name=&quot;subject&quot; placeholder=&quot;Subject&quot;&gt; &lt;/br&gt;
                      &lt;label for=&quot;message&quot;&gt;Message:   &lt;/label&gt; &lt;/br&gt;
                      &lt;textarea name=&quot;message&quot; class=&quot;message&quot; placeholder=&quot;Message&quot;  rows=&quot;15&quot; cols=&quot;50&quot;&gt;&lt;/textarea&gt; &lt;/br&gt;
                      &lt;button type=&quot;submit&quot; name=&quot;submit&quot;&gt; SEND &lt;/button&gt;
                  &lt;/form&gt;
                      &lt;span class=&quot;modal-close&quot;&gt;X&lt;/span&gt;
                  &lt;/div&gt;
              &lt;/div&gt;
  </code></pre>