cant get a simple php command to work

Grins
Grins used Ask the Experts™
on
i have a form and after validation all its information is stored in one variable then passed to a hidden field named 'allInfo'. here is my code with comments explaining the problem the emails i receive after processing. (i just started learning php last night, which should explain the looks of things)

<?
$recipient = "myemail@hotmail.com";
$subject = "Order";
$message = " Name: $name\n Email: $email\n Order: $order\n  Phone: $phone\n";
$from = "$email";

$name=$_POST['name'];
$email=$_POST['email'];
$phone=$_POST['phone'];
$order=$_POST['allInfo'];

$order=nl2br($order);

mail($recipient,$subject,$message,$from); //everything Except $order (my most important field) is emailed to me

echo($order); //yet it echoes perfectly!
?>

my inbox gets:

From: Nobody      To:myemail@hotmail.com    Subject: Order

the email entered in the form, as a link

Name: the name entered
Email: the email entered, as a link
Order:
Phone: the number entered

please help, im completely baffled.
i dont believe this should mean anything but 'allInfo' is the only hidden field on my form.
and if youre feeling generous, why is the From: field in my email always Nobody?
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
you're putting $order into $message before you set its value.  At that point, $order is "", so that's all you get.

put $message= below your $order=$_POST['allInfo']
nentwined has it but here is a revision..........

<?
// Load up from POST
$name=$_POST['name'];
$email=$_POST['email'];
$phone=$_POST['phone'];
$order=$_POST['allInfo'];

// Why? all this will do is put '<br>' in as plain text
$order=nl2br($order);

// Build message parts
$recipient = "myemail@hotmail.com";
$subject = "Order";
$message = " Name: $name\n Email: $email\n Order: $order\n  Phone: $phone\n";
$from = "$email";

// Send mail
mail($recipient,$subject,$message,$from);

?>

Commented:
$from is wrong
$from must be header like "From: email@domain.com";
not a "email@domain.com"


<?
// Load up from POST
$name=$_POST['name'];
$email=$_POST['email'];
$phone=$_POST['phone'];
$order=$_POST['allInfo'];

// NOT NEED
//$order=nl2br($order);

// Build message parts
$recipient = "myemail@hotmail.com";
$subject = "Order";
$message = " Name: $name\n Email: $email\n Order: $order\n  Phone: $phone\n";
$from = "From: $email";
// $from .= "\nReply-To: $email"; // if you need different reply-to mail

// Send mail
mail($recipient,$subject,$message,$from);

?>

Author

Commented:
nentwined, I didnt think it would work because the other variables ($name, $email, $phone) are passed just fine though they are in the exact same position as $order, but you are absolutely correct and it works wonderfully now. Thank you very much.

i add the nl2br() because $order('allInfo') is a concatenation of the entire form which is displayed to the site-visitor in a js confirm box once submit is clicked. i have several \n's added into in the variable for better presentation. instead of getting all the information in one line (a giant paragraph), i receive it the way it is presented in the confirm box.

saknarak, i tried your suggestion with $from and it did not work. it actually prevented me from receiving any of the emails. i am not sure which version php my host is running so it might be just that (which version does your syntax apply to?). out of curiosity, if you are correct about $from needing to be in header form, does that mean $recipient = "To: email@domain.com"; is the correct syntax?

thank you all for your time and input.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial