Multiple values from listbox to form email

Hello,

I know very little PHP. I appreciate any help you can offer for what will probably be (hopefully) a simple question/solution. :smiley:

I am using PHP to email data collected from a form. I have added a list box in the form that allows the buyer to select more than one value. Using the code snippets below, I can’t seem to get the values to be displayed in the email message. I do see a separate line for each value selcted when the info is emailed, but instead of seeing the name of the value, it’s empty. What am I doing wrong?

[code]

Peppermint Cinnamon Spearmint Wintergreen

[/code]
[php]<?

@$Flavor= $_POST[‘Flavor’];
if( is_array($Flavor)){
while (list ($key, $val) = each ($Flavor)) {[/php]$msg .= “Flavor: \t$_POST[$val]\n”;
}
}
?>

Your problem is here:

[php]$_POST[$val][/php]

You are looking for the value in the $_POST array, for example $_POST[‘Cinnamon’] doesn’t exist.

If you wanted to access this value you would need to specify $key not $val. You are also accessing the $_POST array instead of $Flavor so you would need to specify the ‘Flavor’ key as well.

For example:

[php]
// this would work accessing the $_POST array
$msg .= “Flavor:\t” . $_POST[‘Flavor’][$key] . “\n”;

// this would also work accessing the $Flavor array
$msg .= “Flavor:\t” . $Flavor[$key] . “\n”;

// this is most likely what you should be using since you have no need to access the arrays directly
$msg .= “Flavor:\t” . $val . “\n”;
[/php]