This question already has an answer here:
I have created a form for visitors of my website can message me if they want but for some reason it won't send the message and I do not know how to debug it.
Form:
<form method="post" action="sendmail.php">
<fieldset>
<div class="form-group">
<label for="firstname" class="sr-only">First Name</label>
<input type="text" name="firstname" class="form-control" placeholder="First Name" id="firstname">
</div>
<div class="form-group">
<label for="lastname" class="sr-only">Last Name</label>
<input type="text" name="lastname" class="form-control" placeholder="Last Name" id="lastname">
</div>
<div class="form-group">
<label for="email" class="sr-only">Email</label>
<input type="text" name="email" class="form-control" placeholder="Email" id="email">
</div>
<div class="form-group">
<label for="message" class="sr-only">Message</label>
<textarea class="form-control" placeholder="Message" id="message"></textarea>
</div>
<input type="submit" class="btn btn-primary" value="Send Message" >
</fieldset>
</form>
and the sendmail.php for the info to be sent:
<?php
if(isset($_POST['submit'])){
$to = "email@email.tld";
$from = $_POST['email'];
$first_name = $_POST['firstname'];
$last_name = $_POST['lastname'];
$message = $firstname . " " . $last_name . " wrote the following:" . "
" . $_POST['message'];
$message2 = "Here is a copy of your message " . $firstname . "
" . $_POST['message'];
$headers = "From:" . $from;
$headers2 = "From:" . $to;
mail($to,$message,$headers);
mail($from,$message2,$headers2); // sends a copy of the message to the sender
echo "Mail Sent. Thank you " . $first_name . ", we will contact you shortly.";
}
?>
</div>