Mailto: Body formatting

118,092

Solution 1

Use %0D%0A for a line break in your body

Example (Demo):

<a href="mailto:[email protected]?subject=Suggestions&body=name:%0D%0Aemail:">test</a>​
                                                                  ^^^^^^

Solution 2

From the first result on Google:

mailto:[email protected]_t?subject=Header&body=This%20is...%20the%20first%20line%0D%0AThis%20is%20the%20second

Solution 3

Forget it; this might work with Outlook or maybe even GMail but you won't be able to get this working properly supporting most other E-mail clients out there (and there's a shitton of 'em).

You're better of using a simple PHP script (check out PHPMailer) or use a hosted solution (Google "email form hosted", "free email form hosting" or something similar)

By the way, you are looking for the term "Percent-encoding" (also called url-encoding and Javascript uses encodeUri/encodeUriComponent (make sure you understand the differences!)). You will need to encode a whole lot more than just newlines.

Share:
118,092
TheLegend
Author by

TheLegend

#SOreadytohelp. I am a Software Developer here in Cape Town, South Africa. I mostly work on web apps, mostly in Ruby and Rails. I started back in Nov 2011. I work for a company called Peach Payments as their head of engineering. Above all else, I love simple easy to read code. I am a student of the software development process. I find the glue that holds domains together as interesting as the domains themselves.

Updated on July 15, 2022

Comments

  • TheLegend
    TheLegend almost 2 years

    Possible Duplicate:
    mailto link multiple body lines

    Just a quick question. I am creating a website for a charity and they have a section on the site where people can give some suggestions for how they could raise more money for their cause. Their site is just plain HTML, JS and CSS to keep it light-weight. I added a mailto: that will allow people to send them an e-mail, but they would like some more information like their name and their contact details. I want to know if there is a way to format the body so that there are new lines:

    name: 
    email:
    tel:
    postal address:
    

    thank you!

    Here is what my mailto looks like now. any help or suggestions are welcome:

    <a href="mailto:[email protected]?subject=Suggestions&body=Your%20suggestions%20are%20really%20important%20to%20us%20,thanks!">Send suggestions!</a>
    
  • TheLegend
    TheLegend almost 12 years
    thanks man that's perfect. i couldn't find anything on-line that was explicit! you rock my socks
  • TheLegend
    TheLegend almost 12 years
    yeah i know where you are coming from, i am a ruby developer, and i was considering dropping the whole site into a rails app and running it through action mailer and have a few forms. but this client wanted it strictly html and css. so mailto: was the simplest. pulled a few strings and its working just fine. thanks for the advise though
  • John
    John over 10 years
    Curt's solution also works in Thunderbird, so that should cover the major players.
  • Aleksandar
    Aleksandar over 4 years
    %20 is url encoded character for space. That is not url encoded character for new line.
  • Madara's Ghost
    Madara's Ghost over 4 years
    @Aleksandar Yes. Have you read the answer carefully?