Send emails from a web page

Although today almost all pages are versed in one server language or another: ASP, PHP, JSP,… there is a wide spectrum of pages developed in HTML. Almost always with the invaluable help of a web editor. And there are many people, who with minimal knowledge of the Internet, jump into it to tell something to cyberspace. And there will even be places where we can insert code HTML and that does not allow the use of another language

And already, once we have worked on a website, we want people to share with us their opinion about it. Or simply contact us.

Once in this situation, the easiest thing would be to put a text that is a link (or not) with our email address. Here, we are giving the caller only our address and he will use it to tell us whatever he wants. If you want to take this option, read the article «Email Link Properties» which will help you give more power to your email links.

But of course, we may want, when you write to us, to fill out certain information that with the email we will never know if you are going to send it to us or not. For this we have the forms. And that will be when we want you to send us what you filled out in the form.

At this point we have two options. Or we use some server language (for those mentioned, there is no waste Send emails with JavaMail)

For the user to send us the form using HTML we will only have to do one thing. Put «mailto:[email protected]» in the action of the form. We are left with a code HTML like this, using the FORM:

<form action="mailto:[email protected]"></form>

With this we will get the user to send us an email with the structure of the form.

Once we have set up our form we will see that if we click to send the received text it can be something like this:

textfield=victor&textfield2=victor%40miemail.com&textarea=cojonuda

The problem is that to differentiate the different parts of the message, the browser uses the field identifiers. That is why it is quite convenient to modify them. For this purpose you must modify the name field of the form fields. We could put them like this:

<input name="name" type="text" />

Now, the string received would be the following:

name=victor&email=victor%40miemail.com&opinion=cojonuda

Although it is still a cryptic chain, it is somewhat clearer than the previous one.

We also have to keep a couple of things in mind. The first is that this will only work if the user has an email program on their computer (Outlook, Outlook Express, Eudora…). You have to be careful, since although it is rare that the computer does not have an email program, it can happen.

The second is that although we have set the fields (even making them mandatory – we could use JavaScript-), the user has the ability to modify the email before sending it.

Even so, this is a good solution for them to contact us easily.

In the end we will have the following form:

<form action="mailto:[email protected]" method="post" name="form1">
  <label for="name">Name: </label>
  <input id="name" name="name" type="text" />
  <label for="email">Email: </label>
  <input id="email" name="name" type="text" />
  What did you think of the page?
  <textarea id="opinion" name="opinion"></textarea>
  <input name="Submit" type="submit" value="Send" />
</form>