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

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • tomseye

    #1

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

    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="checked 2.php"><br>
    <input type="checkbox" name="foo[]"
    value="Auto">Au to Insurance
    <input type="checkbox" name="foo[]"
    value="Life">Li fe Insurance
    <input type="checkbox" name="foo[]"
    value="Home">Ho me 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
  • Erwin Moller

    #2
    Re: How to display html form selects (via checkbox) in email?

    tomseye wrote:
    [color=blue]
    > 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![/color]

    What is your problem?


    [color=blue]
    >
    > tomseye
    >
    >
    >
    > <body>
    > <br>
    > <b>Please select the information you'd like to
    > receive:</b>
    > <br>
    >
    > <form method="post"
    > action="checked 2.php"><br>
    > <input type="checkbox" name="foo[]"
    > value="Auto">Au to Insurance
    > <input type="checkbox" name="foo[]"
    > value="Life">Li fe Insurance
    > <input type="checkbox" name="foo[]"
    > value="Home">Ho me Insurance
    > <br><br>
    > <input type="submit" value="Submit">
    > <input type="reset" value="Clear">
    > </form>[/color]

    So far so good.
    [color=blue]
    >
    > <?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'];[/color]

    $bodyOfEmail = "";
    [color=blue]
    > if (count($foo) > 0) {[/color]

    Why use this if-statement?
    If count($foo) is 0, you will not enter the loop.
    Remove it for clarity's sake.

    [color=blue]
    > // 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";[/color]

    $bodyOfEmail .= $foo[$i]."\n";
    [color=blue]
    >
    > } // end "for" loop
    >
    > } // endif
    > echo "<br>";
    > echo "insurance products.\n";
    > ?>[/color]


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

    Regards,
    Erwin Moller
    [color=blue]
    > :lol:[/color]

    What are you laughing about?
    [color=blue]
    > http://eye.cc php newsgroups[/color]

    Comment

    Working...