Link to home
Start Free TrialLog in
Avatar of Refael
RefaelFlag for United States of America

asked on

php form to email with checkboxes

In a PHP form to Email I have 5 Checkboxes such as:

<input type="checkbox" name="Subject_Requested[]" id="English" value="English" />English
<input type="checkbox" name="Subject_Requested[]" id="Science" value="Science" />Science
<input type="checkbox" name="Subject_Requested[]" id="Maths"  value="Maths" /> Maths

I need to print/echo only the one that has been checked by the user:
Since the output is sent by email i included all the variables inside of the email "body" such as:

===========================================
$body ="

foreach ($Subject_Requested as $value) {
echo $value.'<br />'
};"

=============================================

But it does not seem to work. I know I should create the loop outside the "body" and then call the function, but I do not know how and I am not sure if I am right :-)

Please help..........
Avatar of sakuya_su
sakuya_su

I had the following test files:

<form action="test.php" method="post">
<input type="checkbox" name="Subject_Requested[]" id="English" value="English" />English
<input type="checkbox" name="Subject_Requested[]" id="Science" value="Science" />Science
<input type="checkbox" name="Subject_Requested[]" id="Maths"  value="Maths" /> Maths
<INPUT type="submit" value="Send">
</form>
----------------
<?php

foreach ($Subject_Requested as $value) {
echo $value.'<br />';
}

?>

and it worked fine?
Avatar of Refael

ASKER

sakuya_su

the problem is that i have this code inside of the email body....
$body ="foreach ($Subject_Requested as $value) {echo $value.'<br />'};"
it does bot read it ?! you know what i mean?

Avatar of Refael

ASKER

this is what i get in the email:

foreach (Spanish as ) { echo .'
'; }

i think its because its within the duble quote of the body message.....
Avatar of Refael

ASKER

i have found the solution.....

outside the body i added:
=======================================
foreach($_POST['Subject_Requested']as $value){
$check_msg.="$value<br>";}
======================================

then in the body i just the $check_msg

work great!
ASKER CERTIFIED SOLUTION
Avatar of Computer101
Computer101
Flag of United States of America image

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