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