Simple Contact Form Help
Posted: Tue Feb 02, 2010 10:00 am
Hello, I am very new to PHP and just created my first small contact form, however I can not get the form to send to my email. I would also like to know what code I can include that once I hit submit the page redirects to a certain page of my site. Below is the HTML code for my form: (the form page is called about_new.html)
<form METHOD=POST ACTION="contact_form.php">
<table width="300" border="0" cellspacing="0" cellpadding="0">
<tr>
<td>
<h3 align="right" class="fieldname">Name:</h3></td>
<td> <INPUT NAME="name" TYPE="text" class="form" size="27"></td></tr>
<tr><td><h3 align="right" class="fieldname">E-mail:</h3></td><td><INPUT NAME="email" TYPE="text" class="form" size="27"></td></tr>
<tr><td valign="top"><h3 align="right" class="fieldname">Message:</h3></td>
<td><TEXTAREA NAME="message" COLS="25" ROWS="4" class="message"></TEXTAREA></td></tr>
<td><br> </td><td><br>
<input name="submit" type="submit" class="sendbtn" id="Submit" value="Submit" /></td></tr>
</table>
</form>
The following is the php code in a file called contact_form.php
<?php
if(isset($_POST['submit'])) {
$to = "lauren.kalik@yahoo.com";
$subject = "IP Contact Form";
$name_field = $_POST['name'];
$email_field = $_POST['email'];
$message = $_POST['message'];
$body = "From: $name_field\n E-Mail: $email_field\n Message:\n $message";
echo "Data has been submitted to $to!";
mail($to, $subject, $body);
} else {
echo "blarg!";
}
?>
Any help would be greatly appreciated! Thanks in advance!
<form METHOD=POST ACTION="contact_form.php">
<table width="300" border="0" cellspacing="0" cellpadding="0">
<tr>
<td>
<h3 align="right" class="fieldname">Name:</h3></td>
<td> <INPUT NAME="name" TYPE="text" class="form" size="27"></td></tr>
<tr><td><h3 align="right" class="fieldname">E-mail:</h3></td><td><INPUT NAME="email" TYPE="text" class="form" size="27"></td></tr>
<tr><td valign="top"><h3 align="right" class="fieldname">Message:</h3></td>
<td><TEXTAREA NAME="message" COLS="25" ROWS="4" class="message"></TEXTAREA></td></tr>
<td><br> </td><td><br>
<input name="submit" type="submit" class="sendbtn" id="Submit" value="Submit" /></td></tr>
</table>
</form>
The following is the php code in a file called contact_form.php
<?php
if(isset($_POST['submit'])) {
$to = "lauren.kalik@yahoo.com";
$subject = "IP Contact Form";
$name_field = $_POST['name'];
$email_field = $_POST['email'];
$message = $_POST['message'];
$body = "From: $name_field\n E-Mail: $email_field\n Message:\n $message";
echo "Data has been submitted to $to!";
mail($to, $subject, $body);
} else {
echo "blarg!";
}
?>
Any help would be greatly appreciated! Thanks in advance!