在提交PHP驱动的表单后,如何防止页面重新加载?

时间:2018-04-05 13:03:06

标签: php html forms

我有一个表单,使用PHP向电子邮件提交输入。单击提交按钮后,页面将重新加载。这不是我想要的。我希望在输入的数据发送到电子邮件时不要重新加载页面。

这是我的HTML代码:

<form action="/index.php" method="POST" id="myForm">
   <input type="email" name="email" placeholder="Your Email" id="email" tabindex="2" class"form-control" required>
   <button type="submit" value="submit" name="submit" class="btn btn-start-order">YES!</button>
</form>

这是我的PHP代码:

<?php
if(isset($_POST['submit'])){
$to = "myemail@mail.com";
$from = $_POST['email'];
$subject = "new_form_submission";
$subject2 = "Copy of your form submission";
$message = $name . " " . $last_name . " wrote the following:" . "\n\n" . $_POST['message'];
$message2 = "Here is a copy of your message " . $name . "\n\n" . $_POST['message'];

$headers = "From:" . $from;
$headers2 = "From:" . $to;
mail($to,$subject,$message,$headers);
}
if (isset($_POST['submit']))
{   
?>
<?php
}

&GT;

0 个答案:

没有答案