Forum Moderators: coopster

Message Too Old, No Replies

Menu chooses e-mail address to send to?

PHP form using <select> menu to choose receipient

         

charles_s

7:51 pm on Feb 2, 2004 (gmt 0)

10+ Year Member



I'd like to create a feedback form using PHP that the user can select to whom the e-mail is sent by a drop-down, <select> style menu. (i.e. Technicial Support, Customer Service, etc.)

I understand how to do a simple feedback script, and I understand how to create the menu, I'm just not sure how to tie the together.

Would anyone give me a hand on this?

jatar_k

8:21 pm on Feb 2, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



if you had a select element like so

<select name="email">
<option value="">select a dept</option>
<option value="1">sales</option>
<option value="2">marketing</option>
<option value="3">human resources</option>
</select>

You can access this in the script that the form posts to by accessing the $_POST [ca.php.net] superglobal array. First test to make sure a selection was made.

if ($_POST['email'] == "" ¦¦!isset($_POST['email'])) { 
echo "you didn't pick a dept";
} else {
switch ($_POST['email']) {
case 1:
$mail_to = "sales@example.com";
break;
case 2:
$mail_to = "marketing@example.com";
break;
case 3:
$mail_to = "hr@example.com";
break;
}
// then you can do your mail call here
$sub = "some subject";
$mess = "Message stuff";
$mailhead = "your preferred mail headers here";
mail($mail_to,$sub,$mess,$mailhead);
}

note: code in posts have the ¦ changed to a broken pipe char. Always replace pipes in pasted code