Forum Moderators: coopster

Message Too Old, No Replies

PHP Formmail send mail to user defined address

         

aharen

1:17 pm on Sep 9, 2006 (gmt 0)

10+ Year Member



Hi..I'm using Jack's Formmail.php and i am trying to make the script to send the mail it generates to the email address defined by the user..I have a drop down menue which shows the e-mail addresses and the user will hav to select one. When the form is submited it should send the mail to the selected address. I've searched all over web and specialy this site but with no luck.. Can anyone help..please?

Thanx in advance for n e reply,
Cheers

jatar_k

4:02 pm on Sep 9, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Welcome to WebmasterWorld aharen,

>> When the form is submited it should send the mail to the selected address.

do you get errors? or what is happening specifically? nothing?

did you add this drop down box yourself? You don't need to paste all the code but maybe the part that you added to deal with the new drop down.

aharen

7:13 pm on Sep 9, 2006 (gmt 0)

10+ Year Member



thanx jatar_k :-)

No the form works perfectly wen it is send to one email adress i just want to modify the script and i hav no idea how to do that. Yea i added the drop down its a simple html dropdown in the html page, here's the code;

<td align="left"><select name="to" id="to">
<option value="One" selected="selected">One</option>
<option value="Two">Two</option>
<option value="Three">Three</option>
</select></td>

i just dont know how to edit 'Jack's Formmail.php' to work with it..

Thanx
Cheers

jatar_k

4:56 pm on Sep 10, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



did the form use a text box for the 'to' address before or was it hard coded to a single address?

you will need to look at the function call for the mail function
look at the variable it uses for the first parameter
find where that vaiable is set in the code
then make sure your drop down value is being pushed into that variable

you will need to add a little error checking to make sure no one passes bad values

I would suggest using an integer for the values and having the actual addresses in the formmail script, something like this

<td align="left"><select name="to" id="to">
<option value="1" selected="selected">first person</option>
<option value="2">second person</option>
<option value="3">third person</option>
</select></td>

then in the formmail script

switch ($_POST['to']) { 
case 1:
$to = 'address1@example.com';
break;
case 2:
$to = 'address2@example.com';
break;
case 3:
$to = 'address3@example.com';
break;
default:
$to = false;
break;
}
if (!$to) {
echo 'you selected a bad value, shame on you';
die();
}

obviously the last bit is not proper error handling but I don't know how yours is done. You could then use the variable $to in your mail function call.

aharen

8:37 am on Sep 11, 2006 (gmt 0)

10+ Year Member



thanx alot jatar_k :-),
it works now!..
i disabled the default $recepient and renamed $to to $recepient..and it works fine..thanx alot for your help and time..

cheers mate :)