首先,我想知道是否有办法制作,以便页面不会在表单提交时刷新,但方框等仍然全部清除。
但我的主要问题是,一旦我提交表格,它就会发送一封电子邮件。但是....现在每次刷新页面或返回网站时它都会再次发送电子邮件。我也可以点击几次提交。非常感谢任何帮助。
代码
<?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 -->