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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can mailto code include subject and body? 1

Status
Not open for further replies.

cthaxter

Programmer
Aug 2, 2001
71
US
I am trying to compose a message by typing directly into a browser's address bar, or by using HTML code. Is that possible? I know that you can add the subject:
Code:
  mailto:someone@greatdomain.com?subject=How%20are%20you
but what would the syntax be to tag on the body?

Or, if anyone has a more roundabout solution, that would be appreciated as well.

I want someone to be able to click on a link that will take them directly to their default mail composer, such as Outlook; the whole message will be ready, and all they have to do is hit Send.

Thanks.

-Christopher
 
To say truth, I don't see much sence in this. But if you want it, here it is:

<html>
<title>Emails </title>
<head>
<script>

function createEmail() {

document.location.href = &quot;mailto:someone@somewhere.com?subject=&quot; + document.email.subject.value + &quot;&body=&quot; + document.email.messagebody.value;

}
</script>
</head>
<body>

<form name=email>
subject: <input type=text name=subject><br>
text:<br>
<textarea name=messagebody rows=10 cols=30></textarea>
<br><input type=button value=&quot;send email&quot; onclick=createEmail()>
</form>

</body>
</html>

Once you click &quot;send email&quot; button the default email client will launch and open new message window with data entered in form.
This script was tested in IE (that launch Outlook), Opera and N6 (that launch their own email clients).

BUT remember, you'll have a problem with line breaks in message body!
You need some script that will convert all line breaks that you make in textarea. Otherwise all text will be inserted as one line.
The example of such a script is here:

That example convert all carriage returns to <BR>, but it doesn't suit for you. You have to know the linebreak chars that email clients recognize (as for me - I don't know this).

Again, I don't see that this is very useful. I'd recommend to remove textarea, so the user will enter the message in new email client window. This is what it was developer for, right?

good luck
 
Would this be an easier way?
Now sure how it works in different browsers though.

<a href=&quot;mailto:name@domain.com?subject=Website%20Feedback&body=Dear%20sir,%20regarding%20your...&quot;>Email me</a>



É **new site coming soon**
 
the line break character for an email client is:

\n

replace carriage returns with this to place a line break in the body of an email...
 
crazyboybert, did you try it?
\n works fine in javascript, but it does not work in message body of email client.

This was the first thing I tried while writing this script.
Not \n nor \n\r works.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top