Log in

View Full Version : Resolved PHP Form-to-Email won't post input into email



rsrwebs
06-11-2009, 07:22 PM
Hi,

I am working on a page where you fill out a form to sign up for an email newsletter. Sending an email alone is no problem, but the text entered into the form does not show up when I run a test.
I know it probably has to do with how the info is being posted, but I haven't the slightest clue what code is missing/incorrect.
All I'm trying to do is have the information entered into the form be in the body of the email the PHP sends out.

Here's the form page: http://www.laurendragon.com/mailinglistform.php
The code I'm using:

<?php
$ipi = getenv("REMOTE_ADDR");
$httprefi = getenv ("HTTP_REFERER");
$httpagenti = getenv ("HTTP_USER_AGENT");

?>

<input type="hidden" name="ip" value="<?php echo $ipi ?>" />
<form method="POST" action="sendemail.PHP" name="mailinglist" id="mailinglist">
<div align="left">
<p align="center"><br>
Name (First & Last):<br>
<input type="text" name="Name"/>
<br>
<br>
City:<br>
<input type="text" name="City" />
<br>
<br>
State:<br>
<input type="text" name="State"/>
<br>
<br>
Email:<br>
<input type="text" name="Email"/>
<br>
<br>
<input type="submit" VALUE="Sign Me Up" onClick="alert('Thank you! Your form has been sent.')" />
<br>
</p>
</div>
</form>
</form>


Here is the sendemail.php code:

<?php
$to="Laurendragon@laurendragon.net";
$subject="Mailing List Signup";
$body="
Name $name
City $city
State $state
Email $email";
mail($to,$subject,$body);
?>

I tried to change the code to a post array:

$body="
Name $_POST['name']
City $_POST['city']
State $_POST['state']
Email $_POST['email']";

I got this error message:
Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in sendemail.php on line 15

Line 15 when I look at it in Dreamweaver MX is Name $_POST['name']

Any help is much appreciated. :D
-Raven

thetestingsite
06-11-2009, 08:43 PM
Try:



$body = "Name: ".$_POST['name']."\r\n";
$body .= "City: ".$_POST['city']."\r\n";

//rest of code here!


Hope this helps.

rsrwebs
06-11-2009, 08:56 PM
Well, I'm back to the drawing board again. The email sends fine, but the info entered in the form is not sent. This is all I see:

Name:
City:
State:
Email:

Thanks for the response, though.

bluewalrus
06-11-2009, 10:24 PM
Maybe try this and let us know your out puts



$Name = $_POST['Name'];
$City = $_POST['City'];
$State = $_POST['State'];
$Email = $_POST['Email'];

echo "Your variables are set as:\n Name:" . $name . "\nCity:" . $city . ":\nState:" . $ state . "\nEmail:" . $email ;


$body = "Name:" . $name . "\nCity:" . $city . ":\nState:" . $ state . "\nEmail:" . $email ;

if (empty($body) || ($body=="") || (!isset($body)) {
echo "Body is empty";
} else {
echo "You should have this in your email" . $body;
}


It may be that the post is case sensitive.

thetestingsite
06-11-2009, 10:32 PM
It may be that the post is case sensitive.

Yes, all variables are case sensitive so if you have a form named "name" but you are calling it in your PHP like so: $_POST['Name'], you will continue to get blank results.

Hope this helps.

rsrwebs
06-12-2009, 12:07 AM
Parse error: syntax error, unexpected T_STRING, expecting T_VARIABLE or '$' in D:\Hosting\4213630\html\sendemail.php on line 19

That's what I got when I tried that, line 19 is echo "Your variables are set as:\n Name:" . $name . "\nCity:" . $city . ":\nState:" . $ state . "\nEmail:" . $email ;

rsrwebs
06-12-2009, 12:14 AM
Yes, all variables are case sensitive so if you have a form named "name" but you are calling it in your PHP like so: $_POST['Name'], you will continue to get blank results.

Hope this helps.
Oh god thank you, wow... Words cannot describe how happy I am right now. :lol:
I can't believe it was something so simple! Man I feel silly, oh well thank you guys!!!