OK, this is the first tip I've done that's about HTML, so it may not suit all readers, but for those who do work with HTML, it may be a useful discovery. did you know you can both pre-load the body AND force a line break within that body of an email?
Most HTML (of CFML, JSP, ASP, PHP) developers already know that you can create a hyperlink that opens an email for the browser user, using:
<a href="mailto:someaddress@somedomain.com">create email</a>
And you may further know that you can add, in effect, query string values with keywords that pre-populate the email message with the CC, BCC, SUBJECT, and BODY values. So a more complete link might be:
<a href="mailto:someaddr@somedomain.com?cc=someotheraddr@somedomain.com">create email</a>
Note the use of a single ? character to separate the first keyword from the to address. To add multiple keywords, use &'s to separate any subsequent keywords:
<a href="mailto:someaddr@somedomain.com?cc=someotheraddr@somedomain.com&subject=some subject&body=some body text">create email</a>
(That would all be on one line. The split is being forced by my blog editor).
But a trick many may not know is that when forming the BODY values, you can cause the body text to have a new line within the text you pre-populate by using the ascii characters for a carriage return (%0D) and line feed (%0A), as in:
<a href="mailto:someaddress@somedomain.com?cc=someotheraddress@somedomain.com&subject=some subject&body=Some body text.%0D%0ASome new line.">create email</a>
This will create an email with a body showing:
Some body text.
Some new line.
Note that there have been reports that some browser/email client combinations don't honor that setting, so be sure to test it before relying on it for mission-critical email processing.
I'd just like to say thank you for the mailto: script lesson. Out of all
the sites I located online with information about line breaking in the body
of an email, ONLY your site and wisdom gave me the answer I was looking
for. Thanks again and bless your soul for showing others the way! Your
great!
Bill Daly
Thanks you, kindly, Bill. It's comments like that which help motivate folks
like me to share tips like this. :-) Glad to have helped.
Thanks so much for the useful tip. I was worried that I wouldnt be able to
find a solution for inserting line breaks in the HTML Email Link and this
is indeed the only site that gave this information :)
Swetha, glad I could help. As with Bill who had commented similarly when he
found the tip last year, I'm actually amazed that you guys are finding this
in your searching. Fortunately I must have used some words that relate to
what you folks are using when you search! :-)
Thank you for your good hint.
Viet, I'm afraid that all depends on the mail clients (both yours and those
of your intended recipient). You could of course put HTML
<b>bold</b> and <i>italics</i> tags around your
desired content, but that doesn't mean that it will show that way to users.
It may instead appear as <b>bold</b>, for
instance, just showing the tags to the user. The thing is, some mail
clients support using HTML, and some do not.
Great code for the line breaks. Works impeccably in versions of Outlook
bundled with Windows 2000. Am I the only one who took a minute to realize
those are zeros in %0D%0A and not o's?
Hi,
Thanks for clarifying that the %0d is a zero not the letter o. Sorry I
didn't think to clarify that. As for the person asking about using this
approach to add a signature inside the mail body, sure, no reason it
wouldn't work (for a text-based signature only, of course.) The signature
is just more text to be put inside the email, right?
Thanks. Very useful and clear help. Excellent. I have added a aid too.
:)
I found your hint when I was asked to create a sample e-mail for our
employees to send to their children's teachers. I was not only able to
preformat the body of the e-mail using your hint, but I discovered another
useful thing: You can place any text in the To: portion of the e-mail link.
For example, I used "mailto: enter teacher's e-mail address here," and
that's exactly what shows up when you click the link and it opens a new
e-mail message (Outlook in this case; may not work for all e-mail clients).
Kersi and Barbara, glad you found it useful, and nice bonus there, Barbara.
Thanks. :-)
Thanks for your very helpful tip. It saved me from much research.
I especilialy thank you for the "new line" hint, THANK YOU !
Guys, can anyone help with Bolding the text of the email body. Thanks.
NK, this has been discussed above in the comments. See the question from
"Viet" and my answer to him. I'm afraid that's all I can think of, and no
one has added more on it.
Thank you so much for this code. Very helpful and definitely saved me a lot
of work creating a form when I don't really need it.
when i use mailto: the cursor in the email remains at the top of the body
no matter what text or codes I use. How do you force the cursor to go to
the end of the line.
JB, you're simply expecting too much from a little ol' hyperlink. This
isn't a desktop application you're building, with the power of precise
cursor control. Indeed, even in a web page, using tools like javascript,
you couldn't put the cursor at the end of a line, but only at the beginning
of an input field (by setting its focus, as far as I know).
Interesting idea, interesting post.
A bit of adverticement: <a href= " http://plavix.phpbbx.de "> plavix
</a>, <a href= " http://cephalexin.phpbbx.de "> cephalexin
</a>
Your CfLf tip is great. I tried using it in a body statement that also
includes variables concatenated with an ampersand, as in ASP 3.0? The final
statement threw an error suggesting that the ampersand modifies the
resulting string and causes errors. Is there a reliable method to handle
this?
Thanks, Richard, but as for your question, I'm not sure I understand. You
want to append vars to the URL in the mailto? For what purpose? To fill in
the body with ASP variables? In that case, you're confusing things I think.
You could put variable data on your server-side page in what gets placed in
that BODY attribute of the mailto URL. But if you add any more ampersands
on the mailto URL, the browser's going to think it's part of the mailto,
and the only things the browsers seem to recognize is subject, body, and
cc.
Thanks Charlie. I was floundering around with this, using 'content', and
various tricks to try to get the link to work properly. All good now :).
One thing though: I have to insert %20 wherever there should be a word
space, or MSOE cuts the string there.
This is really helpful. I am trying to go one stage further by adding a
link within the body portion - i.e. <a
href='http://www.wyehead.co.uk>CLICK HERE</a>. I have tried
converting angle brackets and = into hex but to no avail - i.e. %3Ca
href%3D'http://www.wyehead.co.uk'%3ECLICK HERE%3C%5Ca%3E" - any ideas would
be gratefully received as am really scratching my head here
Thanks for this posting Charlie. I have a similar problem and I tried using
your suggestion, but it did not work. I'm hoping you can help. :)
Alib, about your challenge of the ascii chars for < and > not
working, what are you really saying? Because they do work for me. The
hyperlink code you offer shows up in the body of my email if I place it in
the BODY attribute on the mailto line.
Mike, you're barking up the entirely wrong tree on this one. My entry is
about the HTML A HREF tag and using it to cause a link to open an email.
You, instead, are talking about creating an email from within a PHP
program. Entirely unrelated.
Hi Charlie - thank you so much for your help. You were right - I wanted it
to show up as a link in the mail rather than the html for the link being
visible. I did suspect I was flogging a dead horse on this one it was just
that my client particularly to do it this way. I will come up with another
plan.
Thanks you very much for your post. Its really helped and its a unique
post.
I am looking to do the same pre population of the body in an email but in a
hyperlink on a word document as a way to generate a reponse form as a mode
of communication between my end users and my company. I am able to
pre-populate the body but I am limited in the number of characters I can
have in the body.
This is exactly what I was looking for. I searched many places looking for
this information and was unable find it anywhere else but here. Thank you
so much!
Thank you for this, I am have been looking for years (evidently not with
sufficient diligence!)