...

View Full Version : Working Code but receiving BLANK email fields



bcurls14
10-23-2009, 09:54 PM
Hi all,

Below is the code used for an online form created with PHP. I'm receiving a confirmation that the form was sent, however when I receive the email, it looks like this with obvious blank fields.


Email:
Name:
Property Address:
City:
State:
Zip:
Telephone:


Here is my code being used:


<!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>Untitled Document</title>
<style type="text/css">
<!--
body {
background-color: #CCCCCC;
margin-bottom: 0px;
margin: 0px;
padding: 0px;
}
body,td,th {
font-family: Verdana, Arial, Helvetica, sans-serif;
}
.table {
width: 800px;
height: 1000px;
background-color: #FFFFFF;
margin-top: 0px;
cell-margin: 20px;
}
.table2 {
background-image: url(table_bg.png);
height: 600px;
width: 800px;
background-position: top;
margin-top: 400px;
}
a:link {
color: #000000;
text-decoration: none;
}
a:visited {
text-decoration: none;
}
a:hover {
text-decoration: none;
}
a:active {
text-decoration: none;
}
-->
</style>
</head>

<body>
<table class="table" align="center" border="0" cellpadding="0" cellspacing="0" width="600">
<tbody>
<tr>
<td valign="top">
<p>&nbsp;</p>
<center><img src="table_bg2.png" />
<p>&nbsp;</p>
<div class="form" id="formHolder"><form name="form1" method="post" action="click-here-form.php">
<table align="center" border="0" cellpadding="6" cellspacing="0" width="100%">
<tbody>
<tr>
<td><label for="email"> </label>
<div align="right">Email Address:</div>
</td>
<td>
<div align="left"><input name="email" id="email" size="35" maxlength="100" type="text" /></div>
</td>
</tr>
<tr>
<td><label for="name"> </label>
<div align="right">Name:</div>
</td>
<td>
<div align="left"><input name="name" id="name" size="35" maxlength="80" type="text" /></div>
</td>
</tr>
<tr>
<td><label for="Address"> </label>
<div align="right">Property Address:</div>
</td>
<td>
<div align="left"><input name="address" id="address" size="35" maxlength="35" type="text" /></div>
</td>
</tr>
<tr>
<td><label for="city"> </label>
<div align="right">City:</div>
</td>
<td>
<div align="left"><input name="city" id="city" size="35" maxlength="12" type="text" /></div>
</td>
</tr>
<tr>
<td><label for="state"> </label>
<div align="right">State:</div>
</td>
<td>
<div align="left"><input name="state" id="state" size="35" maxlength="12" type="text" /></div>
</td>
</tr>
<tr>
<td><label for="zip"> </label>
<div align="right">Zip:</div>
</td>
<td>
<div align="left"><input name="zip" id="zip" size="35" maxlength="12" type="text" /></div>
</td>
</tr>
<tr>
<td><label for="state"> </label>
<div align="right">Telephone Number:</div>
</td>
<td>
<div align="left"><input name="telephone" id="telephone" size="35" maxlength="12" type="text" /></div>
</td>
</tr>
<tr>
<td>
<div align="right"><label for="clear"></label> <input name="clear" id="clear" value="Reset Form" type="reset" /></div>
</td>
<td>
<div align="right"><label for="submit"></label>
<div align="left"><input name="submit" id="submit" value="Send Email!" type="submit" /></div>
</div>
</td>
</tr>
</tbody>
</table>
</form></div>
</center></td>
</tr>
</tbody>
</table>
</body>
</html>


<?php

/* Subject and Email Varibales */

$emailSubject = "Rent Jiffy Form";
$webMaster = "me@bcurley.com";

/* Gathering Data Variables */

$emailField = $_POST['email'];
$nameField = $_POST['name'];
$addressField = $_POST['address'];
$cityField = $_POST['city'];
$stateField = $_POST['state'];
$zipField = $_POST['zip'];
$telephoneField = $_POST['telephone'];

$body = <<<EOD
<br><hr><br>
Email: $email <br>
Name: $name <br>
Property Address: $address <br>
City: $city <br>
State: $state <br>
Zip: $zip <br>
Telephone: $telephone <br>
EOD;

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

/* Results rendered as HTML */

$theResults = <<<EOD
<html>
<head>
<title>JakesWorks - travel made easy-Homepage</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css">
<!--
body {
background-color: #f1f1f1;
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 12px;
font-style: normal;
line-height: normal;
font-weight: normal;
color: #666666;
text-decoration: none;
}
-->
</style>
</head>

<div>
<div align="left">Thank you for your interest! Your email will be answered very soon!</div>
</div>
</body>
</html>
EOD;
echo "$theResults";



?>


Anything will help! Thanks!

Fumigator
10-23-2009, 10:47 PM
This is total deja vu. I swear this exact code has been posted with this exact problem before. Woah.

Anyway...



$emailField = $_POST['email'];
$nameField = $_POST['name'];
$addressField = $_POST['address'];
$cityField = $_POST['city'];
$stateField = $_POST['state'];
$zipField = $_POST['zip'];
$telephoneField = $_POST['telephone'];

$body = <<<EOD
<br><hr><br>
Email: $email <br>
Name: $name <br>
Property Address: $address <br>
City: $city <br>
State: $state <br>
Zip: $zip <br>
Telephone: $telephone <br>
EOD;


Take a close look at the variable names you are echoing out, as opposed to the variable names you assigning $_POST values to. Notice anything?

Fumigator
10-23-2009, 10:51 PM
I was right :D

http://codingforums.com/showthread.php?t=164631

Lamped
10-26-2009, 02:57 AM
Looks like some example code or something is making its rounds...

bcurls14: You set $emailField but later use it as $email... They need to be the same.

Also:
$headers = "From: $email\n";
Should be:
$headers = "From: $email\r\n";



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum