Can I set subject/content of email using mailto:?
Solution 1
Yes, look all tips and tricks with mailto: http://www.angelfire.com/dc/html-webmaster/mailto.htm
mailto subject example:
<a href="mailto:[email protected]?subject=free chocolate">example</a>
mailto with content:
<a href="mailto:[email protected]?subject=look at this website&body=Hi,I found this website and thought you might like it http://www.geocities.com/wowhtml/">tell a friend</a>
As alluded to in the comments, both subject
and body
must be escaped properly. Use encodeURIComponent(subject)
on each, rather than hand-coding for specific cases.
As Hoody mentioned in the comments, you can add line breaks by adding the following encoded sequence in the string:
%0D%0A // one line break
Solution 2
<a href="mailto:[email protected]?subject=Feedback for
webdevelopersnotes.com&body=The Tips and Tricks section is great
&[email protected]
&[email protected]">Send me an email</a>
you can use this code to set subject, body, cc, bcc
Solution 3
I created an open-source tool for making this easy. Enter the strings you want and you'll instantly get the mailto
:
mailto.now.sh
💌⚡️ Template full emails in a mailto
Solution 4
The mailto:
URL scheme is defined in RFC 2368. Also, the convention for encoding information into URLs and URIs is defined in RFC 1738 and then RFC 3986. These prescribe how to include the body
and subject
headers into a URL (URI):
mailto:[email protected]?subject=current-issue&body=send%20current-issue
Specifically, you must percent-encode the email address, subject, and body and put them into the format above. Percent-encoded text is legal for use in HTML, however this URL must be entity encoded for use in an href
attribute, according to the HTML4 standard:
<a href="mailto:[email protected]?subject=current-issue&body=send%20current-issue">Send email</a>
And most generally, here is a simple PHP script that encodes per the above.
<?php
$encodedTo = rawurlencode($message->to);
$encodedSubject = rawurlencode($message->subject);
$encodedBody = rawurlencode($message->body);
$uri = "mailto:$encodedTo?subject=$encodedSubject&body=$encodedBody";
$encodedUri = htmlspecialchars($uri);
echo "<a href=\"$encodedUri\">Send email</a>";
?>
Solution 5
You can add subject added to the mailto command using either one of the following ways. Add ?subject out mailto to the mailto tag.
<a href="mailto:[email protected]?subject=testing out mailto">First Example</a>
We can also add text into the body of the message by adding &body to the end of the tag as shown in the below example.
<a href="mailto:[email protected]?subject=testing out mailto&body=Just testing">Second Example</a>
In addition to body, a user may also type &cc or &bcc to fill out the CC and BCC fields.
<a href="mailto:[email protected]?subject=testing out mailto&body=Just testing&[email protected]&[email protected]">Third
Example</a>
Jiew Meng
Web Developer & Computer Science Student Tools of Trade: PHP, Symfony MVC, Doctrine ORM, HTML, CSS, jQuery/JS Looking at Python/Google App Engine, C#/WPF/Entity Framework I hope to develop usable web applications like Wunderlist, SpringPad in the future
Updated on May 11, 2020Comments
-
Jiew Meng almost 4 years
Is it possible to set the subject/content of email when I use mailto:?
-
Adrien Be almost 9 years
-
Dawson B over 6 yearsYou can set each and every part of an email. Here's a tool I built to make it dead simple: mailto.now.sh
-
-
Jiew Meng about 13 yearsis it possible to use HTML for the body?
-
tripleee almost 11 yearsThat is entirely client specific. In the general case, no.
-
jocull over 10 yearsYou may be able to add HTML into the body if you URL encode the entire string. You'd need to test and make sure it works well in a majority of email clients.
-
Oscar Pérez over 10 yearsJust as a reference: you don't have to htmlescape the subject
-
Simon East about 10 yearsDoes anyone know a reference that outlines the mail client support for this?
-
gordie about 9 yearsNote that W3C requires that you encode your string following those rules : Characters should be represented in NFC and spaces should be escaped as %20.
-
Armfoot over 8 yearsAlso a very useful feature of this href field composer is the ability to encode all characters to hexadecimal (e.g.:
[Test Zõne]
becomes%5BTest%20Z%C3%B5ne%5D
, this may avoid some spam bots). -
Armfoot over 8 yearsI mean, if you choose to encode all characters, they are all converted to HTML notation
&#x
(avoiding some spam bots). -
varun aaruru about 8 yearsthis question was answered 5 years ago
-
quemeful about 8 yearsand it still is used today when you wanna mail something
-
dakab almost 8 yearsThat angelfire.com link is unavailable. Can you find a replacement for it? If not, it may be removed from the answer. What information were there?
-
Haim Evgi almost 8 yearsi can acsess the link, what you see
-
David almost 8 yearsMy
subject
is not text. It is a table. How to add that. -
Quentin over 7 yearsThe question is asking how to set the subject and content. It didn't mention formatting. While that is a useful thing to note on an answer, you left out the bit about what is possible and how to achieve it. Without that, this is a comment, not an answer.
-
Capsule over 7 yearsYou know this angelfire link is probably 15 years old, right?
-
nafg over 7 yearsI don't think the space should be there?
-
Namkce over 6 yearsis there still a 256 char limit to the mailto string?
-
superphonic over 6 years+one for the retro Angelfire and Geocities links that gave me a huge rush of nostalgia
-
William Entriken about 6 yearsHere is a much deeper example for if your email has a URL in it and that URL has stuff that needs to be encoded: stackoverflow.com/questions/4744888/…
-
Ciro Santilli OurBigBook.com about 6 years@tripleee what about the RFC mentioned at: stackoverflow.com/a/41365892/895245
-
tripleee about 6 years@CiroSantilli Indeed, five years later, client support is considerably more widespread, but still not entirely reliable in my experience.
-
Bram Vanroy over 5 yearsThis link is dead.
-
Sam Carlton over 5 yearsHere's a tool that does it all for you(Subject, Body, URL Encoding, Line Breaks) email-link-builder.netlify.com
-
bytor99999 over 5 yearsJure I really appreciate you putting this as an answer to this question as that is EXACTLY what I needed to find out and was asking myself. So while Quentin thinks this doesn't answer the OP question, it answers mine that I was searching for that brought up this post. Thank you so much Jure!
-
bytor99999 over 5 yearsCan you also post an example where the body <a href> just has the href and a text between it and the end tag? Thanks
-
sed over 5 years<a href="<same as above>">This is the link text</a> @user1567291
-
SuperUberDuper almost 5 yearsis the + needed instead of spaces? works fine without on gmail
-
Ε Г И І И О over 4 yearsThis doesn't work. The email client will just show all the html tags as text instead of processing it as a rich text document.
-
Hassan Raza about 4 yearsthis should be without space.
-
Macumbaomuerte over 3 years@David You cannot put a table on a subject, do you know how email subjects work? Subjects are plain-text strings. The maximum out of the basic stuff you can put on a subject is emojis
-
Peter Johnson over 3 yearsLink is dead now
-
Vikas Lalwani over 3 yearslink doesn't work, try qawithexperts.com/article/html/… To get of using details of mailto in anchor tag