I'm currently working through setting up a fully functional contact form using the Bootstrap framework and PHP. I'm receiving test emails from the form but it's not displaying the content the way I understood it would and I'm having some other issues.
First, the user-submitted email is showing up as being received from the host of my site. It is also not including the name of the person, which I thought I included in my PHP
Here is my code for contact.php and the form in my index.html file
<?php
$to = 'example@gmail.com';
$name = $_POST['name'];
$email = $_POST['email'];
$subject=$_POST['subject'];
$message = $_POST['msg'];
if ($_POST){
mail($to, $subject, $message);
$confirm= "Your email was sent successfully!";
echo "<script type='text/javascript'>confirm('$confirm');</script>";
}
else {
$error_msg= "All fields are required!";
echo "<script type='text/javascript'>alert('$error_msg');</script>";
}
?>
index.html
<form class="form-horizontal" role="form" action="contact.php" method="post">
<div class="modal-header">
<h2>Contact</h2>
</div>
<div class="modal-body">
<!--name-->
<div class="form-group">
<label for="name" class="col-sm-2 control-label">Name</label>
<div class="col-sm-10">
<input type="text" class="form-control" name="name" id="name" placeholder="First and Last Name">
</div>
</div>
<!--email-->
<div class="form-group">
<label for="email" class="col-sm-2 control-label">Email</label>
<div class="col-sm-10">
<input type="email" class="form-control" name="email" id="email" placeholder="example@somewhere.com">
</div>
</div>
<!--subject-->
<div class="form-group">
<label for="subject" class="col-sm-2 control-label">Subject</label>
<div class="col-sm-10">
<input type="text" class="form-control" name="subject" id="subject" placeholder="Enter subject here...">
</div>
</div>
<!--message-->
<div class="form-group">
<label for="msg" class="col-sm-2 control-label">Message</label>
<div class="col-sm-10">
<textarea class="form-control" rows="4" name="msg" id="msg" placeholder="Enter message here..."></textarea>
</div>
</div>
</div>
<div class="modal-footer">
<a class="btn btn-default" data-dismiss="modal">Close</a>
<button type="submit" class="btn btn-primary">Send</button>
</div>
</form>
Another unintended issue is that once the page is submitted, a blank page (contact.php) is loaded. I thought, looking at my code, a javascript alert or confirm box would pop up instead though? I'm new at this so, I apologize if these are dumb questions.
Thanks -K