I have an html form where users will submit their contact information for us to get in contact with them. I would like to have all of this live on index.html
, but I am not opposed to having to create another file in the folder.
<form class="row" method="post" action="contact.php">
<div class="col-md-12">
<div class="form-group">
<input type="text" class="form-control" placeholder="Your Full Name">
</div>
<div class="form-group">
<input type="text" class="form-control" placeholder="Phone Number*">
</div>
<div class="form-group">
<input type="text" class="form-control" placeholder="Email Address*">
</div>
<div class="form-group">
<input type="text" class="form-control" placeholder="Company Name*">
</div>
<div class="form-group">
<textarea class="form-control lg_textarea" placeholder="Questions / comments"></textarea>
</div>
</div>
<div class="buttn_outer">
<button type="submit" class="btn signin_btn col-sm-5 clearfix" style="margin:0 0 0 4%; float: left;">Submit</button>
</div>
</form>
I have had php installed on the server machine. Looking at other examples I have found attempted using a php script as follows.
<?php
if($_POST["submit"]) {
$recipient = "me@me.com";
$subject = "Some Message subject";
$sender = $_POST["sender"];
$senderEmail = $_POST["senderEmail"];
$message = $_POST["message"];
$mailBody = "Name: ".$sender."\nEmail: ".$senderEmail."\n\n".$message;
mail($recipient, $subject, $mailBody, "From: ".$sender." <".$senderemail.">");
$thankYou = "<p>Thank you! Your message has been sent.</p>";
}
?>
As of right now it goes to the success message however I never get anything to go to my email. I am extremely new to php, any help/advice is appreciated.
None of your input fields have name attributes.
<input type="text" class="form-control" placeholder="Email Address*">
<input type="text" class="form-control" placeholder="Your Full Name">
<textarea class="form-control lg_textarea" placeholder="Questions / comments"></textarea>
Should be
<input type="text" class="form-control" name="senderEmail" placeholder="Email Address*">
<input type="text" class="form-control" name="sender" placeholder="Your Full Name">
<textarea class="form-control lg_textarea" name="message" placeholder="Questions / comments"></textarea>
Basically, the name attribute of the input field should match what the $_POST
key is.
So, <input name="name" />
would be handled as $_POST['name']
Also, it looks like you're mixing up the $recipient
and $senderEmail
variables. PHP's mail function specifies that the first parameter is the recipient. I understand that me@me.com
is clearly not a real email. But, the recipient should be the user's email that he/she has submitted in the form. Make sure the mail function works by testing it without submitting the form and if it does, then try to make it work with the form variables.