Using mail(): sending an array in an email<

windows

Guest
Hi there,

I have an online form where a user can select more than one checkbox. The selected checkbox values are placed into an array:


<input name="Talks[]" type="checkbox" value="1-Tom Jones" />
<input name="Talks[]" type="checkbox" value="2-John Smith" />


I want to send this array to an email address using mail(). I have used mail in the past just fine, an example being:


$Message = "To $Fname $Lname\n\nYou sent an email, well done.\n\nThanks,\n-Tatlar";

mail( "[email protected],$Email", "Subject: You sent me an email!", $Message, "From: $Fname $Lname<$Email>" ) ;


where $Email, $Fname and $Lname are other variables taken from the online form.

Now, back to the array. How do I get the array into the variable $Message?

I can print out all the values of the array in HTML thus:


print "<ul>\n";
if ( is_array( $Talks ) ) {
foreach ($Talks as $value) {
echo "<li>$value</li>\n" ;
}
}
print "</ul>\n";


But how do I get the variables $value from the array into the variable $Message? Should I somehow use:


$Message = "Hi there, here are the values from the array";
$Message .= "$value[0]";
$Message .= "$value[1]";


This seems a very inefficient way to add each variable, particular as I do not know ahead of time how many $Talks will be selected.

Thanks in advance for the help,

- Tatlaryou just answered you own question. if you don't know how many there are then just use this

$Message = "Hi there, here are the values from the array";
if ( is_array( $Talks ) ) {
foreach ($Talks as $value) {
$Message .= $value."\n" ;
}
}

and in the future if you want to print out an array just do this

print_r($Talks);Thanks Scoutt - you saved the day again.

I thought I was close, but needed nudging in the right direction.

- Tatlar
 
Back
Top