Web Development
How to create a feedback form and receive an email
Ipshita Soni
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..
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
Latest projects on Web Development
Want to develop practical skills on Web Development? Checkout our latest projects and start learning for free
- 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.
- 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.
- 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.
- 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”.
- 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.
- 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.
- 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.
- 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.
- 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.
- 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.
Did you know
Skyfi Labs helps students learn practical skills by building real-world projects.
You can enrol with friends and receive kits at your doorstep
You can learn from experts, build working projects, showcase skills to the world and grab the best jobs.
Get started today!
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:
How to create a feedback form and receive an email
Skyfi Labs
•
Published:
2020-08-02 •
Last Updated:
2021-06-25