Multiple email addresses in a form with formmail

  • louve_vix
  • Newbie
  • Newbie
  • User avatar
  • Posts: 13

Post 3+ Months Ago

I have a form with a drop down box that has two email addresses. I would like the form to go to two different email addresses based on which one of the two options was selected. The form has to go to the URL where my formmail file is located. When I upload the page and submit my form, it gives me this email warning. There should be no warning. Usually in the hidden field for recipient, I put in the email address it's supposed to go to, however since I have more than one,
what do I put for the value for recipient?
My code so far is below:

Code: [ Select ]
<script language="JavaScript" type="text/JavaScript">
function setEmail(){
theForm = document.mailForm;
theForm.action = "mailto:" + theForm.me.options[theForm.me.selectedIndex].value;
}
</script>

<form name="mailForm" method="post" action="http://www.whatever/cgi-bin/formmail.pl" enctype="text/plain"> 
<input type=hidden name="recipient" value="">
             <input type=hidden name="subject" value="Form Mail from Whatever Page">
             <input type=hidden name="redirect" value="http://www.something.com/redirect.html">

<td height="22">City:</td>
       <td><select name="me" size="1" onchange="setEmail()">
        <option value="me@something.com">Location1</option>
        <option value="you@something.com" selected>Location2</option>
       </select></td>
  1. <script language="JavaScript" type="text/JavaScript">
  2. function setEmail(){
  3. theForm = document.mailForm;
  4. theForm.action = "mailto:" + theForm.me.options[theForm.me.selectedIndex].value;
  5. }
  6. </script>
  7. <form name="mailForm" method="post" action="http://www.whatever/cgi-bin/formmail.pl" enctype="text/plain"> 
  8. <input type=hidden name="recipient" value="">
  9.              <input type=hidden name="subject" value="Form Mail from Whatever Page">
  10.              <input type=hidden name="redirect" value="http://www.something.com/redirect.html">
  11. <td height="22">City:</td>
  12.        <td><select name="me" size="1" onchange="setEmail()">
  13.         <option value="me@something.com">Location1</option>
  14.         <option value="you@something.com" selected>Location2</option>
  15.        </select></td>
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • ATNO/TW
  • Super Moderator
  • Super Moderator
  • User avatar
  • Posts: 23456
  • Loc: Woodbridge VA
  • RichB
  • Guru
  • Guru
  • User avatar
  • Posts: 1121
  • Loc: Boston

Post 3+ Months Ago

I think this may be a slightly different problem. If the form must use the formmail script then changing the action of the form is not an option. Instead the script could change the value of the hidden recipient field to whichever email address is selected. Since the recipient field will only be set when the select box changes, the value of the recipient field would be initially set to the same as the first choice in the select field in case the user does not change it.

Code: [ Select ]
<script language="JavaScript" type="text/JavaScript">
function setEmail(){
theForm = document.mailForm;
theForm.recipient.value = theForm.me.options[theForm.me.selectedIndex].value;
}
</script>

<form name="mailForm" method="post" action="http://www.whatever/cgi-bin/formmail.pl">
<input type=hidden name="recipient" value="me@something.com">
<input type=hidden name="subject" value="Form Mail from Whatever Page">
<input type=hidden name="redirect" value="http://www.something.com/redirect.html">

<td height="22">City:</td>
<td><select name="me" size="1" onchange="setEmail()">
<option value="me@something.com">Location1</option>
<option value="you@something.com" selected>Location2</option>
</select></td>
  1. <script language="JavaScript" type="text/JavaScript">
  2. function setEmail(){
  3. theForm = document.mailForm;
  4. theForm.recipient.value = theForm.me.options[theForm.me.selectedIndex].value;
  5. }
  6. </script>
  7. <form name="mailForm" method="post" action="http://www.whatever/cgi-bin/formmail.pl">
  8. <input type=hidden name="recipient" value="me@something.com">
  9. <input type=hidden name="subject" value="Form Mail from Whatever Page">
  10. <input type=hidden name="redirect" value="http://www.something.com/redirect.html">
  11. <td height="22">City:</td>
  12. <td><select name="me" size="1" onchange="setEmail()">
  13. <option value="me@something.com">Location1</option>
  14. <option value="you@something.com" selected>Location2</option>
  15. </select></td>
  • mika_jussi
  • Born
  • Born
  • mika_jussi
  • Posts: 1

