Link to home
Start Free TrialLog in
Avatar of Grins
GrinsFlag for United States of America

asked on

cant get a simple php command to work

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?
ASKER CERTIFIED SOLUTION
Avatar of nentwined
nentwined

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Mark_Kendall
Mark_Kendall

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);

?>
$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);

?>
Avatar of Grins

ASKER

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.