0

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"
bcye
  • 758
  • 5
  • 22

2 Answers2

1

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.

IeuanG
  • 504
  • 5
  • 13
  • Whats the difference between this and the above mentioned %0A – bcye Feb 24 '18 at 14:57
  • Windows tends to use CRLF `(%0D%0A)`, whereas older macs and linux computers will use either CR `(%0D)` or LF `(%0A)`. It shouldn't make a huge amount of difference, but I've always used CRLF to be on the safe side. – IeuanG Feb 24 '18 at 14:59
1

You should use URL encoding, therefore the solution is %0A. In your example:

<a href="mailto:example@example.com?Subject=test&body=test%0Atest%0Atest%0A"
Web R
  • 565
  • 1
  • 6
  • 23