52

is there anyway that I can use "mailto" with empty recipient? I only want to supply the subject and the message body and then the user can write the to addresses on mail. I tried writing only a space but it didn't work.

6
  • When you say "didn't work", what do you mean? Does anything at all happen when you click on the link? And can you post the "a href" link you tested with? Nov 20, 2009 at 9:09
  • Also, what mail application are you using? Nov 20, 2009 at 9:10
  • 1
    And thirdly, why do you want this anyway? Are you making a shortcut to send email to anyone? Usually you want people to send an email from a website to a specific mailbox, like a support mailbox or similar. What are you actually trying to implement here? I'm pretty sure most people that use email is clever enough to be able to start a new email by themselves. What problem are you trying to solve? Nov 20, 2009 at 9:11
  • i meant the email application of the iphone couldn't be opened when i left the recipient empty. it s not a href; NSString *url = [NSString stringWithString: @"mailto: ?subject=Test&body=Test!"]; [[UIApplication sharedApplication] openURL: [NSURL URLWithString: url]];
    – xenep
    Nov 20, 2009 at 9:19
  • i'm showing football news in my application and i want to add a share functionality to news.every news has a share button at the bottom and i want the mail application of iphone to be opened with news title as the subject and news as the message content when that share button is clicked. then user can write the to addresses to send.
    – xenep
    Nov 20, 2009 at 9:24

3 Answers 3

58

This should do, I tested it.

mailto:?subject=your%20subject&body=your%20body

And as HTML with correct escaping of the ampersand:

<a href="mailto:?subject=your%20subject&amp;body=your%20body">test</a>
6
  • 1
    is there a need to escape the ampersand? & -> &amp; May 3, 2013 at 18:51
  • @DigitalDesignDj No, that's a URL parameter, but your subject and message body will need to be URL encoded.
    – Xyon
    Jun 27, 2013 at 10:50
  • @Már Örlygsson see @Xyon's comment - you shouldn't escape the ampersand after subject because it's a URL parameter separator, not a literal ampersand. Jan 8, 2016 at 17:26
  • Nope, the example shows the URL as part of HTML code - and "&" is a reserved character in HTML and needs to be escaped. The code example is invalid HTML without &amp; Jan 17, 2016 at 21:39
  • The above example will work without the &amp; escaping - but only because current browsers adhere to the Robustness Principle and autocorrect this bad HTML. Jan 17, 2016 at 21:41
12

This should work..

<a href="mailto:?subject=My Subject">test</a>
1
  • 3
    Of all the suggestions, this was one was the working for me. A lot of the other solutions are 5 years old.
    – afxjzs
    Dec 10, 2014 at 16:55
7

I tried the accepted answer but it failed to launch an email when using Chrome. Using a %20 instead of a space worked though:

<a href="mailto:%20?subject=Wazzup&body=Yo">Send an Email</a>

1
  • This worked for me while the others weren't. I was using chrome and my default mail client was outlook 2013 desktop.
    – user967451
    Aug 31, 2015 at 19:00

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.