Reputation: 21
<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 :"."\n\n".$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.";
}
}
?>
Upvotes: 2
Views: 90
Reputation: 1364
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:
if(isset($_POST['submit'])){
with:
if (!empty($_POST['email'])){
or simply:
if (!empty($_POST)){
Upvotes: 0
Reputation: 378
<button class="btn btn-default pull-right" id="submit" type="submit">Verstuur</button>
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:
<button class="btn btn-default pull-right" id="submit" name="submit" type="submit">Verstuur</button>
Upvotes: 0
Reputation: 982
try this
<button class="btn btn-default pull-right" name="submit" id="submit" type="submit">Verstuur</button>
Upvotes: 0
Reputation: 1717
You should add name attribute to the button so replace
<button class="btn btn-default pull-right" id="submit" type="submit">Verstuur</button>
by
<button class="btn btn-default pull-right" id="submit" name="submit" type="submit">Verstuur</button>`
Upvotes: 4