[html] Can I set subject/content of email using mailto:?

Is it possible to set the subject/content of email when I use mailto:?

This question is related to html email mailto

The answer is


If you want to add html content to your email, url encode your html code for the message body and include it in your mailto link code, but trouble is you can't set the type of the email from this link from plaintext to html, the client using the link needs their mail client to send html emails by default. In case you want to test here is the code for a simple mailto link, with an image wrapped in a link (angular style urls added for visibility):

<a href="mailto:?body=%3Ca%20href%3D%22{{ scope.url }}%22%3E%3Cimg%20src%3D%22{{ scope.url }}%22%20width%3D%22300%22%20%2F%3E%3C%2Fa%3E">

The html tags are url encoded.


Note that it is not possible to use HTML in the message body, according to RFC 2368:

The special hname "body" indicates that the associated hvalue is the body of the message. The "body" hname should contain the content for the first text/plain body part of the message. The mailto URL is primarily intended for generation of short text messages that are actually the content of automatic processing (such as "subscribe" messages for mailing lists), not general MIME bodies.

Credit: https://stackoverflow.com/a/13415988/1835519


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

enter image description here


Yes, you can like this:

mailto: [email protected]?subject=something

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>

How to add subject to mailto tag


I split it into separate lines to make it a little more readable.

<a href="

    mailto:[email protected]

    ?subject=My+great+email+to+you

    &body=This+is+an+awesome+email

    &[email protected]

    &[email protected]

">Click here to send email!</a>

Here's a runnable snippet to help you generate mailto: links with optional subject and body.

_x000D_
_x000D_
function generate() {_x000D_
  var email = $('#email').val();_x000D_
  var subject = $('#subject').val();_x000D_
  var body = $('#body').val();_x000D_
_x000D_
  var mailto = 'mailto:' + email;_x000D_
  var params = {};_x000D_
  if (subject) {_x000D_
    params.subject = subject;_x000D_
  }_x000D_
  if (body) {_x000D_
    params.body = body;_x000D_
  }_x000D_
  if (params) {_x000D_
    mailto += '?' + $.param(params);_x000D_
  }_x000D_
_x000D_
  var $output = $('#output');_x000D_
  $output.val(mailto);_x000D_
  $output.focus();_x000D_
  $output.select();_x000D_
  document.execCommand('copy');_x000D_
}_x000D_
_x000D_
$(document).ready(function() {_x000D_
  $('#generate').on('click', generate);_x000D_
});
_x000D_
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>_x000D_
<input type="text" id="email" placeholder="email address" /><br/>_x000D_
<input type="text" id="subject" placeholder="Subject" /><br/>_x000D_
<textarea id="body" placeholder="Body"></textarea><br/>_x000D_
<button type="button" id="generate">Generate & copy to clipboard</button><br/>_x000D_
<textarea id="output">Output</textarea>
_x000D_
_x000D_
_x000D_


here is the trick http://neworganizing.com/content/blog/tip-prepopulate-mailto-links-with-subject-body-text

<a href="mailto:[email protected]?subject=Your+tip+on+mailto+links&body=Thanks+for+this+tip">tell a friend</a>

mailto:[email protected]?subject=Your+subject

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&amp;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>";
?>

<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


Yes:

Use this to experiment with mailto form elements and link encoding.

You can enter subject, body (i.e. content), etc. into the form, hit the button and see the mailto html link that you can paste into your page.

You can even specify elements that are rarely known and used: cc, bcc, from emails.


Examples related to html

Embed ruby within URL : Middleman Blog Please help me convert this script to a simple image slider Generating a list of pages (not posts) without the index file Why there is this "clear" class before footer? Is it possible to change the content HTML5 alert messages? Getting all files in directory with ajax DevTools failed to load SourceMap: Could not load content for chrome-extension How to set width of mat-table column in angular? How to open a link in new tab using angular? ERROR Error: Uncaught (in promise), Cannot match any routes. URL Segment

Examples related to email

Monitoring the Full Disclosure mailinglist require(vendor/autoload.php): failed to open stream Failed to authenticate on SMTP server error using gmail Expected response code 220 but got code "", with message "" in Laravel How to to send mail using gmail in Laravel? Laravel Mail::send() sending to multiple to or bcc addresses Getting "The remote certificate is invalid according to the validation procedure" when SMTP server has a valid certificate How to validate an e-mail address in swift? PHP mail function doesn't complete sending of e-mail How to validate email id in angularJs using ng-pattern

Examples related to mailto

Insert a line break in mailto body Automatically open default email client and pre-populate content Mailto on submit button Mailto: Body formatting mailto link multiple body lines mailto using javascript mailto link with HTML body Can I set subject/content of email using mailto:? Is it possible to add an HTML link in the body of a MAILTO link