I am using php mail form on my page. It work good but when email is sent the message about successful post is opened in new blank page. What I want to do is show message directly under send button with some formating. My code looks like this.
<form action="contact.php" method="POST" id="contactform_main2" style="font-size:14px">
<ol>
<li>
<label for="email">Email</label>
<input type="email" id="email" name="email" class="text" required />
</li>
....etc
<li class="buttons">
<input type="submit" name="imageField" value="Odoslať" class="send" style="cursor:pointer" />
</li>
</ol>
</form>
and this is the php
<?php
...geting data
if(
mail("dominik0109@gmail.com", $subject,
$sprava, "From:" . $email)){
echo "<strong>Sucessfully sent</strong>";}
else {
echo "Error";}
?>
You can see it live on my page, fill any content to post form. How to fix this please? Thnaks
You just need to send the form to the same page and check if POST variables are passed.
<form action="#message" method="POST" id="contactform_main2" style="font-size:14px">
<ol>
<li>
<label for="email">Email</label>
<input type="email" id="email" name="email" class="text" required />
</li>
<!-- ....etc -->
<li class="buttons">
<input type="submit" name="imageField" value="Odoslať" class="send" style="cursor:pointer" />
</li>
</ol>
</form>
<?php
if(isset($_POST['email'])) {
// ...geting data
echo "<a name='message'></a>";
if(mail("dominik0109@gmail.com", $subject, $sprava, "From:" . $email)){
echo "<strong>Sucessfully sent</strong>";
}
else {
echo "Error";
}
}
?>
If you are looking not to refresh the page at all you'll need javascript and ajax.