Page 1 of 1

How to send form to assigned emails depending on chosen opti

Posted: Wed Jan 03, 2007 3:37 am
by maciek4
feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


Lets say I have 5 different options in my combo box (5 different languages)

English
German
Polish
Italian
Russian

when one choses English, I want the email to be sent to english@english.com
when one choses German, I want the email to be sent to german@german.com
etc

different otion chosen, different email address that the form is sent to. How to do that?

[syntax="html"]<td width=\"60%\"><select size=\"1\" name=\"language\">
          <option>English</option>
          <option>German</option>
          <option>Polish</option>
          <option>Italian</option>
          <option>Russian</option>
          <option selected>Choose...</option>
        </select></td>

feyd | Please use[/syntax]

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Posted: Wed Jan 03, 2007 3:44 am
by Oren
Assuming the form's method is set to "post", use $_POST['language'] to see which language the user chose.

Edit: For more information see Working with forms in PHP.

Posted: Wed Jan 03, 2007 4:39 am
by hrubos
I would do :
page1.php

Code: Select all

<form method = "POST" action = "page2.php">
<td width=\"60%\"><select size=\"1\" name=\"language\">
          <option>English</option>
          <option>German</option>
          <option>Polish</option>
          <option>Italian</option>
          <option>Russian</option>
          <option selected>Choose...</option>
        </select></td>
page2.php

Code: Select all

bla bla....

Posted: Wed Jan 03, 2007 4:56 am
by Ollie Saunders
The other thing you will want to do is validate the input and use it to build your email address to send to.
To validate (which you should always do for security reasons) create an array of acceptable values and test (in_array() is good) that the input is one of them, blow the user out if it isn't. This is called white-listing.

Once you are sure the variable is a known and safe value use it to construct the email address using the concatenation operator (.).

For actually sending the email you can use mail() or, better, SwiftMailer library.