Forum Moderators: coopster

Message Too Old, No Replies

php email not sending variables

         

Deuce_Bigs

5:13 am on Jun 18, 2003 (gmt 0)

10+ Year Member



I've got a form that's supposed to send an email after it's been submitted. i get the text to show but the actual variable doesn't. can someone tell me what i'm doing wrong? i searched this forum for help already and that's how i got this far. here is what i'm using:

<?
echo "<PRE>_POST: ";
print_r ($_POST);
echo "</PRE>";

$today = date("F j, Y, g:i a");

$message = "Order submitted on $today\r\n\r\n";
$message .= "Requested by: $_POST['name']\r\n";
$message .= "Address: $_POST['shipadd']\r\n\r\n";
$message .= "State: $_POST['state'] \r\n";
$message .= "zip: $_POST['zip'] \r\n";
$message .= "Email: $_POST['email'] \r\n";

$to = "webmaster@site.com";
$from = "From: $_POST['email']\r\n";
$subject = "Order Request - $today";

mail($to,$subject,$message,$from);

?>

thanks!

[edited by: jatar_k at 6:22 am (utc) on June 18, 2003]
[edit reason] made email address generic [/edit]

jatar_k

6:25 am on Jun 18, 2003 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



what are the odds the date is the only one showing up?

I ran into a similar little problem today. Vars wouldn't get resolved between double quotes. Some did and some didn't. I figured out that the ones that didn't were arrays with [], so..

$message = "Order submitted on $today\r\n\r\n";
$message .= "Requested by: " . $_POST['name'] . "\r\n";
$message .= "Address: " . $_POST['shipadd']] . "\r\n\r\n";
$message .= "State: " . $_POST['state']] . " \r\n";
$message .= "zip: " . $_POST['zip']] . " \r\n";
$message .= "Email: " . $_POST['email']] . " \r\n";

when they are cat'ed together they work, maybe this is your problem too.

DrDoc

6:38 am on Jun 18, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You're absolutely right, jatar_k.

You cannot refer to an item in an array with [] inside any form of quotes.

echo "Whatever: $_POST['whatever']"; // doesn't work
echo "Whatever: " .$_POST['whatever']; // works

echo <<<END
Whatever: $_POST['whatever']
END // doesn't work either

jatar_k

6:50 am on Jun 18, 2003 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



It's one of those funny things. I always cat my strings together so I have never run into it.

I happened to be destroying someone else's code and building something that worked ;) and reused some strings that wereset up like that. Replaced a few vars, nuthin.

learn something new all the time.

<added>oops, pardon our manners

Welcome to WebmasterWorld Deuce_Bigs

madcat

2:16 pm on Jun 18, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



['shipadd']]

Am I seeing those correctly jatar? Two closing brackets?

jatar_k

2:22 pm on Jun 18, 2003 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



thax madcat, I'm an idiot, once again the dangers of cut and paste, good catch, hehe ;)

$message = "Order submitted on $today\r\n\r\n";
$message .= "Requested by: " . $_POST['name'] . "\r\n";
$message .= "Address: " . $_POST['shipadd'] . "\r\n\r\n";
$message .= "State: " . $_POST['state'] . " \r\n";
$message .= "zip: " . $_POST['zip'] . " \r\n";
$message .= "Email: " . $_POST['email'] . " \r\n";

madcat

2:25 pm on Jun 18, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Nah, only confusing for the wee php peons like me-self ;)

Deuce_Bigs

4:42 pm on Jun 18, 2003 (gmt 0)

10+ Year Member



awesome that fixed everything thanks guys!