By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,406 Members | 1,504 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,406 IT Pros & Developers. It's quick & easy.

How to display html form selects (via checkbox) in email?

P: n/a
I have a simple form to collect user selections in html form. I am
pretty new to php...how can I send the user's checkbox selects to me
in an email...I am struggling with buiding an array to send this info

mail() function. Any help appreciated... Thanks very much!

tomseye

<body>
<br>
<b>Please select the information you'd like to
receive:</b>
<br>

<form method="post"
action="checked2.php"><br>
<input type="checkbox" name="foo[]"
value="Auto">Auto Insurance
<input type="checkbox" name="foo[]"
value="Life">Life Insurance
<input type="checkbox" name="foo[]"
value="Home">Home Insurance
<br><br>
<input type="submit" value="Submit">
<input type="reset" value="Clear">
</form>

<?php

echo "You have chosen to receive information on: \n\n";
// check to be sure at least one option was selected<br>

$foo = $_POST['foo'];
if (count($foo) > 0) {
// loop through the array
for ($i=0;$i<count($foo);$i++) {

// do something - this can be a SQL query, echoing data to the
browser, or whatever

echo "<li>$foo[$i]\n";

} // end "for" loop

} // endif
echo "<br>";
echo "insurance products.\n";
?>
:lol:
http://eye.cc php newsgroups
Feb 21 '06 #1
Share this Question
Share on Google+
1 Reply


P: n/a
tomseye wrote:
I have a simple form to collect user selections in html form. I am
pretty new to php...how can I send the user's checkbox selects to me
in an email...I am struggling with buiding an array to send this info

mail() function. Any help appreciated... Thanks very much!
What is your problem?

tomseye

<body>
<br>
<b>Please select the information you'd like to
receive:</b>
<br>

<form method="post"
action="checked2.php"><br>
<input type="checkbox" name="foo[]"
value="Auto">Auto Insurance
<input type="checkbox" name="foo[]"
value="Life">Life Insurance
<input type="checkbox" name="foo[]"
value="Home">Home Insurance
<br><br>
<input type="submit" value="Submit">
<input type="reset" value="Clear">
</form>
So far so good.

<?php

echo "You have chosen to receive information on: \n\n";
// check to be sure at least one option was selected<br>

$foo = $_POST['foo'];
$bodyOfEmail = "";
if (count($foo) > 0) {
Why use this if-statement?
If count($foo) is 0, you will not enter the loop.
Remove it for clarity's sake.

// loop through the array
for ($i=0;$i<count($foo);$i++) {

// do something - this can be a SQL query, echoing data to the
browser, or whatever

echo "<li>$foo[$i]\n";
$bodyOfEmail .= $foo[$i]."\n";

} // end "for" loop

} // endif
echo "<br>";
echo "insurance products.\n";
?>

Now add insurance product if you like to $bodyOfEmail, and go mailing.

Regards,
Erwin Moller
:lol:
What are you laughing about?
http://eye.cc php newsgroups


Feb 21 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.