Ask Me Help Desk

Ask Me Help Desk (https://www.askmehelpdesk.com/forum.php)
-   Other Web Development (https://www.askmehelpdesk.com/forumdisplay.php?f=467)
-   -   E-mail and web forms (https://www.askmehelpdesk.com/showthread.php?t=205085)

  • Apr 12, 2008, 09:57 AM
    alwysAThm
    e-mail and web forms
    How can I make it to where you can select from a dropdown list and have it go to different e-mails
  • Oct 16, 2008, 06:56 PM
    jthomsonmain
    Time to dust off the old Form processing script!
    For the sake of my sanity, I am going to assume (In other words, make an of you and me) that you already know how to make HTML forms and PHP scripts to process them. This is the code that needs to go into your HTML File:

    Code:

    <select name = "EmailTo">
          <option value = "[email protected]">[email protected]</option>
          <option value = "[email protected]">[email protected]</option>
          <option value = "[email protected]">[email protected]</option>
    </select>

    In the PHP Script, you just 'trim' it like you would any other form variable:
    Code:

    $EmailTo = Trim(stripslashes($_POST['EmailTo']));
    All in all, this is a complete overview of my Source code for a simple email script:

    index.htm
    Code:

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/transitional.dtd">
      <head>
        <title>Example Email Form</title>
        <link href="style.css" rel = "stylesheet" type = "text/css">
      </head>
     
      <body>
        <form method="POST" action="post.php">
        <h1>Example Email Form</h1>
       
        <p>Recipiant Email Address:</p>
        <select name = "EmailTo">
          <option value = "[email protected]">[email protected]</option>
          <option value = "[email protected]">[email protected]</option>
          <option value = "[email protected]">[email protected]</option>
        </select>
        <br>
        <p>Subject: <input type="text" name="subj"></p>
        <p>Message:</p>
        <textarea name = "msg" rows = "20" cols = "40">Enter Message Here</textarea>
        <p><input type="submit" name="submit" value="Submit"></p>
        <br><br><br><br>
        </form>



    post.php
    Code:

    <?php

    $EmailFrom = "[email protected]";
    $EmailTo = Trim(stripslashes($_POST['EmailTo']));
    $Subject = Trim(stripslashes($_POST['subj']));
    $Message = Trim(stripslashes($_POST['msg']));

    $Body = "";
    $Body .= $Message;
    $Body .= "\n";

    $Success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>");

    if ($Success)
    {
      echo "Form Submited";
    }
    else
    {
      echo "ERROR: UNKNOWN";
    }
    ?>

    I have also uploaded the script to my webserver. The email function has been dissabled, but this will show you what it looks like: http://jthomsonmain.server1.cc/dev/examp/mail/mail.htm

  • All times are GMT -7. The time now is 07:41 AM.