PDA

View Full Version : contact form - help?



lillizzierae
September 10th, 2007, 12:42 AM
i'm having some trouble to some reason getting my form to work that i got off this site. i don't know what the problem is. it's probably so small that i'm overlooking it. i'm really, really new to php. but here's the code:


its filename is: contact.php



<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Elizabeth Nichols - Portfolio</title>
<link href="css.css" rel="stylesheet" type="text/css" />
<style type="text/css">
#contact {
position:absolute;
left:358px;
top:655px;
font-size: 10px;
width: 373px;
height: 297px;
}
.style2 {font-size: 14px}
</style>
</head>

<body id="body">

<div id="container">
<div id="login">
Email Address:<br />
<input name="login" type="text" size="18" maxlength="30" />
<br />
Password:<br />
<input name="password" type="password" size="18" maxlength="30" />
<br />
<p align="center"><a href="newmember.php"><img src="images/button_new.png" border="0" /></a>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<img src="images/button_login.png" /></p>
</div>

<div id="header"><img src="images/navigation.png" border="0" usemap="#navigation" />
<map name="navigation" id="navigation">
<area shape="rect" coords="38,21,107,47" href="index.php" alt="home" />
<area shape="rect" coords="124,23,293,48" href="about.php" alt="about" />
<area shape="rect" coords="313,20,383,46" href="work.php" alt="work" />
<area shape="rect" coords="404,21,472,47" href="links.php" alt="link" />
<area shape="rect" coords="495,21,578,46" href="contact.php" alt="contact" />
</map></div>

<div id="contact">

<span class="style2">Fill out the below form and I'll get back to you as soon as I can.</span><br />
<br /><br />
<form method="post" action="thankyou.php">
<table width="284" height="241" border="0">
<tr>
<td width="278" height="39">

<span class="style2">Name:</span><br />
<input name="name" type="text" size="20" maxlength="20" /><br /><br />
<span class="style2">E-mail Address:</span><br />
<input name="email" type="test" size="30" maxlength="40" /></td>
</tr>
<tr>
<td height="187"><span class="style2">Comments/Questions:</span><br />
<textarea name="question" cols="30" rows="6"></textarea>
<br /><br />
<input name="Reset" type="reset" value="Clear" />
<input name="submit" type="submit" value="Submit" /></td>
</tr>
</table></form>

<br />



</div>
<div id="footer_container">
<div id="footer_left">&copy;2006-2007 Elizabeth Nichols. All Rights Reserved.</font></div>
</div>



</div>
</body>
</html>


and this is the php part. its filename is: thankyou.php



<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Sendemail Script</title>
</head>
<body>


<?php
if(isset($_POST['submit'])) {

$to = "lillizzierae@aol.com";
$subject = "Form Tutorial";
$name_field = $_POST['name'];
$email_field = $_POST['email'];
$question = $_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!";

}
?>


</body>
</html>

kaykays
September 10th, 2007, 07:27 AM
You seem to be missing out the Message parameter from the Mail function.

Try changing the Line sending Mail to This:

mail($to, $subject, "This is the Message", $body);

lillizzierae
September 10th, 2007, 02:39 PM
the form still isn't working. the only thing that change is now when i click submit it takes me to the other page telling me "The data has been submitted to lillizzierae@aol.com" but I receive nothing in my mail or in spam.

it wouldn't by any chance have anything to do with the form itself, would it?

simplistik
September 10th, 2007, 03:20 PM
it's probably because you're not submitting any header information, the way a mailer should look is something like


mail($to, $subject, $body, $headers);

so with that being said make a new variable called $headers


$headers = "From: tutorialform@mysite.com\r\n";

also note that this is wrong:


$question = $_POST['message'];

since you changed the "name" of your textarea from "message" to "question"


<textarea name="question" cols="30" rows="6"></textarea>

your post needs to be "question" as well; so you should have


$question = $_POST['question'];