Insert a line break in mailto body

后端 未结 6 1505
甜味超标
甜味超标 2020-11-29 00:21

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

相关标签:
6条回答
  • 2020-11-29 00:26

    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?

    0 讨论(0)
  • 2020-11-29 00:26

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

    0 讨论(0)
  • 2020-11-29 00:27
    <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
    
    0 讨论(0)
  • 2020-11-29 00:34

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

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

    0 讨论(0)
  • 2020-11-29 00:39

    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>
    
    0 讨论(0)
  • 2020-11-29 00:42

    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
    
    0 讨论(0)
提交回复
热议问题