<form method="post" action="mail_handler.php">
<div class="col-sm-7 slideanim">
<div class="row">
<div class="col-sm-6 form-group">
<input class="form-control" id="name" name="name" placeholder="Naam" type="text" required>
</div>
<div class="col-sm-6 form-group">
<input class="form-control" id="phone" name="phone" placeholder="Telefoonnummer" type="text" required>
</div>
<div class="col-sm-12 form-group">
<input class="form-control" id="email" name="email" placeholder="Email" type="email" required>
</div>
</div>
<textarea class="form-control" id="msg" name="msg" placeholder="Bericht" rows="5"></textarea><br>
<div class="row">
<div class="col-sm-12 form-group">
<button class="btn btn-default pull-right" id="submit" type="submit">Verstuur</button>
</div>
</div>
</div>
</div>
</div>
</form>
I’ve tried to make this form work, but for some reason it just doesn’t send the E-mail, also it stays blank after I press the submit button. I’ve tried eveything within my reach to fix it, it must be something pretty obvious that I keep overlooking. (I work with the Cpanel to check if the mail is sending, so there is a smtp server available).
<?php
if(isset($_POST['submit'])){
$name=$_POST['name'];
$email=$_POST['email'];
$phone=$_POST['phone'];
$msg=$_POST['msg'];
$to='[email protected]'; // Receiver Email ID, Replace with your email ID
$subject='Form Submission';
$message="Name :".$name."n"."Phone :".$phone."n"."Wrote the following :"."nn".$msg;
$headers="From: ".$email;
if(mail($to, $subject, $message, $headers)){
echo "<h1>Bedankt voor uw bericht!"." ".$name.", Wij nemen zo snel mogelijk contact met u op.</h1>";
}
else{
echo "Er is iets fout gegaan, probeer het alstublieft opnieuw.";
}
}
?>
4
Answers
You should add name attribute to the button so replace
by
try this
You are missing name attribute and your php handler doesn’t get in the if true condition, because it can’t find “submit” key. Change your HTML Button like this:
You can either add a name=”” attribute to button or relay on some other var. Also double check that passed variables are not empty string by using
!empty()
.So replace:
with:
or simply: