Maybe I should have posted my thread in the noob-category ...
When I use djjjozsi's solution the results get presented as "Array" in the e-mail. The same thing happends when I use the method in the tutorials halojoy referred to ...
This is my new xhtml:
<form method="post" action="sendmail.php" style="margin-top: 13px; margin-bottom: 0px;">
<br />
<h2>Question 1</h2>
<br />
<input type="radio" name="education" value="A" /> No
<br />
<input type="radio" name="education" value="B"/> Yes, some courses
<br />
<input type="radio" name="education" value="C"/> Yes, several years
<br />
<br />
<h2>Question 2</h2>
<br />
<input type="checkbox" name="media[]" value="A" /> Newspaper
<br />
<input type="checkbox" name="media[]" value="B" /> Website
<br />
<input type="checkbox" name="media[]" value="C" /> E-magazine
<br />
<input type="checkbox" name="media[]" value="D" /> E-mail
<br />
<input type="checkbox" name="media[]" value="E" /> TV
<br />
<br />
<input class="button" type="submit" value="Send" style="font-family: Arial, sans-serif; font-size: 12px;"/>
<input class="button" type="reset" value="Reset" style="font-family: Arial, sans-serif; font-size: 12px; margin-left: 3px;"/>
</form>
and the two verions of php I've tried:
<?php
// Get all $_POST variables
foreach($_POST as $var => $val)
{
${$var} = $val;
}
if(isset($_POST["media"]))
$body.="Selected media" . implode("," , $_POST["media"]);
else
$body.="media is empty" ;
// Set up the email body
$body_body .= "ANSWERS:\n";
$body_body .= " Education-------------| ".$education."\n";
$body_body .= " Choice of media-------| ".$media."\n";
$body_body .= " Decisions-------------| ".$decisions."\n";
$to = 'Josefina <myemail@yahoo.com>';
$subject = 'Survey';
$body = $body_body;
mail($to, $subject, $body);
/*
echo '<div style="white-space: pre">';
print_r(str_replace("\n", "<br />",$body));
echo '</div>';
*/
?>
<?php
// Get all $_POST variables
foreach($_POST as $var => $val)
{
${$var} = $val;
}
$media=$_POST['media'];
while (list ($key,$val) = @each ($media)) {
echo "$val,";
}
// Set up the email body
$body_body .= "ANSWERS:\n";
$body_body .= " Education-------------| ".$education."\n";
$body_body .= " Choice of media-------| ".$media."\n";
$body_body .= " Decisions-------------| ".$decisions."\n";
$to = 'Josefina <myemail@yahoo.com>';
$subject = 'Survey';
$body = $body_body;
mail($to, $subject, $body);
/*
echo '<div style="white-space: pre">';
print_r(str_replace("\n", "<br />",$body));
echo '</div>';
*/
?>
In both cases my e-mail says:
Education--------------| B
Choice of media------| Array
What am i doing wrong? (Probably all of it 🙂
/Josefina