PDA

View Full Version : Form Mailer - PHP Script - Data issue



dcj
28 Sep 2009, 03:30 PM
Hi, I'm hoping that someone can help me with this problem as I've never encountered it before. I set up a short contact form in a website and created the php script to attach to it so that it can send the information to an email account. The form works (let's the user fill it in and sends the email); however, the email has the names of the form fields but does not pick up the user entries - meaning it will say "Name:" but will have no value attached. I will attach here my html and php code and if anyone can tell me what I have done wrong or if there is something else I need to do I would be so appreciative:

HTML:

<!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=utf-8" />
<title>Wine Out Dine Out | Contact</title>
<style type="text/css">
#wrap { width: 1200px; position: relative; margin: auto; }
<!--
body {
background-image: url(images/pattern4.png);
background-repeat: repeat;
}
body,td,th {
font-family: "Bell Gothic Std Light", "Bell Gothic Std Black";
font-size: 18px;
color: #AC9B77;
}
a:link {
text-decoration: none;
color: ac9b77;
}
a:visited {
text-decoration: none;
color: ac9b77;
}
a:hover {
text-decoration: underline;
}
a:active {
text-decoration: none;
}
#apDiv1 {
position:absolute;
left:134px;
top:68px;
width:600px;
height:262px;
z-index:1;
}
#apDiv2 {
position:absolute;
left:67px;
top:11px;
width:700px;
height:350px;
z-index:1;
}
#apDiv3 {
position:absolute;
left:736px;
top:33px;
width:300px;
height:128px;
z-index:10;
}
#apDiv4 {
position:absolute;
left:0px;
top:247px;
width:167px;
height:300px;
z-index:50;
}
-->
</style>
<script src="SpryAssets/SpryMenuBar.js" type="text/javascript"></script>
<script src="SpryAssets/SpryEffects.js" type="text/javascript"></script>
<link href="SpryAssets/SpryMenuBarVertical.css" rel="stylesheet" type="text/css" />
<style type="text/css">
<!--
#apDiv5 {
position:absolute;
left:0px;
top:0px;
width:1200px;
height:1000px;
z-index:1;
}
#apDiv6 {
position:absolute;
left:480px;
top:857px;
width:700px;
height:75px;
z-index:51;
}
#apDiv7 {
position:absolute;
left:393px;
top:550px;
width:400px;
height:250px;
z-index:100;
}
#apDiv8 {
position:absolute;
left:981px;
top:946px;
width:201px;
height:17px;
z-index:101;
}
.style1 {
font-family: Candara;
font-size: 14px;
color: #ac9b77;
}
#apDiv9 {
position:absolute;
left:552px;
top:775px;
width:75px;
height:75px;
z-index:102;
}
a:link {color: #ac9b77} /* unvisited link */
a:visited {color: #ac9b77} /* visited link */
a:hover {color: #ac9b77} /* mouse over link */
a:active {color: #ac9b77} /* selected link */
#apDiv10 {
position:absolute;
left:358px;
top:198px;
width:535px;
height:275px;
z-index:103;
}
.style2 {color: #9F8F6F}
.style3 {color: #AC9B77}
#apDiv11 {
position:absolute;
left:307px;
top:247px;
width:587px;
height:284px;
z-index:103;
}
-->
</style>
<script type="text/javascript">
<!--
function MM_effectGrowShrink(targetElement, duration, from, to, toggle, referHeight, growFromCenter)
{
Spry.Effect.DoGrow(targetElement, {duration: duration, from: from, to: to, toggle: toggle, referHeight: referHeight, growCenter: growFromCenter});
}
//-->
</script>
</head>
<div id="wrap">
<body>
<div id="apDiv3"><a href="http://www.wineoutdineout.com"><img src="images/logopink.png" width="300" height="128" border="0" onmouseover="MM_effectGrowShrink(this, 1000, '100%', '125%', true, false, false)" /></a></div>
<div id="apDiv4">
<ul id="MenuBar1" class="MenuBarVertical">
<li><a href="http://www.wineoutdineout.com">Home</a> </li>
<li><a href="ComingEvents.html">Coming Events</a></li>
<li><a href="PastEvents.html">Past Events</a> </li>
<li><a href="ContactUs.html">Contact Us</a></li>
</ul>
</div>
<div id="apDiv5">
<map name="Map2" id="Map2"><area shape="rect" coords="430,519,802,572" href="mailto:wineoutdineout@aol.com" />
</map></div>
<div id="apDiv6"><img src="images/contactbottom.png" width="700" height="75" border="0" usemap="#Map" />
<map name="Map" id="Map"><area shape="rect" coords="592,3,696,41" href="http://www.wineoutdineout.com" />
<area shape="rect" coords="32,44,165,64" href="http://www.wineoutdineout.com" />
</map></div>
<div id="apDiv7"><a href="mailto:info@wineoutdineout.com"><img src="images/contactpage.png" width="400" height="250" border="0" /></a></div>
<div class="style1" id="apDiv8">
<div align="right"><a href="http://www.dcjanodesign.com" target="_blank">site by dcjanodesign</a></div>
</div>
<div id="apDiv9"><a href="http://www.facebook.com/group.php?gid=123358685611&amp;ref=ts" target="_blank"><img src="images/facebook_logo.png" width="75" height="75" border="0" /></a></div>
<div id="apDiv11">
<table width="100%" border="0" cellspacing="5" cellpadding="0">
<tr>
<td><div align="right">
<form id="name" name="name" method="post" action="">
<label for="name">Name:</label>
</form>
</div></td>
<td><div align="left">
<input name="name" type="text" id="name" size="50" maxlength="50" />
</div></td>
</tr>
<tr>
<td><div align="right">
<form id="email" name="email" method="post" action="">
<label for="email">Email:</label>
</form>
</div></td>
<td><div align="left">
<input name="email" type="text" id="email" size="50" maxlength="100" />
</div></td>
</tr>
<tr>
<td><div align="right">
<form id="zip" name="zip" method="post" action="">
<label for="zip">Zip Code:</label>
</form>
</div></td>
<td><div align="left">
<input name="zip" type="text" id="zip" size="50" maxlength="10" />
</div></td>
</tr>
<tr>
<td><div align="right">
<form id="comments" name="comments" method="post" action="">
<label for="comments">Comments:</label>
</form>
</div></td>
<td><div align="left">
<textarea name="comments" cols="50" rows="3" id="comments"></textarea>
</div></td>
</tr>
<tr>
<td><div align="right">
<form id="reset" name="reset" method="post" action="">
<label for="reset"></label>
<input type="reset" name="reset" id="reset" value="Clear Form" />
</form>
</div></td>
<td><div align="left">
<form id="submit" name="submit" method="post" action="comments.php">
<label for="submit"></label>
<input type="submit" name="submit" id="submit" value="Send" />
</form>
</div></td>
</tr>
</table>
</div>
<script type="text/javascript">
<!--
var MenuBar1 = new Spry.Widget.MenuBar("MenuBar1", {imgRight:"SpryAssets/SpryMenuBarRightHover.gif"});
//-->
</script>
</body>
</div>
</html>



PHP:

<?php

/* Subject and Email Variables */

$emailSubject = 'Info Request!';
$webMaster = 'info@wineoutdineout.com';

/* Gathering Data Variables */

$name = $_POST['name'];
$email = $_POST['email'];
$zip = $_POST['zip'];
$comments = $_POST['comments'];

$body = <<<EOD
<br><hr><br>
Name: $name<br>
Email: $email<br>
Zip Code: $zip<br>
Comments: $comments<br>
EOD;

$headers = "From: $email\r\n";
$headers .= "Content-type: text/html\r\n";
$success = mail($webMaster, $emailSubject, $body, $headers);

/* Results rendered as HTML */

$theResults = <<<EOD
<html>
<head>
<title>sent message</title>
<meta http-equiv="refresh" content="1;URL=http://wineoutdineout.com/index.html">
<style type="text/css">
<!--
}

-->
</style>
</head>
<div align="center">Your email will be answered soon as possible!
You will return to Wine Out Dine Out in a few seconds !</div>
</div>
</body>
</html>
EOD;
echo "$theResults";


?>

prasanthmj
28 Sep 2009, 09:44 PM
You have so many forms in this page!
Keep only one <form> tag above the first input element


<form method="post" action="comments.php">
<label for="name">Name:</label>
</div></td>
<td><div align="left">
<input name="name" type="text" id="name" size="50" maxlength="50" />
and close the form tag after the last element



<input type="submit" name="submit" id="submit" value="Send" />
</form>
remove all other <form> and </form> tags

Going through these articles will help:
HTML Form Tutorial (http://www.javascript-coder.com/html-form/html-form-tutorial-p1.phtml)
and this
HTML form input examples (http://www.html-form-guide.com/html-form/html-form-input.html)