Friday 8 June 2012

Sending form submissions to email using 'mailto:'

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.


How to get the form data in plain text
We 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 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.

No comments:

Post a Comment