262

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@mycompany.com?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>
Limon Monte
  • 52,539
  • 45
  • 182
  • 213
Marion
  • 2,623
  • 2
  • 12
  • 4
  • 4
    possible duplicate: http://stackoverflow.com/questions/15019689/html-insert-line-break-in-email-subject-like-20-is-a-space – John Mar 31 '14 at 16:14
  • 1
    @John 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. – jdmdevdotnet Jun 02 '17 at 14:32
  • 1
    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. –  Jun 02 '17 at 15:54
  • Does this answer your question? [mailto link multiple body lines](https://stackoverflow.com/questions/10356329/mailto-link-multiple-body-lines) – jtbandes Sep 07 '20 at 19:32

6 Answers6

364

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@mycompany.com?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?

Jem
  • 4,313
  • 2
  • 18
  • 20
  • 2
    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 code – Marion Apr 01 '14 at 06:25
  • 1
    Oh, if you're using a seperate solution, have you tried the HTML tag "
    "? That sometimes works when I'm using 3rd party applications.
    – Jem Apr 01 '14 at 12:05
  • 3
    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 help – Marion Apr 03 '14 at 15:33
  • 7
    if you'd like to convert every `
    `, `
    ` or `
    ` to `%0D%0A` you can do `var emailBody = htmlBody.replace(/
    /mg,"%0D%0A");`
    – João Pimentel Ferreira May 29 '17 at 20:54
  • 1
    This resulted in colons for me. I ended up using %0A%0A – Keyslinger Feb 25 '21 at 19:20
  • does not work, the only way it worked for me is %0D%0A – Mostafa Jul 03 '22 at 08:43
185

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..

Community
  • 1
  • 1
davidcondrey
  • 34,416
  • 17
  • 114
  • 136
  • 14
    Note that if your constructing a mailto link using JavaScript, then you can use `escape('\r\n')` to get `%0D%0A`. – Mark Rhodes Apr 05 '16 at 20:59
  • 9
    Additional note: If you're constructing the link with ES6/ES2015 string templates the raw code (`%0D%0A`) works just fine. – Adam Simpson Apr 18 '16 at 16:00
  • 2
    @MarkRhodes: Since mailto is a URI you can also use encodeURI(myMailToURIString), which will then escape all the characters needed in your mail body :-) – Lars Juel Jensen Apr 09 '19 at 18:06
14
<a href="mailto:example@gmail.com?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
sɐunıɔןɐqɐp
  • 3,332
  • 15
  • 36
  • 40
Flemin Louis
  • 171
  • 1
  • 6
10

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:me@house.country?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
alexandre1985
  • 1,056
  • 3
  • 13
  • 31
  • 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 accordingly – AquilaIrreale Oct 03 '19 at 08:42
5

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

<a href="mailto:anything@any.com?subject=This%20is%20Subject&body=First line<br>Second line">
   click here to mail me
</a>
Buddy Christ
  • 1,364
  • 8
  • 22
  • You are adding "
    " inside a string and it shows as "
    " in the mail body.
    – Sergi Nov 09 '20 at 18:18
  • 1
    This seems to be no longer correct with the lastest GMail app on Android 10 – `
    ` will be printed as "
    " instead of a line break.
    – Frederik May 17 '21 at 10:44
-2

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

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

David Buck
  • 3,752
  • 35
  • 31
  • 35
Pooja
  • 9