HTML.form.guide

Sending form submissions to email using 'mailto:'

email form mailto mailto email form

The simplest method to get the form submissions posted to you via email is by using “mailto:” in the action field of the form. However, this method has many drawbacks. First, let us see how we can use ‘mailto’ in a form.

How to set up ‘mailto’ in your HTML form

In the action field of the form, set the action as “mailto:youremailaddress” for example:


<form action="mailto:myforms@mydomain.com">

The sad part is that the behavior of such a form will be different in different browsers.

In Internet Explorer 6, on submitting the form it throws a message as shown below:

If you press ‘Yes’ then if the default email client is outlook express, outlook express is invoked and an email is sent with an attachment POSTDATA.ATT

What is POSTDATA.ATT?

When a form is submitted using the “mailto:” method, outlook express sends the submitted form data as an attachment POSTDATA.ATT. It is simply a text file and you can open it using notepad. However, the file will contain the submitted form data in somewhat cryptic format.

If the form contains fields: ‘Name’, ‘Email’, ‘Address’ and submit, POSTDATA.ATT for a sample submission looks like this:


Name=john&Email=john@yahoo.com&Address=&Submit=Submit

How to get the form data in plain text

As you saw, it is difficult to read the POSTDATA.att. You can make the form data sent to be in readable form by making a small change in the form.

Add ’enctype=text/plain’ in the form attributes. The form code becomes:


<form action="mailto:myforms@mydomain.com" enctype="text/plain" >

When this form is submitted, you will get the email in readable form. Like this:


Name=john  
Email=john@yahoo.com  
Address=  
Submit=Submit  

How to show a ‘Thank You’ page

You have successfully submitted the form. Now you want to show a confirmation page to the visitor that the form is submitted. Here is how to do it:

Suppose the name of the confirmation page is thanks.html Update the code for the form tag to:


<form action="mailto:myforms@mydomain.com" 
enctype="text/plain" onsubmit="location.href='thanks.html';" >

How to customize the subject of the email

By default, the subject of the email that you receive from such a form will read something like: “Form posted from Microsoft Internet Explorer” The following code shows the change:


<form action= "mailto:myforms@mydomain.com?subject=myform_submission" 
enctype="text/plain" onsubmit="location.href='thanks.html';" >

Drawbacks of ‘mailto’ email form

We have seen that using mailto is the simplest way to get your HTML form submissions via email. However, there are many disadvantages for this method.

  1. Your visitor must have Internet Explorer as the browser and Outlook Express as the default client for this to work correctly.
  2. Even if your visitor is using Internet Explorer, but the default mail client is different, your mailto form will not work.
  3. Even if your visitors have IE and has configured Outlook Express as default mail client, they may press cancel on the warning dialog that pops up.
  4. According to the HTML specifications, the action field of the form should be a correctly formed HTTP URL. So ‘mailto:’ is not valid for the action field.

Use a form mail script

The only consistent alternative to ensure that you get the email form the form submissions is to use a form mail script.

See:
Using form mail scripts

See Also