Insert a line break in mailto body

180,792

Solution 1

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?

Solution 2

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

Solution 3

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

Solution 4

<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

Solution 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>
Share:
180,792

Related videos on Youtube

Marion
Author by

Marion

Updated on September 04, 2020

Comments

  • Marion
    Marion over 3 years

    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>
    
    • John
      John about 10 years
    • jdmdevdotnet
      jdmdevdotnet almost 7 years
      @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.
    • Admin
      Admin almost 7 years
      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.
    • csiu
      csiu over 3 years
      Does this answer your question? mailto link multiple body lines
  • Marion
    Marion about 10 years
    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
  • Jem
    Jem about 10 years
    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.
  • Marion
    Marion about 10 years
    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
  • Mark Rhodes
    Mark Rhodes about 8 years
    Note that if your constructing a mailto link using JavaScript, then you can use escape('\r\n') to get %0D%0A.
  • Adam Simpson
    Adam Simpson about 8 years
    Additional note: If you're constructing the link with ES6/ES2015 string templates the raw code (%0D%0A) works just fine.
  • João Pimentel Ferreira
    João Pimentel Ferreira almost 7 years
    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");
  • Lars Juel Jensen
    Lars Juel Jensen about 5 years
    @MarkRhodes: Since mailto is a URI you can also use encodeURI(myMailToURIString), which will then escape all the characters needed in your mail body :-)
  • AquilaIrreale
    AquilaIrreale over 4 years
    @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
  • Pavel Bariev
    Pavel Bariev over 3 years
    What is for a tripple break, please?
  • Sergi
    Sergi over 3 years
    You are adding "<br>" inside a string and it shows as "<br>" in the mail body.
  • atereshkov
    atereshkov over 3 years
    @PavelBariev %0D0A%0D0A%0D0A
  • Keyslinger
    Keyslinger about 3 years
    This resulted in colons for me. I ended up using %0A%0A
  • Frederik
    Frederik almost 3 years
    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.
  • Moebius
    Moebius about 2 years
    I love you!!!!!