On my contact form I want to allow the user to pick who they want the email to go to. So I’m going to have a drop-down list where they can select the person. How would I do this? Or would this be done with PHP?
@novemberGreyauthorApr 04.2007 — #Sorry for the lack of information. There will probably be around 10 different emails to choose from. I would like to send the form server side via PHP. And yes I would like the form to be accessible to those with js diabled.
@ricpApr 04.2007 — #Ok, if you need this to be non-js supportable then we would need to move just about all the processing onto the server side. The process I would go with is this one..
1) While parsing/generating the page on the server side, include the emails using php, so you have something like..
[code=html] <form method="post" action="emailForm.php"> <select name="email"> <? populateEmailAddresses() ?> </select> <input type="submit" value="Email"/> : // include any further form elements : </form> [/code]
inside the populateEmailAddresses() function in the php is code to output the addresses in the format like so..
The page is then all sent to the client with a form which will pass the selected email address to the page emailForm.php
2) Inside emailForm.php you have the php code for manipulating the POST values sent and initialising the message to be sent through SMTP, then sending it.
Basically there is no JS in there, even the form submission is handled "naturally" on the client to avoid the need for JS. You could overload the form using JS and have xmlhttp send the value of the selected email to a server side script that would send what it needs to. That would at least allow those with script enabled to avoid submitting/reloading the page.
@pcthugApr 04.2007 — #You could have a select field like so: [code=html] <select name="to"> <option value="0">John</option> <option value="1">Jill</option> <option value="2">Bill</option> </select> [/code]
@TaschenApr 04.2007 — # [code=html] <option value="[email protected]"> foo </option> [/code] [/QUOTE] I would strongly advise you not to follow the above method. Where possible never publish an email address directly to your website in plain text, it aids spam harvesters.
Rather make your value a resource identifier of the form 'n' [code=html] <option value="n1"> foo </option> [/code] Use this to access an array of email address in your php script [code=php]$available_mail_addresses = array("n1"=>"[email protected]", "n2" => "[email protected]");[/code] Hard coding email addresse into you mail processing script will also make it harder for your form processor to be abused by third parties.
And I see that while I was writing that PC Thug replyed on similar lines.
@ricpApr 04.2007 — # Where possible never publish an email address directly to your website in plain text, it aids spam harvesters.[/QUOTE] It's a fair point, I had overlooked that when I was doing the generalisation, but it's definitely valid.
That said, is there such a thing as a spam free email address?
@novemberGreyauthorApr 04.2007 — #I uploaded my form and my PHP script to one server, and it wouldn't work for some reason. When I would click Submit it would give me a "couldn't find page error" and the address of the PHP script would be in the address bar. So then I uploaded my files in a different server and it worked perfectly. What do you think is the problem with the first server?