I’m having a bit of trouble getting a contact form to function correctly. The template did not come with any contact related php of js. I have managed to get it to send the email fine. But the content of the email is not being sent. If possible, I would like some help with my contact.php. Below is my code:
HTML
<form action="contact.php" method="post">
<div>
<input type="text" class="textbox" value="Name (Required)" onfocus="this.value = '';" onblur="if (this.value == '') {this.value = 'Name';}">
</div>
<div>
<input type="text" class="textbox" value="Email (Required)" onfocus="this.value = '';" onblur="if (this.value == '') {this.value = 'Email';}">
</div>
<div>
<input type="text" class="textbox" value="Subject" onfocus="this.value = '';" onblur="if (this.value == '') {this.value = 'Subject';}">
</div>
<div>
<textarea value="Message:" onfocus="this.value = '';" onblur="if (this.value == '') {this.value = 'Message';}">Describe Your project in detail...</textarea>
</div>
<label>*What is 2+2? (Anti-spam)</label>
<input name="human" placeholder="Type Here">
<input type="hidden" name="send" >
<button class="btn btn-8 btn-8c">Submit</button>
</form>
CSS
.col{
display: block;
float:left;
margin: 1% 0 1% 1.6%;
}
.col:first-child{
margin-left:0;
}
.span_2_of_3 {
width: 66.1%;
}
.span_1_of_3 {
width: 32.2%;
}
.contact-form{
position:relative;
padding-bottom:30px;
}
.contact-form div{
padding:5px 0 15px;
}
.contact-form input[type="text"],.contact-form textarea{
padding: 12px;
display: block;
width: 95%;
background:#017e80;
border: none;
outline: none;
color:#88B8B9;
font-size: 0.8125em;
font-family: 'Open Sans', sans-serif;
-webkit-appearance: none;
}
.contact-form textarea{
resize:none;
height:120px;
}
.btn {
border: none;
font-size: inherit;
color: inherit;
background: none;
cursor: pointer;
padding: 20px 75px;
display: inline-block;
color:#fff;
text-transform: uppercase;
letter-spacing: 1px;
outline: none;
position: relative;
-webkit-transition: all 0.3s;
-moz-transition: all 0.3s;
transition: all 0.3s;
font-family: 'Open Sans', sans-serif;
}
.btn-8 {
display: block;
background: #017E80;
-webkit-transform-style: preserve-3d;
-moz-transform-style: preserve-3d;
transform-style: preserve-3d;
}
.btn-8c:hover {
-webkit-transform: rotateY(15deg);
-moz-transform: rotateY(15deg);
-ms-transform: rotateY(15deg);
transform: rotateY(15deg);
}
.company_address p{
font-family: 'Open Sans', sans-serif;
color:#C6D7DA;
font-size:0.8125em;
line-height: 1.8em;
margin-bottom: 2%;
}
PHP
<?php
$field_name = $_POST['cf_name'];
$field_email = $_POST['cf_email'];
$field_message = $_POST['cf_message'];
$mail_to = 'MyEmail@Host.com';
$subject = 'Message from a site visitor '.$field_name;
$body_message = 'From: '.$field_name."\
";
$body_message .= 'E-mail: '.$field_email."\
";
$body_message .= 'Message: '.$field_message;
$headers = 'From: '.$field_email."\\r\
";
$headers .= 'Reply-To: '.$field_email."\\r\
";
$mail_status = mail($mail_to, $subject, $body_message, $headers);
if ($mail_status) { ?>
<script language="javascript" type="text/javascript">
alert('Thank you for the message. We will contact you shortly.');
window.location = 'temp.html';
</script>
<?php
}
else { ?>
<script language="javascript" type="text/javascript">
alert('Message failed. Please, send an email to mymail@host.com');
window.location = 'temp.html';
</script>
<?php
}
?>