48

How do I set a proper name for the recipient when in HTML I want to use the "mailto" tag.

Something like:

mailto:"John Wayne([email protected])?subject..

How do I achieve that ??

0

8 Answers 8

33

The original standard for mailto: links, RFC 1738, says this:

A mailto URL takes the form:

mailto:<rfc822-addr-spec>

where <rfc822-addr-spec> is (the encoding of an) addr-spec, as specified in RFC 822 [6].

Under that definition, addr-spec is of the form "local-part@domain", so no proper name could be included.

But the mailto: section of RFC 1738 was first superseded by RFC 2368, which allows (among other things, including predefined subject lines) for an RFC 822 mailbox specification—which includes a proper name.

[2016-05-31] As David Balažic points out in a comment, RFC 2368 is in turn obsoleted by RFC 6068. From Section 9, “Main Changes from RFC 2368”:

The main changes from RFC 2368 are as follows:

An RFC 5322 <addr-spec> is of the same "local-part@domain" form as mentioned above, so once again, no name can officially be included.

In actual use, mailto:Fred Foo<[email protected]> still seems to work, but it’s not officially supported; you may also have to encode the space, i.e., mailto:Fred%20Foo<[email protected]>, and/or put the name in quotes, i.e., mailto:"Fred Foo"<[email protected]>.

1
  • 7
    Note that that RFC 2368 is obsoleted by RFC 6068 , which defines addr-spec = local-part "@" domain , so it seems display name is not allowed in it. May 24, 2016 at 17:42
20

Try this: mailto:%22John%20Wayne%22%[email protected]%3e?subject..

Wrap the name in %22 and the email has %3c before it and %3e after it and %20 for spaces

That will output: "John Wayne"<[email protected]>

Full list of URL Encoding here: http://www.w3schools.com/tags/ref_urlencode.asp

5
  • 2
    Great, thanks for the ref. BTW: the %22 around the display name are not required.
    – Wolf
    Sep 23, 2016 at 10:40
  • 2
    This is not standards-compliant.
    – user824425
    Dec 24, 2016 at 1:22
  • Doesn't work with the Mail application in Windows 10. Using mailto:John Wayne<[email protected]> (with or without encoding the space between first and last names) does work.
    – Aaron
    Jul 15, 2017 at 0:00
  • 4
    @Aaron I would disregard any results with the Windows 10 Mail app - it is as far away from standards as IE5/6/7 ever were - it doesn't even respect the Reply-To header field.
    – Jake
    May 12, 2020 at 22:23
  • Fair call @Jake.
    – Aaron
    May 13, 2020 at 8:53
7

I tried

mailto:John Wayne<[email protected]>?subject...

and it seems to work.

1
  • 1
    Where did you try this? It definitely works not for me.
    – Wolf
    Sep 23, 2016 at 10:37
5

As mentioned in other answers, RFC 2368 allows the full mailbox syntax, which can be in name-addr (display-name plus angle-addr) form (RFC 5322). Unfortunately, it was obsoleted by RFC 6068, which only allows addr-spec form. However, both specifications allow omitting the URI authority (where the to-address usually goes) and specifying full header fields (including To:) as query parameters. Therefore, mailto:?to=John%20Wayne%20%[email protected]%3e is valid.

1
  • 3
    For me mailto:?to=John%20Wayne%20%[email protected]%3e does work with ubuntu+evince+thunderbird, but it does not work with windows7+firefox+outlook. However mailto:John%20Wayne%20%[email protected]%3e works with both.
    – not-a-user
    Jan 16, 2018 at 10:30
1
  <a href="mailto:lala lala2([email protected])?subject=MailTo Comments&[email protected]&[email protected]">ddddd</a>

Remember to use only one ? (question mark), when providing multiple entries beyond e-mail address

2
  • Not sure if it really tackles my original question :-) where is the Name of the recipient on the TO part? Nov 16, 2011 at 18:14
  • @SFDeveloper: I believe "lala lala2" is the name of the recipient in this example. Mar 4, 2021 at 21:24
-1

This all depends on what mail client you use. I've tried that long before at Outlook express and it's ok. But after many years, I use Dream Mail and it will only bring in the mail address part while leave out the name part.

-1

Encode the uri and assign it to mailto.

Also your email and display name need to be formed as either John Wayne <[email protected]> or [email protected] (John Wayne).

Make sure you did encodeURI for these. Else it wont work properly in different mailclients.

1
  • I think encodeURI() can just solve the purpose. Instead of adding the %22 or any characters to add space or parenthesis. I don't know why its downvoted too.
    – jerry
    Jan 3, 2017 at 6:22
-6

You can't set the receipt name on mailto links

2
  • sorry for the last comment . I was the stupid who didnt read the question properly.
    – Royi Namir
    Nov 16, 2011 at 20:42
  • Yes you can; see the other answers. Apr 28, 2013 at 17:31

Your Answer

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.