Hostaan.one WordPress plans from €0.99/mo for the 1st year (-67%). See Black Friday web hosting
Skip to content
Contents

Web Hosting

Building a feedback form

Feedback and contact forms are usually easiest to build with the tools of the content management system you use, or, for example, with the tools of the Sitebuilder we offer. In WordPress, for example, you can install a plugin called
Contact Form 7 for this. In our Sitebuilder you can add a contact form through the Form menu. However, if you build your website entirely yourself, by editing HTML files and transferring them to the server, you also have to build the feedback form yourself.

In this guide we go through building a simple and secure feedback form in PHP. In the form, the recipient address is defined inside the PHP code, so the email address is not exposed to spam bots that harvest addresses, and the form cannot otherwise be misused for sending spam either.

To build the feedback form you need two files: an HTML file containing the feedback form itself (which you can also freely adapt to your own HTML site template) and a form sender written in PHP, which takes care of checking the form and sending it to your email.

Feedback form

Copy the example form's source code from the following box into the HTML text editor you use and save it as palaute.html.

You can also download the ready-made file here: palaute.html

Form sender

Next, copy the PHP code that sends the form from the following box into the HTML text editor you use and save it as postita.php.
You can also download the ready-made file here: postita.php

Adapt the files as follows:
  • In the file postita.php, on the second line, replace the $mailto parameter with your own email address, where you want the form to be delivered
  • Transfer both files to the httpdocs directory of your hosting space and open the form at http://www.yourdomain.tld/palaute.html
  • Test that the form reaches your email address before you publish it

Customizing the form and additional settings

If you need more fields in your form, you can add them by adding label and input tags to the palaute.html file and giving them unique names (for example 'phone'). The corresponding fields must also be added to the fields array in the postittaja.php file (for example "phone" => "*", ). With an asterisk (*) you control whether the field is required or optional to fill in.

You can also create your own thank-you and error pages for your site. In that case, remove the comments from lines 6-7 of the postittaja.php file and replace the URLs of the thank-you and error pages you have built in the $thanks and $error variables on those lines.

Read also

Back to category guides