Hi.

I need to create a PHP form that, when submited, is sent to one of three e-mail addresses. The relevant e-mail address will be appropriated by a drop down box in the form that lists 3 different locations.

I.e. If the user selects the drop down location of London as their nearest location the form will be sent to london@hotmail.com. If they select Portsmouth the form will be sent to portsmouth@hotmail.com etc.

Does anyone know the code for this?? Thanks in advance.

    hi

    in your form you have a listbox like that:

    <select name="nearest_location" size=1>
    <option value="london">London</option>
    <option value="vienna">Vienna</option>
    ...
    </select>

    then you can set the recipients email according to
    the value of $nearest_location like this:

    if ($nearest_location == "vienna") $r_email = "vienna@mycomp.com";
    else if (...) $r_email = "...";

    hope that helps

    stefan

      Thanks Stefan

      That doesn't seem to work with the code I am using. Could you point me to some mail form code that you have previously used with that code you just sent me please? Thanks again.

        I can't find an example on this page that is relevant to sending mail from a form.

        Please could someone send me a link to some sample code where I can just copy and paste and change the relevant bits. I have tried several times with various code but it seems too ellaborate for what I need and doesn't work (due no doubt to to me messing it up).

        Apologies for being an idiot. I did this same function ages ago and I remember it being pretty easy.

        For example with this code I've used it won't even display the initial form page:

        http://www.harbourstudios.com/online_application.php

        Here's the initial code:

        <?php // <= This has to be the very first tag on your page. No comments, no whitespace. NOTHING!
        include("php/v.inc");
        include("php/q.inc");
        
        $validator = new ValidateForm();
        
        if ($HTTP_SERVER_VARS['REQUEST_METHOD'] == 'POST'){
        
        $validator->addCheck('First_and_Last_name');
        $validator->addCheckEmail('Email_address');
        $validator->addCheck('Comment');
        
        if ($validator->validate() && checkAnswer()){
        
          //send email or another action to be performed
        
        $SendTo = "oliver.coquelin@harbourstudios.com";
        $FromString .= "from: ". $validator->get("Email_address") ."\r\n";
        $Indhold .= "Navn: ". $validator->get("First_and_Last_name") ."\r\n";
        $Indhold .= "Email: ". $validator->get("Email_address") ."\r\n";
        $Indhold .= "Comment:\r\n".preg_replace("(\r\n|\r|\n)","\r\n",$validator->get("Comment"))."\r\n\r\n";
        
        $MailSuccess = mail($SendTo,$Subject,$Indhold,$FromString);
          header("Location: http://domain1263419.sites.fasthosts.com/online_application_thankyou.htm");
           exit;
         }
        }
        ?>
        

        I'm putting this on my form page above the opening HTML tag. It just results in the error mesages you can see at the link above.

          This may be a daft answer as I'm a newbie myself but doesn't "header" need to be "$header =" and does it need to be in the "mail" variable?

          The fact that there is a parse error with } involved normally is due to something not being opened or closed properly with () or []....

          Or maybe I'm off the beaten track well and truely...😉

            servedchilled wrote:

            doesn't "header" need to be "$header ="

            No, after he sends the mail he's using the [man]header/man function to redirect the user to a different page.

            As to the error, I don't see anything wrong with the code snippet you provided, so could you please copy and paste the entire contents of the script for us to see?

            Also, I see you're using the $HTTP*VARS, which have been deprecated some time ago. Instead, you should replace these types of variables with the corresponding superglobal array ($SERVER, $GET, $_POST, etc.) explained on this page: [man]variables.predefined[/man].

              Thanks. I'll take a look at those variable upgrades.

              http://domain1263419.sites.fasthosts.com/online_application.php

              The problem I am having seems to be with the incorporated Spam protection feature which is powered by the two include files. If you fill in these three fields:

              Position
              First Name
              E-mail (these are the only mandatory fields at the moment)

              Submit the form and you will see the problem. "The spamtrap question was not answered correctly!"

              I need to either get this feature working or disable it.

              This is the site I got the code from:

              http://www.geekministry.com/blog_article.php?id=93

              I have attached all the relevant files in a zip doc. Thank you.

                Looks to me as if at one time there was a field in the form that asked you what weekday it was, or possibly what weekday tomorrow is... something like that, I didn't look at the code very intensely.

                To remove this spamtrap, you'd need to remove lines 82-84 from online_application.php:

                  if ($HTTP_SERVER_VARS['REQUEST_METHOD'] == 'POST' && !checkAnswer()){
                      print "The spamtrap question was not answered correctly!";
                  }

                and change line 13:

                if ($validator->validate() && checkAnswer()){

                to:

                if ($validator->validate()){

                EDIT: Yeah, looking at the original, you're missing this:

                <label for="Spamtrap"><?php print AskQuestion();?>&nbsp;*</label><br />
                <input id="Spamtrap" type="text" alt="Please answer the spamtrap question" name="Spamtrap" value="<?php print $validator->get("Spamtrap");?>" /><br />

                  Hey Brad

                  Thanks for the advice. I did what you suggested and the form page submits and goes throught to the thank you page. However the form is not deliverd to my e-mail address. Do you have any idea why this may be?? Thanks again.

                    1. Comment out the header() line so it doesn't redirect you away from a page that may contain helpful error messages.

                    2. Ensure that display_errors is On and that error_reporting is set to E_ALL .

                    3. $Subject is never defined.

                    4. You start concatenating values to $Indhold when it wasn't even defined in the first place. You should make sure that you assign it a value first, and then use the ".=" concatenation method with the subsequent strings.

                    5. Your $FromString is used as the 4th parameter of the mail function. The 4th parameter of this function defined the e-mail headers. Not only do you not have any headers (MIME-Version, From, Content-Type, etc. etc.), but the string you're sending for this parameter ("Position: ...") isn't a valid e-mail header. If you meant for that to go in the body of the e-mail, make sure that you put that in the variable that holds the message contents. Then, make sure you add some valid e-mail headers... otherwise your e-mail will likely be marked as spam.

                    6. You store the returned value of the mail() call in a variable ($MailSuccess). Test if that value is TRUE and then redirect. Otherwise... well, obviously the mail() call failed. The manual page for the mail() function has some examples of this, I believe.

                      Write a Reply...