#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2011
    Posts
    5
    Rep Power
    0

    Email webform with form results


    I have a 2 part form that gathers all the data for me onto a 3rd page.

    What I want it to do is send all the gathered data to an email. I'm sure its easy but thats all i need it to do now. thanks for any help. Code for the 3 pages is below. Thanks!


    step1.php


    <form action="step2.php" method="post">
    <p>
    Loan Type:
    <select name="loanType">
    <option>Loan Type 1</option>
    <option>Loan Type 2</option>
    <option>Loan Type 3</option>
    </select>
    </p>
    <p>
    Property Type:
    <select name="peopertyType">
    <option>Property Type 1</option>
    <option>Property Type 2</option>
    <option>Property Type 3</option>
    </select>
    </p>
    <p>
    Property State:
    <select name="peopertyState">
    <option>Property State 1</option>
    <option>Property State 2</option>
    <option>Property State 3</option>
    </select>
    </p>
    <p><input type="submit" name="step1_submit" value="Continue &rarr;" /></p>
    </form>


    step2.php


    <?php
    session_start();
    if(isset($_POST['step1_submit']))
    {
    $_SESSION['step1_data'] = $_POST; /* add all data from step1 to session variable */
    ?>
    <form action="step3.php" method="post">
    <p>
    Credit Score:
    <select name="creditScore">
    <option>500 - 600</option>
    <option>600 - 700</option>
    <option>800 - 900</option>
    </select>
    </p>
    <p>
    Phone Number: <input type="text" name="phoneNumber" />
    </p>
    <p>
    Email Address: <input type="text" name="emailAddress" />
    </p>
    <p><input type="submit" name="step2_submit" value="Continue &rarr;" /></p>
    </form>
    <?php
    }
    else
    {
    ?>
    Please fill in <a href="step1.php">Step 1</a>
    <?php
    };
    ?>


    step3.php


    <?php
    session_start();
    if(isset($_POST['step2_submit']) && isset($_SESSION['step1_data']))
    {
    echo "Your data: <h1>Step 1</h1>";
    foreach($_SESSION['step1_data'] as $field => $value)
    {
    if($field != 'step1_submit')
    echo "<p><b>$field</b> = $value</p>";
    }
    echo "<h1>Step 2</h1>";
    foreach($_POST as $field => $value)
    {
    if($field != 'step2_submit')
    echo "<p><b>$field</b> = $value</p>";
    }
    }
    else
    {
    echo 'Fill in <a href="step1.php">Step 1</a>';
    }
    ?>
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2011
    Posts
    113
    Rep Power
    49
    Not an expert on PHP forms but, looking at about.com, you should only need something like the following:

    PHP Code:
    <?php
     $to 
    "recipient@example.com";
     
    $subject "Hi!";
     
    $body "Hi,\n\nHow are you?";
     if (
    mail($to$subject$body)) {
       echo(
    "<p>Message successfully sent!</p>");
      } else {
       echo(
    "<p>Message delivery failed...</p>");
      }
     
    ?>
    Obviously you will need to add your $_POST variables into the body section of the email, and you will need some kind of validation. Apparently you will need a PEAR module if you need SMTP authentication of any kind.

IMN logo majestic logo threadwatch logo seochat tools logo