PDA

View Full Version : PHP Script & HTML form returning blank email


AllisonBass
01-04-2011, 05:41 AM
I am new to PHP. My PHP Script & HTML form return blank emails... help please!!!

Here is the email body that I recieve:
FirstName: LastName: Street: City: State: Zip: Email: Phone: Customer

Form Code:
<form action="http://www.website.com/sendresults.php" method="post" enctype="text/plain" name="Service Request" id="ServiceRequest" title="ServiceRequest" dir="ltr" lang="English">
<p>
<label for="FirstName">First Name </label>
<input name="FirstName" type="text" id="FirstName" size="42" />
</p>
<p>
<label for="LastName">Last Name </label>
<input name="LastName" type="text" id="LastName" size="42" />
</p>
<p>
<label for="StrreetAddress">Street Address</label>
<input name="StrreetAddress" type="text" id="StrreetAddress" size="39" />
</p>
<p>
<label for="City">City</label>
<input name="City" type="text" id="City" size="20" />
<label for="State">State</label>
<input name="State" type="text" id="State" size="2" maxlength="2" />
Zip
<input name="City2" type="text" id="City" size="6" maxlength="5" />
</p>
<p>
<label for="Email">Email</label>
<input name="Email" type="text" id="Email" size="19" />
<label for="DayPhone"> Phone</label>
<input name="DayPhone" type="text" id="DayPhone" size="16" maxlength="12" />
</p>
<p>I am a
<label>
<input type="radio" name="Customer" value="radio" id="Customer_0" />
New Customer. </label>
<label>
<input type="radio" name="Customer" value="radio" id="Customer_1" />
Existing Customer.</label>
<br />
</p>
<p>Requesting an estimate for (see <a href="Services.html"> services</a> page for descriptions)</p>
<p>
<label>
<input type="radio" name="Estimate For" value="radio" id="EstimateFor_0" />
Weekly Lawn Care </label>
<label>
<input type="radio" name="Estimate For" value="radio" id="EstimateFor_1" />
Full Service Lawn Care</label>
<p>
<label>
<input type="radio" name="Estimate For" value="radio" id="EstimateFor_1" />
Spring/Fall Clean Up</label>
<label>
<input type="radio" name="Estimate For" value="radio" id="EstimateFor_1" />
Other</label>
</p>
<p>
<label for="AdditionalComments">Additional Comments:</label>
<textarea name="AdditionalComments" id="AdditionalComments" cols="42" rows="5"></textarea>
</p>
<center>
<p>
<input type="submit" name="Submit" id="Submit" value="Submit" />
<br />
</p>
</center>
</form>

Here is my PHP script:

<?php
/*Subject and Email Variables*/
$emailSubject = 'Online Service Request';
$webMaster = 'emailaddress@gmail.com';
/*Gathering Data Variables*/
$firstnameField = $_POST['First Name'];
$lasenameField = $_POST['Last Name'];
$streetaddressField = $_POST['Street Address'];
$cityField = $_POST['City'];
$stateField = $_POST['State'];
$zipField = $_POST['Zip'];
$emailField = $_POST['Email'];
$phoneField = $_POST['Phone'];
$commentsField = $_POST['Additional Comments:'];
$customerField = $_POST['I am a '];
$ServicesField = $_POST['Requesting an estimate for (see services page for descriptions)'];
$body =
"FirstName:" .$firstnameField. "\n LastName:" .$lasenameField. "\n Street:" .$streetaddressField. "\n City:" .$cityField. "\n State:" .$stateField. "\n Zip:" .$zipField. "\n Email:" .$emailField. "\n Phone:" .$phoneField. "\n Customer:" .$customerField. "\n Services:" .$ServicesField. "\n" ;
$headers = "From: $emailField\r\n";
$headers = "Content-type: text/html\r\n";
$success = mail($webMaster, $emailSubject, $body, $headers);
/*Results Rendered as HTML*/
$theResults = <<<EOD
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Service Request</title>
</head>
<body>
<p>Thank you for your interest. We will get back to you as soon as possible.</p>
<p><a href="http://www.website.com/"> Back </a> </p>
</body>
</html>
EOD;
echo "$theResults";
?>

edbr
01-04-2011, 05:52 AM
should pass hte values , try changing http://www.website.com/sendresults.php" for sendresults.php (http://www.website.com/sendresults.php)" in the action.
also you have a typo om streetaddress StrreetAddress

jmichae3
01-04-2011, 08:56 AM
why is your enctype text/plain? there are 3 valid values:
enctype=[application/x-www-form-urlencoded]|multipart/form-data|text/plain

try changing it to multipart/form-data. text/plain is used for sending mailto emails. like this http://www.csc.flint.umich.edu/~hickslm/263/L10enctype.htm (http://www.csc.flint.umich.edu/%7Ehickslm/263/L10enctype.htm)

according to http://htmlhelp.com/reference/html40/forms/form.html you should not use enctype unless you are uploading files.
I generally have not used it except when uploading files and have had much success.

so remove the enctype and see if that fixes it.

also, your body is not HTML. so you should not be using text/html for an email mime type. it should be text/plain.

AllisonBass
01-04-2011, 05:22 PM
Thanks for the input! I still get the same blank email even when I did the following:
-Updated misspelling of street address
-Updated form action to ="sendresults.php"
-Tried removing the enctype
-Tried updating enctype to multipart/form-data

Ideas on what I am doing wrong?

Corrosive
01-04-2011, 05:52 PM
Your input names should match what you post. Example;

<input name="FirstName" type="text" id="FirstName" size="42" />

and

$firstnameField = $_POST['First Name'];

Don't match. There is a space in the name you are posting. Generally I'd leave spaces out of PHP all together!

Try sorting that and see if it helps.

Btw, don't mind you posting code but please use code tags. Thanks

Corrosive
01-04-2011, 05:54 PM
Just noticed it is also full of typos;

<input name="StrreetAddress" type="text" id="StrreetAddress" size="39" />

Go through it with a fine tooth comb, make sure everything matches (typos or no) and then I bet it works just fine.

AllisonBass
01-04-2011, 08:18 PM
That did it!!!! My posts did not match my form input names.... once I realized that mistake, I was able to see the typos better.

What a relief. Thank you very much for helping me with this.

I am new to using this type of forum. Can you please share with me how to use code tags? Will use in the future.

jmichae3
01-04-2011, 09:26 PM
open square bracket then the word code close square bracket
insert your text
open square bracket then the word /code close square bracket

AllisonBass
01-04-2011, 10:11 PM
will do. again, thanks to all.

jmichae3
01-05-2011, 04:01 AM
good catch, Corrosive.

Corrosive
01-05-2011, 06:11 AM
That did it!!!! My posts did not match my form input names.... once I realized that mistake, I was able to see the typos better.

What a relief. Thank you very much for helping me with this.

I am new to using this type of forum. Can you please share with me how to use code tags? Will use in the future.

You are most welcome. Glad it is now working. That's the thing about code, one single character out of place and nothing works as it should. You just have to have a good eye for detail.

Code tags are the # symbol at the top of the area where you post. Press that and then post code in between the tags it produces. Just keeps stuff neater.