treehouse : what would you like to learn today?
Web Design Web Development iOS Development

forms

  • hi all,

    is it possible to create a form that will send an email to different email addresses based on what is entered in the form?

    say for example there was a company who had branches all over the world, but one centralized website that they all used. and on the contact form they wanted the customers to beable to choose what country they are from and then send the form data to the appropriate person?

    I hope I explained it clear enough :-)
    thanks
  • The simple answer: yes.

    How are you handling your form? If your using php then you can do a simple if, else if statement to set a variable for the to address based on the input of your form.


    <?php
    $country = $_REQUEST['country'];

    if ($country == USA) {
    $toAddress = infoUSA@yoursite.com;
    } else if ($country == UK) {
    $toAddress = infoUK@yoursite.com;
    } else if ($country == WhatEv {
    $toAddress = inforWhatEv@yoursite.com;
    }

    mail($toAddress, \"Website Contact\", $body, \"From: $email\");
    header(\"Location: http://www.yoursite.com/thanks.php\");
    ?>
  • Thanks cotton thats exactly what I needed :-)