How to create a feedback form and receive an email

Published on . Written by

How to create a feedback form and receive an email

You may often come across some form links which redirect you to a page. The page contains big boxes with some questions and here you are asked to fill in the boxes with the answers to their respective questions. These types of forms are often asked to fill by students to collect their data. Else, these forms are made for websites to collect feedback about the website. Such forms have many such advantages and may look tough to build but it is yet another easy task if you decide to do it with interest. 

Read more..

SLNOTE

Skyfi Labs Projects
This blog will guide you through the process of creating a feedback form. The form will have three fields such as name, email address, and message. So, let us look into it. 

Knowledge required: PHP 

Tools required: Text editor


SLLATEST
  1. First of all, make a new folder with two files named index.php and contact.php. You will make the whole form in index.php and also style and edit the form with CSS. You will use the contact.php for the main logic and receiving the email.
  2. Design a simple feedback form in Index.php. Create three input fields named “name”, “email”, and “message”. Also, create a button named “send”. The user will answer these questions in these fields.
  3. Style and edit the form using CSS. All the fields are required therefore put a ‘*’ before all the fields indicating the fact. You will have to create a logic such that if any required field is not filled by the user then the screen displays an error. Likely, if all the three fields are left empty then there are three errors. 
  4. Remember to link your contact.php file in your index.php file where you will make the outline code and also the method should be “post”.
  5. To generate errors, create an array. This array will be used to loop through later. Make an if statement to see if the fields name, email, and messages are set. Also, make an else type a message “something went wrong”. Create another array which will hold the entered data.
  6. You will have to loop through the array and see which fields are empty and therefore notify the user on the screen displaying the error. Give the print statement in the index.php file. Keep the errors in a list. 
  7. Next, work on receiving an email with all the feedback details to your email account. For this, you can use the PHP mailer library available on the internet. Install the required documents and then include the files in contact.php.
  8. To receive an email finally use the PHP mailer autoload now. Check if the array of errors is empty. This means the data was entered and therefore you can extract it and mail it to yourself.
  9. Instantiate PHP mailer then use SMTP authentication. Set the server to smtp.gmail.com. Set the username to your Gmail account and then set the password to the password of your Gmail account. Set the port to 465.
  10. Last but not least create a subject that will be displayed each time you receive feedback as an email. So, the subject can be “feedback received”. Also, make a body that will contain all the details which the user filled in the feedback form.

SLDYK
Kit required to develop How to create a feedback form and receive an email:
Technologies you will learn by working on How to create a feedback form and receive an email:


Any Questions?


Subscribe for more project ideas