How to Get Email from an HTML Form

Your requirement is simple; you have created a form and want to get the information submitted in the form via email. However, getting this right is not very easy as it sounds. This article attempts to clear the misunderstandings that some people used to have about email forms.

Note Using Simfatic Forms drag & drop form builder, you can make awesome email forms quickly!

How to send email directly from your HTML form?

It would have been a nice feature for a web developer if the browsers let them route the form submission directly to an email address. But this is not the case. The reason is that if the browsers allowed emailing directly from the form page, that will reveal the visitors email address. A malicious hacker can collect the email address of the visitors to the web page and then spam them. In order to protect the web users, no client side language can send email without the user’s intervention.
No way to send email directly from HTML

Is there an HTML Code to send email from a form submission?

There is no feature in HTML to send the form submission directly to an email address.
What about “mailto” ?
Using mailto:
You can set the action field of the form as ‘mailto’. In this case, the web browser invokes the email client to send the form submission to the email address specified.

<form action="">

However, this method is not compatible across browsers. It is not user friendly too; on form submission, it throws a warning message. For more details on this method, see:
email form using mailto

Can JavaScript send the form submission to an email address?

No. JavaScript can’t do email either. If the client-side JavaScript allowed sending email programmatically, spammers will be the first to exploit it and you will hate your web browser!

So, How to get email from an HTML form?

Before jumping into the solution, I will take you through the general structure of a web form. A web form has two parts: the front-end of the form that you see in your browser and a back-end script that runs on the webserver.
A web form has two parts: client side HTML and server side script
Your web browser displays the Form using the HTML front-end code. When you submit the form, the browser sends the information you submitted in the form to the back-end.

when you submit the form, the browser sends the form data to the script on the web server

The link to the back-end script is mentioned in the ‘action’ attribute of the HTML form tag.

<form action="">

The browser picks the link (URL) mentioned in the action attribute and sends the form submission data to that URL. The webserver passes the form submission data to the script in the action URL (yourform-processor.php in the example.)
Now, the back-end script can send emails, save form submission to a database or even direct the user to a payment page.
the server side script sends email

How to create a back-end Script?

There are a number of scripting languages created for back-end programming. PHP is one of the popular and widely supported scripting platform (Others include Perl, Ruby, ASP- for windows only- etc) Almost all hosting services support PHP on their webservers.

Working of a simple PHP script

The PHP script runs on your web server. When a form is submitted, the form mail script collects the data submitted in the form, composes an email and sends the email to the address it is configured.

php form mail script working

Further Reading and Resources

Note: Using a web form maker tool like Simfatic Forms, you can make complete web forms ( send submissions to email, save to database and more) quickly.

Be Sociable, Share!

Comments on this entry are closed.

  • Cynthia

    I can’t get into my e-mail.

  • http://none Rajendra Srivastava

    I want to know how to send content of feedback htm form to my email id without using outlook express.
    Please reply me.
    Thanks in advance…

  • sammy

    hey when i click on submit outlook express opens but i dont need dat…i jsut wanna have mai and oder details in my email account..pls rply asap

    • Bill

      Ya i know that happend with me I HAVE NO IDEA

  • Sara

    thanks for the great info which ill def use

  • peter

    pls i want the java code that can help me send a confirmation messages to the email address of users who fill my form on my site.thanks

  • Bill

    So you’re saying it’s wrong, but WHAT’S RIGHT????!!!!!!

  • Updesh