Question
Is it possible to set the subject and message content of an email when using a mailto: link? If so, what is the correct syntax for pre-filling fields such as the subject and body?
Short Answer
By the end of this page, you will understand how mailto: links work, how to prefill email fields like subject and body, what the correct URL syntax looks like, and what limitations to expect across email clients and browsers.
Concept
The mailto: scheme is a special type of URL that opens the user's default email application instead of navigating to a web page. It can do more than just specify the recipient address. You can also attach query parameters to prefill parts of the email, such as:
subjectbodyccbcc
A basic mailto: link looks like this:
mailto:user@example.com
A more complete one looks like this:
mailto:user@example.com?subject=Hello&body=How%20are%20you%3F
This matters because it gives users a quick way to contact someone from a website or app while reducing the amount of typing they need to do.
However, mailto: does not send the email by itself. It only opens the user's email client with some fields pre-filled. The user still needs to review and send the message manually.
It is also important to URL-encode special characters such as spaces, line breaks, &, and ?, because mailto: uses URL syntax.
Mental Model
Think of a mailto: link like a pre-filled paper form.
- The email address is the person you want to send it to.
- The
subjectis the title already written on the form. - The
bodyis the message text already filled in. - Clicking the link hands that form to the user's email app.
But the app does not mail it automatically. The user still has to press Send.
Syntax and Examples
The general syntax is:
mailto:recipient@example.com?subject=Your%20Subject&body=Your%20message
Example: subject only
<a href="mailto:support@example.com?subject=Help%20needed">Email support</a>
This opens the user's email app with:
- To:
support@example.com - Subject:
Help needed
Example: subject and body
<a href="mailto:support@example.com?subject=Bug%20Report&body=I%20found%20a%20problem%20on%20your%20site.">Report a bug</a>
This prefills both the subject and the message body.
Example: body with line breaks
<a href="mailto:jobs@example.com?subject=Job%20Application&body=Hello%2C%0A%0AI%20would%20like%20to%20apply%20for%20the%20role.%0A%0ARegards">Apply by email</a>
Here:
Step by Step Execution
Consider this example:
<a href="mailto:hello@example.com?subject=Meeting%20Request&body=Hello%2C%0ACan%20we%20meet%20tomorrow%3F">Send email</a>
Step by step:
- The browser sees a link starting with
mailto:. - Instead of opening a normal web page, it asks the operating system to open the default email client.
hello@example.comis placed into the To field.- The query string begins after
?. subject=Meeting%20Requestsets the email subject toMeeting Request.&body=...adds the body text.- Encoded characters are decoded:
%20becomes a space%0Abecomes a line break%3Fbecomes?
- The email draft opens, and the user can edit or send it.
The final draft looks roughly like this:
- To:
hello@example.com
Real World Use Cases
mailto: links are commonly used in small and medium-sized web projects where opening the user's email app is enough.
Common use cases
- Contact links on personal websites or company pages
- Support requests with a prefilled subject like
Support Request - Bug reporting with a template in the body
- Job applications with a predefined subject line
- Feedback forms that redirect to email instead of storing data in a database
Example scenarios
Customer support
<a href="mailto:support@example.com?subject=Support%20Request">Contact support</a>
Bug report template
<a href="mailto:bugs@example.com?subject=Bug%20Report&body=Page%3A%20%0ASteps%20to%20reproduce%3A%20%0AExpected%20result%3A%20%0AActual%20result%3A%20">Report a bug</a>
Feedback button
<a href="mailto:feedback@example.com?subject=Website%20Feedback">Send feedback
Real Codebase Usage
In real projects, developers usually use mailto: in simple cases where a full backend email system is unnecessary.
Common patterns
1. Prefilled support links
Developers create links with a standard subject so support emails are easier to sort.
<a href="mailto:support@example.com?subject=Account%20Help">Account help</a>
2. Template-based bug reports
A body template guides the user to include useful details.
<a href="mailto:bugs@example.com?subject=Bug%20Report&body=Browser%3A%20%0ADevice%3A%20%0AProblem%3A%20">Report issue</a>
3. Dynamic generation with encoding
In JavaScript apps, the link is often built from user or app data.
function createMailto(recipient, subject, body) {
return `mailto:${recipient}?subject=${encodeURIComponent(subject)}&body=${encodeURIComponent(body)}`;
}
Common Mistakes
1. Forgetting to URL-encode spaces and symbols
Broken example:
<a href="mailto:test@example.com?subject=Hello World&body=How are you?">Send</a>
Problem:
- Spaces and special characters may break the URL or behave unexpectedly.
Better:
<a href="mailto:test@example.com?subject=Hello%20World&body=How%20are%20you%3F">Send</a>
2. Using ? more than once
Broken example:
<a href="mailto:test@example.com?subject=Hi?body=Message">Send</a>
Problem:
- Only the first
?starts the query string. - Additional parameters must use
&.
Correct:
Comparisons
| Approach | What it does | Best for | Limitations |
|---|---|---|---|
mailto: | Opens the user's email client with prefilled fields | Simple contact links | Depends on user email setup |
| HTML contact form | Collects user input on the page | Structured contact flows | Needs frontend and usually backend handling |
| Backend email API | Sends email directly from the server/app | Reliable production email sending | More setup and security work |
mailto: vs contact form
- Use
mailto:when you want something simple and quick. - Use a contact form when you need validation, storage, spam protection, or guaranteed submission.
mailto: vs backend sending
mailto:lets the send the email.
Cheat Sheet
Basic syntax:
mailto:recipient@example.com
With subject:
mailto:recipient@example.com?subject=Hello
With subject and body:
mailto:recipient@example.com?subject=Hello&body=How%20are%20you%3F
With multiple parameters:
mailto:recipient@example.com?cc=copy@example.com&subject=Hi&body=Message
Rules
- Use
?before the first parameter. - Use
&between additional parameters. - URL-encode spaces and special characters.
%20= space%0A= newline%3F=?%2C=,
JavaScript helper
const link = `mailto:test@example.com?subject=${encodeURIComponent("Hello")}&body=${encodeURIComponent("Line 1\nLine 2")}`;
Remember
mailto:opens an email draft.- It does not send the message automatically.
- Support can vary by browser, OS, and email client.
FAQ
Can I set the subject in a mailto: link?
Yes. Use the subject query parameter:
mailto:test@example.com?subject=Hello
Can I set the email body too?
Yes. Use the body parameter:
mailto:test@example.com?body=Hello%20there
Can I use both subject and body together?
Yes:
mailto:test@example.com?subject=Hello&body=How%20are%20you%3F
How do I add line breaks in the body?
Use %0A for a new line.
Does mailto: work in every browser?
It is widely supported, but behavior depends on the browser, operating system, and the user's configured email app.
Can mailto: send the email automatically?
No. It only opens a draft in the user's email client.
Should I use mailto: for a production contact system?
Only for simple cases. If you need reliability, validation, tracking, or guaranteed delivery, use a contact form and backend email service instead.
Mini Project
Description
Build a simple contact section for a website that opens the user's email app with a prefilled subject and body. This demonstrates how to create practical mailto: links and how to safely encode message content.
Goal
Create a contact link that opens an email draft with a recipient, subject, and multi-line body template.
Requirements
- Add a link that sends email to a fixed address.
- Prefill the subject with a meaningful label.
- Prefill the body with at least two lines of text.
- Ensure spaces and line breaks are correctly encoded.
Keep learning
Related questions
Allow Only Numeric Input (0-9) in HTML Input Using jQuery
Learn how to allow only digits 0-9 in an HTML input using jQuery, with examples, validation tips, common mistakes, and best practices.
CSS :not() Selector for Excluding a Class or Attribute
Learn how to use the CSS :not() selector to target elements that do not have a specific class or attribute, with examples and common mistakes.
Can HTML Checkboxes Be Readonly? Understanding readonly vs disabled in HTML Forms
Learn why HTML checkboxes do not support readonly, how disabled differs, and practical ways to prevent changes while still submitting values.