Sometimes, improving UX can cost a lot of money.
And oftentimes, some of the problems website visitors have are easy, simple fixes.
That begs the question: How can you find out if customers are enjoying their website experience?
The answer may be simpler than you think.
Having forms on your website is an effective way to get customer feedback about their experience during their visit. These forms give you insight about how to improve your website's UX for higher conversions in the long run.
In fact, 74% of marketers use forms to generate leads, and of those marketers, over half say that it's the tool that leads to conversion the most often.
Whether you want to convert more visitors to leads, collect information for your sales team, or create more loyal brand advocates, forms are imperative to an inbound strategy.
Ultimately, forms are critical for solving dissatisfaction in a customer's experience, which ensures stronger customer relationships. If you don't have a form on your website, you could be missing out on more leads, higher conversions, and happier long-term customers.
Here, we're going to walk you through how to create a certain type of form — one that sends an email to you, as well as the customer, to ensure the form was received.
How to Create a Form in HTML and Send it to Email
It is possible to create an HTML form that sends emails, but it depends on how you work and on what platform you're working. This is to say that things are a little different if the plan is to use a mix of HTML and different scripts.
Using the Basics
Using just HTML? We've got you covered. From starting fresh, here is a sample code for use:
<input type=”text” size=”19″ name=”ContactName”><br><br>
Message:<br> <textarea name=”ContactCommentt” rows=”6″ cols=”20″>
</textarea><br><br> <input type=”submit” value=”Submit”> </form>
This code will create a form that asks for the contact's name, message, and includes a submit button. Note that this code is basic — it won't look super snazzy. For a more beautiful one, you'll have to add some more lines of code specific to your needs.
Another thing to note with this code is that it doesn't directly send to email addresses, but it can open in an email client or tool window to submit the form.
While you can use just basic HTML, this isn't the ideal option.
The Difficulty of Email Forms in HTML
Ideally, browsers would allow you to route form submissions directly to an email address. However, the reason they don't is that emailing directly from an HTML web form would reveal the visitor's email address, making the user vulnerable to malicious activities, such as phishing.
While the HTML code above can activate the default mail client on the user's computer, the web browser does so by sending a request to the email service provider, not to the specified address.
There are a few problems with the mailto: option. For example, it isn't 100% compatible with all browsers, it isn't very user-friendly, and it's impossible to control the formatting of the data when the form is sent by the browser.
Beyond that, a warning message will pop up when the user goes to submit the form, letting them know that the information they're about to send will not be encrypted for privacy. This can spook the user out of submitting the form at all.
So, what HTML code allows you to send form submissions directly to an email address?
To make it so the form can work with your email server and send it to a mailbox, PHP is the answer — let's explore that option now.
Making a Complete Form
To create a form subscribers can contact you with, the PHP script is going to be your best friend. I know, another acronym. This one stands for Hypertext Preprocessor, and this language collaborates with HTML to process the form.
Before jumping into the process, let's break down a few form basics.
A webform has two sides: The front-end, seen in the browser by visitors, and a backend script running on the server.
The visitor's web browser uses HTML code to display the form. When the form is submitted, the browser sends the information to the backend using the link mentioned in the "action" attribute of the form tag, sending the form data to that URL.
For example: <form action=https://yourwebsite.com/myform-processor.php>.
The server then passes the data to the script specified in the action URL -- myform-processor.php in this case. Using this data, the backend script can create a database of form submissions, direct the user to another page (e.g. payment), and send an email.
There are other scripting languages you can use in the backend programming, like Ruby, Perl, or ASP for Windows. However, PHP is the most popular and is used by almost all web hosting service providers.
If you need to make a complete form, follow the steps below.
How to Make an HTML Form that Sends Email
- Use PHP to create a page.
- Make the form using code.
- Make forms send email.
1. Use PHP to create a page.
When you're creating a webpage, instead of using the ".html" extension, type ".php" instead. This is similar to what happens when you save an image as "jpg" versus "png".
By doing this, the server will know to host the PHP you write. Instead of saving the empty HTML page as such, save it as something like this: "subscriberform.php". After your page is created and saved, you'll then be able to create the form.
2. Make the form using code.
In this step, you'll write the code to create the form.
If you're not sure how to create forms in HTML, check out HTML Dog's resource for a primer on the basics.
The following code is what's needed for a basic form:
<form method="post" action="subscriberform.php">
Because this is similar to the HTML-only write-up, these lines will also create a name for the form and an area for subscribers to type a custom message and send it to you.
An important difference is the "action=contact.php" part. This portion of code is what will make the page send the form when submitted. Recall that in the first example, that wasn't an option.
3. Make forms send email.
After you create the form and add all the proper fixings depending on your design preferences, it's time to create the email portion.
For this, you're going to scroll to the beginning of the page (the very beginning, even before defining the HTML Doctype). To enable sending data in the email, we have to add code that will process the data. Copy this code or create something similar:
mail("firstname.lastname@example.org", "Here is the subject line",
$_POST["insert your message here"]. "From: email@example.com");
Recall that everything inside the first and last lines will tell the webpage to make these functions perform as PHP. This code also checks to see if a subscriber uses the form. From there, it checks to see if the form was sent.
Further breaking it down, "mail" sends the completed form as an email to "firstname.lastname@example.org," and the subject line is what follows. In the next line, you can write copy of the email message inside the quotes, to be sent from whichever email address you choose.
To sum up the process to create HTML email forms:
Once the form is submitted, the page sends the data to itself. If the data has been successfully sent, the page sends it as an email. The browser then loads the page's HTML -- the form included.
With that, you have the basic code you need to create the form.
Note that this is just one way to do this — alternatively, you can also create a form using a CRM like HubSpot.
If you're a HubSpot customer, keep reading to learn how to use HubSpot's tool to create an HTML form that sends you an email.
HubSpot Forms is part of the Marketing Hub, and doesn't require any previous technical knowledge.
If you want to learn how to receive an email after a form submission, take a look at our Knowledge Base article.
When you're using HubSpot Forms, you can build custom forms that connect to your contacts list. You can also customize those forms and trigger automatic emails based on the completion of your forms. Note that the latter requires a premium upgrade. Click here for more information about HubSpot's forms.
HTML forms are a fairly simple process and an excellent way to connect with subscribers. Having these on your site gives customers an easy way to contact your company or sign-up for emails.
Forms that send an email back to you keeps information in your inbox for reference and ease. Remember that these aren't your only options for building forms. If you want a list of tools that help build forms, check out our post here.
Editor's note: This post was originally published in December 2019 and has been updated for comprehensiveness.
Originally published Jun 23, 2020 4:00:00 AM, updated June 10 2021