 <blockquote> <p>You just need to play with <code>$success</code> like this:</p> </blockquote> <pre><code>&lt;?php // Define some constants define("RECIPIENT_NAME", "YOURNAME"); define("RECIPIENT_EMAIL", "YOUR@EMAIL.net"); define("EMAIL_SUBJECT", "Visitor Message"); // Read the form values $success = false; $senderEmail = isset($_POST['senderEmail']) ? preg_replace("/[^\.\-\_\@a-zA-Z0-9]/", "", $_POST['senderEmail']) : ""; $message = isset($_POST['message']) ? preg_replace("/(From:|To:|BCC:|CC:|Subject:|Content-Type:)/", "", $_POST['message']) : ""; // If all values exist, send the email if ($senderEmail &amp;&amp; $message) { $formSubmitted = true; $recipient = RECIPIENT_NAME . " &lt;" . RECIPIENT_EMAIL . "&gt;"; $headers = "From: " . $senderEmail . " &lt;" . $senderEmail . "&gt;"; $success = mail($recipient, EMAIL_SUBJECT, $message, $headers); } // Return an appropriate response to the browser if (isset($_GET["ajax"])) { echo $success ? "success" : "error"; } ?&gt; &lt;!--Your contact.php page--&gt; &lt;form class="o-form" id="contactForm" action="php/contact.php" method="post"&gt; &lt;input type="email" name="senderEmail" id="senderEmail" required="required" placeholder="email"&gt; &lt;textarea name="message" id="message" required="required placeholder=" message"&gt;&lt;/textarea&gt; &lt;input type="submit" value="send" class="send-button"&gt; &lt;/form&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;div class="copyright"&gt; &lt;span&gt; anthonygallina &lt;/span&gt; &lt;/div&gt; &lt;/footer&gt; &lt;div class="th-popup"&gt; &lt;div class="massage-th"&gt; &lt;h1&gt;Thank You!&lt;/h1&gt; &lt;p&gt;We apreciate your visit to our home page. We will contact you soon!&lt;/p&gt; &lt;/div&gt; &lt;/div&gt; &lt;script src="js/jquery-1.11.1.min.js"&gt;&lt;/script&gt; &lt;script src="js/all.js"&gt;&lt;/script&gt; &lt;script src="js/jquery.mixitup.min.js"&gt;&lt;/script&gt; &lt;script src="js/bootstrap.min.js"&gt;&lt;/script&gt; &lt;script src="js/idangerous.swiper.min.js"&gt;&lt;/script&gt; &lt;script&gt; &lt;?php if($formSubmitted) { if ($success) { $msg="&lt;p&gt;Thanks for sending your message! We'll get back to you soon.&lt;/p&gt;"; } else { $msg="&lt;p&gt;There was a problem sending your message. Please try again.&lt;/p&gt;"; } //Open your confirmation or error model here using $msg } ?&gt; &lt;/script&gt; &lt;/body&gt; &lt;/html&gt; </code></pre>