0

First of all I am wondering if there is a way to make it so the page don't refresh on form submission but the boxes etc. are still all cleared.

But my main issue is, once I submit a form it sends an email. BUT.... now every time I refresh the page or go back on the website it sends the email again. I can also click the submit several times. Any help is greatly appreciated.

Code

    <?php 
        if(isset($_POST['SubmitButton'])){
            $name = $_POST['name'];
            $email = $_POST['email'];
            $message = $_POST['message'];
            $formcontent="From: $name \n Message: $message";
            $recipient = "reviews@itssimplytech.co.uk";
            $subject = "Simply Tech Contact Form";
            $headers = "From: $email \r\n".
            "Reply-To: $.email \r\n".
            'X-Mailer: PHP/' . phpversion();
            mail($recipient, $subject, $formcontent, $headers) or die("Error!");  
        } 
    ?>
    <form class="contact-form" action="" method="post">
        <input type="text" name="name" placeholder="Name" required>
        <input type="email" name="email" placeholder="Email" required>
        <textarea rows="5" name="message" placeholder="Say Something..." required></textarea>
        <input type="submit" name="SubmitButton" value="Submit">
    </form> <!--  /.contact-form  -->
  • 1
    Possible duplicate of [Preventing form resubmission](http://stackoverflow.com/questions/3923904/preventing-form-resubmission) – Spoody May 07 '17 at 23:04
  • Neither of them really help me since I am a newbie when it comes to PHP. – Simply Eddie May 07 '17 at 23:20
  • You can always search, try searching for "How to redirect in php" – Spoody May 07 '17 at 23:22
  • Now you really are being silly. Where on earth did I mention needing to redirect? – Simply Eddie May 07 '17 at 23:35
  • No need to talk like this, we are here trying to help, whatever. – Spoody May 07 '17 at 23:37
  • You don't help by marking a question as a duplicate when you clearly don't even understand what is being asked. – Simply Eddie May 07 '17 at 23:39
  • It it indeed duplicated you are looking for how to stop form resubmission, the answer is either with ajax or redirecting, you said you are a newbie in php, i told you to search for how to redirect, that is an answer ! But guess you want us to code for you. – Spoody May 07 '17 at 23:41

0 Answers0