Search code examples
htmlmailto

\n doesn't work in the body value of a mailto: link


I'm trying setting up a mailto: link with a body bigger than one line.

I tried \n to start a new line but it shows up in mail body as characters and doesn't start a new line:

<a href="mailto:example@example.com?Subject=test&body=test \n test \n test \n"

Solution

  • Use %0D%0A in place of \n, due to url encoding. %0D is the url encoding for Carriage Return, %0A is the url encoding for Line Feed.

    Here's an answer that explains what each mean.

    In your example, it'll come out like this:

    <a href="mailto:example@example.com&subject=test&body=test%0D%0Atest%0D%0Atest%0D%0A">mail</a>
    

    Also note that subject should be all lowercase, otherwise you'll end up with Subject=test as the subject itself.