Post 3+ Months Ago

RichB wrote:
I think this may be a slightly different problem. If the form must use the formmail script then changing the action of the form is not an option. Instead the script could change the value of the hidden recipient field to whichever email address is selected. Since the recipient field will only be set when the select box changes, the value of the recipient field would be initially set to the same as the first choice in the select field in case the user does not change it.

Code: [ Select ]
<script language="JavaScript" type="text/JavaScript">
function setEmail(){
theForm = document.mailForm;
theForm.recipient.value = theForm.me.options[theForm.me.selectedIndex].value;
}
</script>

<form name="mailForm" method="post" action="http://www.whatever/cgi-bin/formmail.pl">
<input type=hidden name="recipient" value="me@something.com">
<input type=hidden name="subject" value="Form Mail from Whatever Page">
<input type=hidden name="redirect" value="http://www.something.com/redirect.html">

<td height="22">City:</td>
<td><select name="me" size="1" onchange="setEmail()">
<option value="me@something.com">Location1</option>
<option value="you@something.com" selected>Location2</option>
</select></td>
  1. <script language="JavaScript" type="text/JavaScript">
  2. function setEmail(){
  3. theForm = document.mailForm;
  4. theForm.recipient.value = theForm.me.options[theForm.me.selectedIndex].value;
  5. }
  6. </script>
  7. <form name="mailForm" method="post" action="http://www.whatever/cgi-bin/formmail.pl">
  8. <input type=hidden name="recipient" value="me@something.com">
  9. <input type=hidden name="subject" value="Form Mail from Whatever Page">
  10. <input type=hidden name="redirect" value="http://www.something.com/redirect.html">
  11. <td height="22">City:</td>
  12. <td><select name="me" size="1" onchange="setEmail()">
  13. <option value="me@something.com">Location1</option>
  14. <option value="you@something.com" selected>Location2</option>
  15. </select></td>


Hi there,

I'm struggeling with the same problem that Rich B was giving his solution for and tried to use this script above to solve it. But now there was a new problem: instead of mailing the form to the email selected, it always sends it to the first mail in the list. What could be causing it - and are there any fool proof ways to get it working?

Thanx in advance, anyone who could give me some advice.
  • RichB
  • Guru
  • Guru
  • User avatar
  • Posts: 1121
  • Loc: Boston

Post 3+ Months Ago

Actually, now that I have my brain turned on, I don't think you need javascript at all for this. I was thinking in terms of the previous problem, but in this case you could just name the select field "recipient" if you're using formmail.

Code: [ Select ]
<form name="mailForm" method="post" action="http://www.whatever/cgi-bin/formmail.pl">

<input type=hidden name="subject" value="Form Mail from Whatever Page">
<input type=hidden name="redirect" value="http://www.something.com/redirect.html">
<select name="recipient" size="1">
<option value="me@something.com">Location1</option>
<option value="you@something.com" selected>Location2</option>
</select>
<input type="submit">
</form
  1. <form name="mailForm" method="post" action="http://www.whatever/cgi-bin/formmail.pl">
  2. <input type=hidden name="subject" value="Form Mail from Whatever Page">
  3. <input type=hidden name="redirect" value="http://www.something.com/redirect.html">
  4. <select name="recipient" size="1">
  5. <option value="me@something.com">Location1</option>
  6. <option value="you@something.com" selected>Location2</option>
  7. </select>
  8. <input type="submit">
  9. </form

Post Information

  • Total Posts in this topic: 5 posts
  • Users browsing this forum: No registered users and 43 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.