|
Posted by J.O. Aho on 10/13/42 11:38
Tyrone Slothrop wrote:
> On 18 Jan 2006 06:48:31 -0800, "pmAgony" <fncuis@gmail.com> wrote:
>
>> Hello-
>>
>> In my contact form, I have a drop down field that allows the user to
>> choose what department they want to send inquiry's to. The field is
>> labeled: "who".
>>
>> Each entry has a unique email address it needs to go to. How do I get
>> my php script to recognize the value in "who" when potentially there
>> are 4 different values stored in the "who" array?
>>
>> Then I need to drop in the 'if' value 3 is selected, mail($sendto);
>>
>> Can someone shead some knowledge?
>>
>> Thanks-
>
> When the form is posted, evaluate the value of the selected item:
>
> switch ($_POST['who'] {
> case 1: $sendto = "bob@somedomain.com"; break;
> case 2: $sendto = "mary@somedomain.com"; break;
> case 3: $sendto = "tom@somedomain.com"; break;
> case 4: $sendto = "jill@somedomain.com"; break;
> default: "admin@somedomain.com";
> }
>
> This assumes that the select passes 1-4 as values.
>
>
Or if you have all the email addresses in an array
address.php:
<?PHP
$addresses=array(
array("Department 1","bob@somedomain.com"),
array("Department 2","mary@somedomain.com"),
array("Department 3","tom@somedomain.com"),
array("Webmaster","jill@somedomain.com")
);
?>
having this in a file that is included for the formpage and for the page
processing the result from the form.
formpage.php:
<select name='who'>
<?PHP
include_once("address.php");
for($i=0;$i<count($addresses);$i++) {
echo "<option value='$i'".$addresses[$i][0]."</option>\n";
}
?>
</select>
processing.php
include_once("address.php");
$sendto=$addresses[$_POST['who']][1];
To add or remove an address, then just edit one file, the address.php.
//Aho
[Back to original message]
|