I want to add submit form using php but also I want to stay on the same page after clicking the submit button. Also I want that the entries reset after submit button is clicked. I am new to php and I don't know anything about it so please help by giving me proper coding.
This is the PHP code -
<?php
if(isset($_POST['send'])) {
// Prepare the email
$to = 'letsavepet@gmail.com';
$name = $_POST['name'];
$mail_from = $_POST['email'];
$subject = 'Message sent from website';
$message = $_POST['message'];
$header = "From: $name <$mail_from>";
// Send it
$sent = mail($to, $subject, $message, $header);
if($sent) {
echo 'Your message has been sent successfully!';
} else {
echo 'Sorry, your message could not send.';
}
}
?>
<html><head><title>Contact Us</title>
</head><body>
<form method="post" action="contact.php" target="formDestination">
<p>
<label for="name">Name</label>
<input type="text" id="name" name="name" required="required" />
</p>
<p>
<label for="email">Email</label>
<input type="text" id="email" name="email" required="required" />
</p>
<p>
<label for="message">Message</label>
<textarea id="message" name="message" rows="6" cols="30" required="required"></textarea>
</p>
<p>
<input type="submit" name="send" value="Send message" />
</p>
</form>
</body></html>