Email form

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

    Email form

    Sorry beginners question..

    The following link http://www.schott-systeme.com/en/logintest.php is a
    test secure login page for our customers.

    Type in 123-456-BSE and login, and it returns a form for the customer
    to check three typical bits of into, ie refno, name and email. This
    works ok and code is below.

    <?php
    //Process login
    if (isset($_POST['companyID'])) {
    // Check login
    $companyID = $_POST['companyID'];
    $resultlogin = @mysql_query ("SELECT userID, username, useremail FROM
    schott_news WHERE userID='$compan yID'");
    while ($row = mysql_fetch_arr ay($resultlogin ))
    {
    $userID = $row['userID'];
    $username = $row['username'];
    $useremail = $row['useremail'];
    }
    if ($_POST['companyID'] = $userID)
    {
    $_SESSION['authorized'] = TRUE;
    }
    }
    //Process logout
    if (isset($_SESSIO N['authorized'])) {
    //Display secure information
    ?>
    <h1>Please complete all information</h1>
    <div>
    <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
    <label>UserID :
    <input type="text" name="code" value="<?php echo $userID;
    ?>"/></label><br />
    <label>User Name:
    <input type="text" name="name" value="<?php echo $username;
    ?>"/></label><br />
    <label>User E-Mail:
    <input type="text" name="email" value="<?php echo $useremail;
    ?>"/></label>
    <input type="submit" value="Submit" />
    </form>
    </div>
    <p><a href="<?php echo $_SERVER['PHP_SELF']; ?>?logout=1">Lo g
    OUT</a></p>
    <?php
    } else {
    //Display login form
    ?>
    <h1>Please Enter Company Ref No</h1>
    <div>
    <form action="<?php echo $_SERVER['PHP_SELF']; ?>"
    method="post">

    <label>User ID:
    <input type="text" name="companyID " /></label>
    <input type="submit" value="log IN" />
    </form>
    </div>
    <?php
    }
    ?>

    I want to now click on Submit, and the form results are emailed to
    test@test.com and the user logged out.

    What is the easiest way to achieve this?

    Many thanks

    Alec

  • Erwin Moller

    #2
    Re: Email form

    Alec wrote:
    Sorry beginners question..
    >
    The following link http://www.schott-systeme.com/en/logintest.php is a
    test secure login page for our customers.
    >
    Type in 123-456-BSE and login, and it returns a form for the customer
    to check three typical bits of into, ie refno, name and email. This
    works ok and code is below.
    >
    <?php
    //Process login
    if (isset($_POST['companyID'])) {
    // Check login
    $companyID = $_POST['companyID'];
    $resultlogin = @mysql_query ("SELECT userID, username, useremail FROM
    schott_news WHERE userID='$compan yID'");
    while ($row = mysql_fetch_arr ay($resultlogin ))
    {
    $userID = $row['userID'];
    $username = $row['username'];
    $useremail = $row['useremail'];
    }
    if ($_POST['companyID'] = $userID)
    {
    $_SESSION['authorized'] = TRUE;
    }
    }
    //Process logout
    if (isset($_SESSIO N['authorized'])) {
    //Display secure information
    ?>
    <h1>Please complete all information</h1>
    <div>
    <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
    <label>UserID :
    <input type="text" name="code" value="<?php echo $userID;
    ?>"/></label><br />
    <label>User Name:
    <input type="text" name="name" value="<?php echo $username;
    ?>"/></label><br />
    <label>User E-Mail:
    <input type="text" name="email" value="<?php echo $useremail;
    ?>"/></label>
    <input type="submit" value="Submit" />
    </form>
    </div>
    <p><a href="<?php echo $_SERVER['PHP_SELF']; ?>?logout=1">Lo g
    OUT</a></p>
    <?php
    } else {
    //Display login form
    ?>
    <h1>Please Enter Company Ref No</h1>
    <div>
    <form action="<?php echo $_SERVER['PHP_SELF']; ?>"
    method="post">
    >
    <label>User ID:
    <input type="text" name="companyID " /></label>
    <input type="submit" value="log IN" />
    </form>
    </div>
    <?php
    }
    ?>
    >
    I want to now click on Submit, and the form results are emailed to
    test@test.com and the user logged out.
    >
    What is the easiest way to achieve this?
    Hi,

    A few pointers:
    1) Use the buildfunction mail().
    See www.php.net for details.

    2) When you use one script to do everything, you are only making your life
    unneeded difficult. You code will end up with a spaghettilike logictree to
    handle each situation. A situation you should avoid.
    Consider changing your action-tag in the form into another script, like
    logout_and_emai l.php where you handle the logic.
    You script shows that you already know how to retrieve information from a
    POST. I suggest you take the logic for emailing to a new script.

    3) How to end a session?
    This can be done in many ways.
    Here is one that empties the session, but keeps the session (id) around for
    future use:
    $_SESSION = array();
    or
    session_destroy ()


    Read it all here:


    Regards,
    Erwin Moller
    >
    Many thanks
    >
    Alec

    Comment

    Working...