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!
Simple Contact Form Help
Moderator: General Moderators
Re: Simple Contact Form Help
Post in code tags ^_^
One way to redirect :
This is just the way I use in if statement when redirecting, dunno if its the best way to do it or not but it works.
One way to redirect :
Code: Select all
echo "<head><meta HTTP-EQUIV='REFRESH' content='0; url=where u wanna go to'></head>";Re: Simple Contact Form Help
Thanks for your help...your suggestion on the redirect worked beautifully for me.
I am unfamilar with the tag ^_^ that you are suggesting I use for the first problem. Can you be more specific on where this should be used? Sorry for the stupid questions...like I said I am a beginner here.
I am unfamilar with the tag ^_^ that you are suggesting I use for the first problem. Can you be more specific on where this should be used? Sorry for the stupid questions...like I said I am a beginner here.
Re: Simple Contact Form Help
lol I meant tags to post up your code - takes up less space on the page and makes it easier to read 
Code: Select all
Code: Select all
Re: Simple Contact Form Help
haha...ok here you go.
Below is the HTML code for my form: (the form page is called about_new.html)
The following is the php code in a file called contact_form.php
Below is the HTML code for my form: (the form page is called about_new.html)
Code: Select all
<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>Code: Select all
<?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!";
}
?>