How to use the mailto: protocol in a <FORM> action (279460)
The information in this article applies to:
- Microsoft Internet Explorer (Programming) 4.0
- Microsoft Internet Explorer (Programming) 4.01
- Microsoft Internet Explorer (Programming) 4.01 SP1
- Microsoft Internet Explorer (Programming) 4.01 SP2
- Microsoft Internet Explorer (Programming) 5
- Microsoft Internet Explorer (Programming) 5.01
- Microsoft Internet Explorer (Programming) 5.01 SP1
- Microsoft Internet Explorer (Programming) 5.5
This article was previously published under Q279460 SUMMARY
The sample code provided in this article applies to developers that want to submit the contents of an HTML form directly to an e-mail address. The code also applies to developers who run into the length limitations documented later in this article when using the mailto: protocol in other situations. For the latter case, the body text is often the limiting factor.
For more information about length limitations, see the articles listed in the "References" section.
NOTE: Use of the approach outlined in the "More Information" section has several limitations, including:
- The other tags could exceed the maximum URL limitation by themselves. For instance, if there are a number of "To:" and "CC" recipients.
- A security popup when the user submits the FORM, as documented in the mailto protocol RFC, RFC2368.
- Internet Explorer uses MAPI to communicate with the default mail application. The e-mail client installed on the client computer must be MAPI-compliant. Microsoft Outlook and Outlook Express behave as described within.
- The e-mail client must have made the appropriate registry entries for this to work.
For more information about the registry entries, click the following article number to view the article in the Microsoft Knowledge Base:
154359
How to change the default mail client for Internet Explorer
The more robust approach, which does not have the mailto: protocol limitations, is to submit the FORM to an ASP/CGI script on a Web server. The script packages the data into an e-mail message. For an example about how to do this by using ASP and Collaboration Data Objects (CDO), refer to following Microsoft Knowledge Base article:
186204 How to use CDONTS to collect and mail information from a user
MORE INFORMATION
One solution is using a FORM with an ACTION of POST instead. The caveat is that FORM elements cannot be used to fill in the various fields like Subject, Body, and and so forth because the mailto: protocol handler does not examine these fields. All the FORM data is packaged and e-mailed away.
So, having the FORM ACTION fills in the Subject field as follows
<FORM Action="mailto:xyz?Subject=Test_Post" METHOD="POST">
mailto: protocol test:
<Br>Subject:
<INPUT name="Subject" value="Test Subject">
<Br>Body: 
<TEXTAREA name="Body">
kfdskfdksfkds
</TEXTAREA>
<BR>
<INPUT type="submit" value="Submit">
</FORM>
while having the FORM ACTION illustrated here does not:
<FORM Action="mailto:xyz" METHOD="POST">
mailto: protocol test:
<Br>Subject:
<INPUT name="Subject" value="Test Subject">
<Br>Body: 
<TEXTAREA name="Body">
kfdskfdksfkds
</TEXTAREA>
<BR>
<INPUT type="submit" value="Submit">
</FORM>
In both cases, the FORM data is e-mailed in as an Attachment, in an encoded format. For instance, in the preceding case, this is how the data looks:
Subject=Test+Subject&Body=%09kfdskfdksfkds%0D%0A%09
This is because the default ENCTYPE attribute for the FORM element is "application/x-www-form-urlencoded". To e-mail data in plain-text format instead, explicitly specify an ENCTYPE attribute of "text/plain". For instance:
<FORM Action="mailto:xyz" METHOD="POST" ENCTYPE="text/plain">
mailto: protocol test:
<Br>Subject:
<INPUT name="Subject" value="Test Subject">
<Br>Body: 
<TEXTAREA name="Body">
kfdskfdksfkds
</TEXTAREA>
<BR>
<INPUT type="submit" value="Submit">
</FORM>
produces the following Body:
Subject=Test Subject
Body= kfdskfdksfkds
REFERENCES
For more information, click the following article numbers to view the articles in the Microsoft Knowledge Base:
196461 How to set up a form to post results by e-mail in FrontPage 2000
194088 How to set up a form to post results by e-mail in FrontPage 98
For more information about character limitations, click the following article numbers to view the articles in the Microsoft Knowledge Base:
208427
Maximum URL length is 2,083 characters in Internet Explorer
263909 ShellExecuteEx limits URL to MAX_PATH
For more information about developing Web-based solutions for Microsoft Internet Explorer, visit the following Microsoft Web sites: http://msdn.microsoft.com/workshop/networking/predefined/mailto.asp
Modification Type: | Major | Last Reviewed: | 5/11/2006 |
---|
Keywords: | kbhowto KB279460 |
---|
|