Notice: This website is an unofficial Microsoft Knowledge Base (hereinafter KB) archive and is intended to provide a reliable access to deleted content from Microsoft KB. All KB articles are owned by Microsoft Corporation. Read full disclaimer for more details.

How to use the mailto: protocol in a <FORM> action


View products that this article applies to.

This article was previously published under Q279460

↑ Back to the top


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

↑ Back to the top


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:&#xa0;
	<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:&#xa0;
	<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:&#xa0;
	<TEXTAREA name="Body">
	kfdskfdksfkds
	</TEXTAREA>
	<BR>
	<INPUT type="submit" value="Submit"> 
</FORM>
				
produces the following Body:
Subject=Test Subject
Body=	kfdskfdksfkds
				

↑ Back to the top


References

For more information, click the following article numbers to view the articles in the Microsoft Knowledge Base:
196461
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

↑ Back to the top


Keywords: KB279460, kbhowto

↑ Back to the top

Article Info
Article ID : 279460
Revision : 5
Created on : 5/11/2006
Published on : 5/11/2006
Exists online : False
Views : 523