Link to home
Start Free TrialLog in
Avatar of dj88
dj88Flag for United States of America

asked on

embedding a hyperlink inside a mailto reference

Is it possible to include a hyperlink inside the body reference of a mailto call in html?

For example, using the following example:
<a href="mailto:test@somewhere?body=Test body">email with default body</a>

Is it possible to change the "Test Body" reference to be a link to www.google.com?

Thanks
Avatar of hielo
hielo
Flag of Wallis and Futuna image

You need to encode the value:
email with default body
this will help you encode your data:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
 "http://www.w3.org/TR/html4/loose.dtd"> 
<html>
<head>
<title></title>
</head>
<body>
<form>
	<div>Type Raw value then click in "Encoded Value"</div>
	<div>"Raw" Value: <textarea name="raw" onchange="encoded.value=encodeURIComponent(this.value)" rows="10" cols="80" ></textarea></div>
	<div>Encoded Value: <textarea name="encoded" rows="10" cols="80"></textarea></div>
</form>
</body>
</html>

Open in new window

Avatar of ncoo
ncoo


As HTML
 
<a href="mailto:test@somewhere?body=Test body&lt;a href='http://google.com'&gt;google&lt;/a&gt;">email with default body</a>
 
AS TEXT
<a href="mailto:test@somewhere?body=Test body http://google.com">email with default body</a>

Open in new window

Sorry you wanted Test Body replaced, here you go:
As HTML
 
<a href="mailto:test@somewhere?body=&lt;a href='http://google.com'&gt;google&lt;/a&gt;">email with default body</a>
 
AS TEXT
<a href="mailto:test@somewhere?body=http://google.com">email with default body</a>

Open in new window

Avatar of dj88

ASKER

Thanks for the responses...

In both cases, I get the following results in the body of the email.  Is there anyway to actually just put the hyperlink in the body rather than the HTML?

<a href="http://www.google.com">google</a>

Am I doing something wrong?
I didn't realize my original post got mangled! Take my second post, save it as encoder.html

then in the top text area type the body of whatever you want on the body. Then click on the lower text area and copy the result from the lower textarea and put that as the value of the "body". So if you were to type
http://www.google.com/
 
the result will be:
<a href="mailto:test@somewhere?body=http%3A%2F%2Fwww.google.com%2F">email with default body</a>
 
which is what you need.

Open in new window

>>the result will be:
I meant:
 ... the result will be http%3A%2F%2Fwww.google.com%2F

so on your original post:
<a href="mailto:test@somewhere?body=Test body">email with default body</a>

you need to assign that result to body:
<a href="mailto:test@somewhere?body=http%3A%2F%2Fwww.google.com%2F">email with default body</a>
Avatar of dj88

ASKER

That's a little closer - However, I want it the body of the email to say:

Google (or whatever)

but link to http://www.google.com

So, is it possible to edit the name of the link so to speak?
Then in the top text area you need to type:
<a href="http://www.google.com/">Google</a>
 
and the result that you get in the lower textarea you assign it to "body"

Open in new window


<a href="mailto:test@somewhere?body=%3Ca%20href%3D%22http%3A%2F%2Fwww.google.com%2F%22%3EGoogle%3C%2Fa%3E">email with default body</a>

Open in new window

Avatar of dj88

ASKER

Maybe I'm doing something wrong - but that give me the following in the body of the email:

<a href="http://www.google.com/">Google</a>
ASKER CERTIFIED SOLUTION
Avatar of hielo
hielo
Flag of Wallis and Futuna image

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
All credit to Hielo for this but I noticed this Q and was following it.  His last post is correct that you will be at the mercy of the email client (i.e. the user's email software).  I don't know any that would reliably interpret the code as you want.  Hielo did provide the way to send it to the mailer if it would work but most will just treat what is in "body" as a text email.  All credit to Hielo for that and I just wanted to confirm.
I really suggest you consider using server side script instead for handling mailing.  Mailto is a poor option in my opinion for MANY reasons.  In this case a server script could make the email just as you want and you would get your result.  You would also have the benefit of a method that doesn't rely on the client's email program, doesn't expose your email address to bots/spiders, and is more professional.  Almost all server side languages have an easy way to send emails so making a script to do this (or finding one online) is easy and basic.  The only requirement is a server side language/techonology and some mail "object" or class.
If you have a question about what I have said let me know.  Please keep in mind the last part is a little beyond what you asked here, which Hielo seems to have answered. :)
bol
Avatar of dj88

ASKER

I appreciate all the comments and suggestions...
Avatar of dj88

ASKER

Thanks for the help...