I am new to website development and wanted to get a quick answer about a php script that I am writing. I want this script to take all of the form fields and email them to me as well as let the person filling out the form know that their information has been sent as well as take them back to my site after submitting the form. Right now the form will email incomplete fields to my email address and it will let the person know that the form has been submitted, but it the filled in information is blank. Below is my form code and below that is my php script. Can someone look at both and tell me what I am doing wrong? Thank you in advance.
<form action="contact.php" method="post" id="form">
<input type="text" input name="cf_name" value="Name(Required)" onfocus="this.value = '';" onblur="if (this.value == '') {this.value = 'Name';}">
<input type="text" input name="cf_email" value="Email (Required)" onfocus="this.value = '';" onblur="if (this.value == '') {this.value = 'Email';>
<input type="text" input name="cf_subject" value="Subject" onfocus="this.value = '';" onblur="if (this.value == '') {this.value = 'Subject';}">
<textarea onfocus="if(this.value == 'Your Message here....') this.value='';" onblur="if(this.value == '') this.value='Your Message here....;" >Your Message here....</textarea>
<span class="pull-right"><input type="submit" value="Submit"> </span>
</form>
<?php
$mail_to = '[email protected]';
$subject = 'Message from a site visitor '.$field_name;
$body_message = 'From: '.$field_name."\n";
$body_message .= 'Email: '.$field_email."\n";
$body_message .= 'Subject: '.$field_subject."\n";
$body_message .= 'Message: '.$field_message;
$headers = 'From: '.$field_email."\r\n";
$headers .= 'Reply-To: '.$field_email."\r\n";
$mail_status = mail($mail_to, $subject, $body_message,$headers);
if ($mail_status) { ?>
<script language="javascript" type="text/javascript">
alert('Thank you for the message.');
window.location = 'index.html';
</script>
<?php
}
else { ?>
<script language="javascript" type="text/javascript">
alert('Message failed. Please, send an email to
[email protected]');
window.location = 'index.html';
</script>
<?php
}
?>
the name of your fields are not populated in your php script.
cf_name cf_email cf_subject
You should use something like this in your script: