Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Selectable Mailto Field 1

Status
Not open for further replies.

Lukey

Technical User
Jul 5, 2000
103
GB
Hi,
I am trying to create a mailto form which has a drop down for the mailto email address. I need the user to be able to select from several addresses and then submit the form to that address.
I would be very greatful if anyone could point me in the right direction.

Thanks
 
I had a search around and found the following which is exactly what I was looking for. I have been trying to add a different subject in for each of the mail addresses but not too sure how it works. If anyone has any pointers, that would be great.

Thanks

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>New Page 1</title>
</head>
<body>
<!-- Add this to the <head> section -->
<script language="JavaScript" type="text/javascript">
function GotoURL() {
location.href="mailto:" + document.getElementsByName("picker")[0].value;

}
</script>
<!-- Add this to the <body> section -->
<!-- Obviously, you should edit the code to show your own URLs, and you can change the style attributes to suit your colour scheme -->
<form name="go" id="go">
<select name="picker" id="picker" style="font-family: Arial, Helvetica, sans-serif;">
<option value="hi@hi.com" style="background-color: #e0e0e0;" selected>Home Page</option>
<option value="hello@hello.com">Contents</option>
<option value="goodbye@goodbye.com" style="background-color: #e0e0e0;">Webmaster</option>
<option value="lol@lol.com">Tools I use</option>
</select>
<input type="button" value="Go" style="color:#FFFFFF;background:#CC9900" title="Click to Go" onClick="GotoURL()">
</form>
</body>
</html>
 
Very easy.
Just append the subject into to the email address value in your select box like this:

Code:
<option value="someone@somewhere.com?Subject=About%20your%20cat!">

Make sure you replace any spaces in the subject with %20.
You can also add on CC and BCC values.

Code:
<option value="someone@somewhere.com?cc=johndoe@smith.net&bcc=melonchitlin@blind.org&subject=How%20about%20them%20Yankees?">


It's hard to think outside the box when I'm trapped in a cubicle.
 
Perfect, cheers for your help Nite Owl. I have one last problem which is probably really straight forward but I am new to this.

I can add input fields to the page but can't get the responses to send in the email, the mail just comes up blank. Any further help would be great.

Cheers
 
That gets a little trickier.
I take it you want the person to be able to type info into a field and then have that included in the email?

You can do it by having your javascript function read the value of the input field escape the value so it will not contain any characters that are invalid on the URL and then append it to your string for the location.href command.

Add this field to your form:
Code:
<input type="text" [COLOR=red]id[/color]="mailBody">

Then use this modified function:

Code:
function GotoURL() {
  var mBody = '';
  if (document.getElementById('mailBody').value != '')
    mBody = "&body=" + escape(document.getElementById('mailBody').value);
  location.href="mailto:" + document.getElementsByName("picker")[0].value + mBody;
}

The problem here is that you can only pass so many characters across the URL so you have to limit how much info they can type into the field on the form.


It's hard to think outside the box when I'm trapped in a cubicle.
 
Genius ! Thanks, that is exactly what I was looking for. Does that mean that I am only able to put one text field in there as there is a restriction on the amount of text that can be sent ?

Many thanks
 
I believe the limit is 255 characters. You could put in as many as you like but the text will get cut at 255 including the email address and subject.

The other drawback to this method is of course that it relies on the end-user to have email software setup on their PC. If they use only web based email then the mailto link will not work. Or if the person is on someone else's computer it could be reporting the wrong return address, etc.

It is much better to make use of server-side email if you can then you do not have limits on the amount of text and you can even format the email with HTML to make it look better.

It's hard to think outside the box when I'm trapped in a cubicle.
 
Thanks again. I am hoping to use this solution for a bit until I can sort out a server-side version.

Many Thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top