I need to add a drop down list of email addresses to a basic html form, so you can pick who you are sending it to.
August 15, 2007 7:44 AM   Subscribe

I need to add a drop down list of email addresses to a basic html form, so you can pick who you are sending it to.

Is there an easy way to do this? I don't really know how to pass that variable down to the line.
posted by andrewzipp to Computers & Internet (5 answers total)
 
Response by poster: forgot to remove the <>'s

I meant, I don't really know how to pass that variable down to the

input name="mail_to" type="hidden" id="mail_to" value="the_right_email_address@whatever.com"

line
posted by andrewzipp at 7:46 AM on August 15, 2007


well, in theory, you can simply change the <input&gt from a hidden to a select with the same name (ie, <select name='mail_to'> and then fill out the options like so <option value="foo@bar.com">foo@bar.com</option>, but this is not the best way to go about this

what you should do is remove the 'to' email from the form submit -- if your current form setup does not do input checking on the email, folks could send a POST (or possibly get, depending on how crappy the handler is) request to your server and email whoever they want. If you're also allowing the form to submit content, you're basically letting spammers mail people using your server, not to mention letting them harvest emails from the source of that form. Ideally (and I haven't worked with contact forms for awhile, so this info may be outdated), you should set up your form so emails are contained within the handler code and NOT the form HTML. A simple way to do this is (in PHP)

<select name=mail_recipient>
<option name=1>Foo Bar</option>

...

then in the back end you would assign the email depending on the value of 'mail_recipient'

<?php
switch ($_POST['mail_recipient']) {
case '1':
$mail_to='foo@bar.com';
...
default:
exit;
}

...

etc

I would recommend looking around for existing form solutions if you don't feel confident enough programming this sort of thing yourself.
posted by fishfucker at 8:05 AM on August 15, 2007


annndd. no breaks in my switch, but you get the idea.
posted by fishfucker at 8:05 AM on August 15, 2007


Stephen Ostermiller's contact form does this and is sophisticated and very good at spam prevention (although no CAPTCHA yet)

Stevie Ostermiller & his marvellous contact form
posted by dance at 11:12 AM on August 15, 2007


when you say a "basic form" are you posting a form to an email address? e.g.

<form action="mailto:someone@foo.com">

as mentioned, don't do that. it's messy, requires people to have a mail client installed (won't work for if they use web email) or are borrowing someone's computer (internet cafe, lobby in hotel, etc.) and you'll get spam.

spend the time to configure a contact form. most webhosts have something for this. (although quality varies.)
posted by kamelhoecker at 6:12 AM on August 16, 2007


« Older SF Bound   |   Suddenly.... *HAND SHOOTS OUT OF THE GROUND* Newer »
This thread is closed to new comments.