How to send form to assigned emails depending on chosen opti

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
maciek4
Forum Commoner
Posts: 29
Joined: Tue Apr 04, 2006 8:17 am

How to send form to assigned emails depending on chosen opti

Post 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]
User avatar
Oren
DevNet Resident
Posts: 1640
Joined: Fri Apr 07, 2006 5:13 am
Location: Israel

Post 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.
hrubos
Forum Contributor
Posts: 172
Joined: Sat Oct 07, 2006 3:44 pm

Post 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....
User avatar
Ollie Saunders
DevNet Master
Posts: 3179
Joined: Tue May 24, 2005 6:01 pm
Location: UK

Post 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.
Post Reply