PDA

View Full Version : E-mail recipients from a drop down menu. Please provide code examples.



ComputerGuy523
19-Nov-2010, 10:18 PM
E-mail recipient chose from a drop down menu. Please provide code examples.

ginger23
20-Nov-2010, 12:37 AM
Hi,

You just need to name your select field "recipients".



<select name="recipients">
<option value="joeschmoe@yourdomain.com">Customer Service</option>
<option value="janedoe@yourdomain.com">Human Resources</option>
</select>


Of course, it's not a good idea to put email addresses in your form, so you'd be better off using a server side INI file, which is basically a configuration file where you can specify fields that you don't want viewable in the source code of your form. So, instead of specifying the email address itself as the option value, you would use the email alias in its place. The instructions for an INI file are here as well as how to use email aliases:

http://www.tectite.com/fmhowto/inifile.php

beatsmith
03-Dec-2010, 08:14 PM
Ok... what if you have two drop downs with e-mail addresses, and the recipients are pulled from here.

So
Drop down 1 has e-mail address 1 & 2.
Drop down 2 has e-mail address 3 & 4.

russellr
03-Dec-2010, 09:06 PM
Hi,

Very similar:


<select name="recipients">
<option value="joeschmoe@yourdomain.com,john@yourdomain.com">Customer Service</option>
<option value="janedoe@yourdomain.com,sally@yourdomain.com">Human Resources</option>
</select>

russellr
03-Dec-2010, 09:10 PM
Hi,

Sorry, I think I misunderstood your question.

"recipients" can be an array (add []), so you can do this:


<select name="recipients[]">
<option value="joeschmoe@yourdomain.com">Customer Service</option>
<option value="janedoe@yourdomain.com">Human Resources</option>
</select>

<select name="recipients[]">
<option value="john@yourdomain.com">Sales</option>
<option value="sally@yourdomain.com">Spares</option>
</select>


Not all versions of FormMail support the array feature, but it's in most recent versions (check the version history if in doubt).

beatsmith
03-Dec-2010, 09:54 PM
Brilliant, your second response look like the one I need so I'll give that a go.

I guess it will format them automatically with a comma seperating them for it to work?

beatsmith
06-Dec-2010, 10:38 AM
I think I've noticed a small issue with this method. Correct me if I'm wrong but using this method would mean that I cant have the two different options outputted individually in the e-mail template.

I would like to have:



E-mail one : $First_Dropdown
E-mail two : $Second_Dropdown


But it would have to be:


E-mail addresses: $recipients

russellr
06-Dec-2010, 12:13 PM
Hi,

Correct, but you wouldn't normally put the $recipients in the body of the email.

That's automatically in the To address in the email header.