Insert a line break in mailto body
Asked Answered
T

7

274

I would like to insert a line break into my mailto body. I tried %0A, %0D and %0D%0A. Nothing worked for me. I tested on Gmail, Yahoo, Apple Mail, Outlook 2010, Outlook.com and Thunderbird with Google Chrome on Mac OSX.

Any help please ?

Here's my code :

<a href="mailto:[email protected]?subject=Subscribe&body=Lastame%20%3A%0D%0A%20Firstname%20%3A"><img alt="Subscribe" class="center" height="50" src="subscribe.png" style="width: 137px; height: 50px; color: #4da6f7; font-size: 20px; display: block;" width="137"></a>
Ternary answered 31/3, 2014 at 15:33 Comment(4)
possible duplicate: #15020189Laurin
@Laurin How is that a duplicate? That is a very specific question about %20 being used to enter new line, not how to make a new line like this question.Unrealizable
Looks like a dupe to me. That question asks "how do i insert a line break like i do a space". It isn't asking how to use %20 as a newline. The only substantial difference I see is this is asking about the body, whereas that question asks about the subject. Its the same answer in either case, though.Bonnice
Does this answer your question? mailto link multiple body linesSwampy
L
379

I would suggest you try the html tag <br>, in case your marketing application will recognize it.

I use %0D%0A. This should work as long as the email is HTML formatted.

<a href="mailto:[email protected]?subject=Subscribe&body=Lastame%20%3A%0D%0AFirstname%20%3A"><img alt="Subscribe" class="center" height="50" src="subscribe.png" style="width: 137px; height: 50px; color: #4da6f7; font-size: 20px; display: block;" width="137"></a>

You will likely want to take out the %20 before Firstname, otherwise you will have a space as the first character on the next line.

A note, when I tested this with your code, it worked (along with some extra spacing). Are you using a mail client that doesn't allow HTML formatting?

Lame answered 31/3, 2014 at 15:35 Comment(6)
I already tried %0D%0A, and it's not working for me. I use a email marketing solution to send my newsletter. I suppose it's re-writing my codeTernary
Oh, if you're using a seperate solution, have you tried the HTML tag "<br>"? That sometimes works when I'm using 3rd party applications.Lame
I did some test with an other platform, my code is working perfectly! it's definitly coming from the solution I use. All those hours lost for nothing... sorry guys, and again thank you for your helpTernary
if you'd like to convert every <br>, <br/> or <br /> to %0D%0A you can do var emailBody = htmlBody.replace(/<br\s*\/?>/mg,"%0D%0A");Secretive
This resulted in colons for me. I ended up using %0A%0AHieratic
<br> does not work, the only way it worked for me is %0D%0APryce
P
193

As per RFC2368 which defines mailto:, further reinforced by an example in RFC1738, it is explicitly stated that the only valid way to generate a line break is with %0D%0A.

This also applies to all url schemes such as gopher, smtp, sdp, imap, ldap, etc..

Packston answered 2/9, 2014 at 23:39 Comment(3)
Note that if your constructing a mailto link using JavaScript, then you can use escape('\r\n') to get %0D%0A.Ladonnalady
Additional note: If you're constructing the link with ES6/ES2015 string templates the raw code (%0D%0A) works just fine.Til
@MarkRhodes: Since mailto is a URI you can also use encodeURI(myMailToURIString), which will then escape all the characters needed in your mail body :-)Bipetalous
R
15
<a href="mailto:[email protected]?subject=Request&body=Hi,%0DName:[your name] %0DGood day " target="_blank"></a>

Try adding %0D to break the line. This will definitely work.

Above code will display the following:

Hi,
Name:[your name] 
Good day
Rhatany answered 4/9, 2020 at 7:29 Comment(0)
T
12

For plaintext email using JavaScript, you may also use \r with encodeURIComponent().

For example, this message:

hello\rthis answer is now well formated\rand it contains good knowleadge\rthat is why I am up voting

URI Encoded, results in:

hello%0Dthis%20answer%20is%20now%20well%20formated%0Dand%20it%20contains%20good%20knowleadge%0Dthat%20is%20why%20I%20am%20up%20voting

And, using the href:

mailto:[email protected]?body=hello%0Dthis%20answer%20is%20now%20well%20formated%0Dand%20it%20contains%20good%20knowleadge%0Dthat%20is%20why%20I%20am%20up%20voting

Will result in the following email body text:

hello
this answer is now well formated
and it contains good knowleadge
that is why I am up voting
Tribune answered 24/4, 2017 at 10:38 Comment(1)
@littlecoder Because it is a poor answer: poorly formatted, poorly worded and it omits essential context. It is just as likely to confuse people that land on this page as it is to help them. It is not useful by this site's standards, and so it has been voted accordinglyVeliz
S
5

Curiously in gmail for android %0D%0A doesn't work and <br> works:

<a href="mailto:[email protected]?subject=This%20is%20Subject&body=First line<br>Second line">
   click here to mail me
</a>
Sokoto answered 13/4, 2020 at 12:11 Comment(2)
You are adding "<br>" inside a string and it shows as "<br>" in the mail body.Gnarly
This seems to be no longer correct with the lastest GMail app on Android 10 – <br> will be printed as "<br>" instead of a line break.Exotoxin
C
0

you can do either return \r or new line \n

Cubbyhole answered 25/11, 2023 at 1:33 Comment(0)
R
-2

For the Single line and double line break here are the following codes.

Single break: %0D0A
Double break: %0D0A%0D0A

Retiary answered 10/8, 2020 at 7:6 Comment(2)
What is for a tripple break, please?Id
@PavelBariev %0D0A%0D0A%0D0AConnection

© 2022 - 2025 — McMap. All rights reserved.