Link to home
Start Free TrialLog in
Avatar of winkle
winkle

asked on

mailto: extendability

I'm trying to figure out how (or if) I can get a mailto: link to automatically insert some starter text into the mail message. Has anyone come across a way to do this?

Thanks
Avatar of fibdev
fibdev

You can use javascript to do this ...  This will fill in the subject, but I don't know about filling in the message body.

<SCRIPT language="JavaScript">
<!--
/* Mailto enhancement */

function e_friend()
{
var e_add= 'you@youraddy.com';
var subj= 'your subject here';
var e_body= 'enter some text here';
if ((subj==" ") || (subj==null))
 subj="Hi!";
window.location="mailto:"+e_add+"?subject="+subj;}
//-->
</SCRIPT>

Use this as the link:
<A HREF="javascript:e_friend2()">Email</A>


This may work too ...
<a href="mailto:you@youraddy.com?subject='your subject'">mail me!</a>
Nevermind that last one, I had to fix something on it ...

Revised:

<SCRIPT language="JavaScript">
<!--
/* Mailto enhancement */

function e_friend()
{
var e_add= 'you@youraddy.com';
var subj= 'your subject here';
if ((subj==" ") || (subj==null))
 subj="Hi!";
window.location="mailto:"+e_add+"?subject="+subj;}
//-->
</SCRIPT>

Use this as the link:
<A HREF="javascript:e_friend()">Email</A>
<a href="mailto:me@mydomain.com?subject=hello&body=what is this">Mail me</a>

£.
Or use the CDONTS object from ASP (that is IF you can use ASP)
Hey!

lambda's answer is the easiest, but please note, that this won't work with all browsers / mail clients.

- Tarraq
lease note that you won't be able to have a subject with spaces.
ASKER CERTIFIED SOLUTION
Avatar of fibdev
fibdev

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
There is a space before the message body ... try replacing this line:

window.location="mailto:"+e_add+"?subject="+subj+"&body= "+e_body;}


with this one ...

window.location="mailto:"+e_add+"?subject="+subj+"&body="+e_body;}


:)
You might wanna use the replace function to replace the body text etc with %20 (which is supposed to be a space)
CJ,

I tryed it like this ...

<SCRIPT language="JavaScript">
<!--
/* Mailto enhancement - Place this in the head of the document */

function e_friend()
{
var e_add= 'you@youraddy.com';
var subj= 'your subject here';
var e_body= 'message text goes here ...';
window.location="mailto:"+e_add+"?subject="+subj+"&body="+e_body;}
//-->
</SCRIPT>


It works good.  As of yesterday I'm using it on my site for people to unsubscribe to my mailing list.  It's funny, but this isn't the first thing I've coded becuase the idea was spawned here at the ee.  Many thanks to the Experts-Exchange.
quote:
This will produce the results you want.  Just reject it if you want to try another way, but the only way I think your going to have spaces in the message subject and body is to use some sort of scripting.

quote:
It works good.  As of yesterday I'm using it on my site for people to unsubscribe to my mailing list.  It's funny, but this isn't the first thing I've coded becuase the idea was spawned here at the ee.  Many thanks to the Experts-Exchange.

And you tested it with spaces and stuff too?????.......uhm......whichn of your comment is true?

uh ...

I don't know what your asking but you can go to my site and click the link to be removed from the mailing list at the bottom of the products page

http://fibdev.com/products.htm#produpmail

Just click where it says "Click here" in the blue box.
Just checked it, you're right.
waiting ...  :)
Avatar of winkle

ASKER

Thanks. Both methods worked very well. (spaces included)