I have a form which submits inputs to an email using PHP. When the submit button is clicked, the page reloads. This isn't what I want. I want the page not to reload while the inputted data is sent to the email.
Here's my html code:
<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>
Here's my PHP code:
<?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
}
?>