JDT

 

John Dixon
Technology
Limited

 
Google

Using PHP to Process a Feedback Form


In this article I explain how to create a simple feedback form, and how to send the data entered on that form to an email address.

Two web pages need to be produced to perform this task:

  • feedback.htm - the feedback form itself, and
  • processData.php - the form handler that processes the data entered on the form

feedback.htm

1. <html>
2. <head></head>
3. <body>
4. <table cellpadding="6">
5. <tr>
6. <td bg>
7. <h2>Feedback Form</h2>
8. Please use this form to provide feedback.
9. <form name="form1" method="post" action="processData.php" onSubmit='return checkfields()'>
10. Subject
11. <input type="text" name="title">
12. Enter text
13. <textarea rows="8" cols="43" name="comments"></textarea>
14. From (your email address)
15. <input type="text" name="from">
16. <br>
17. <input type="submit" name="Submit" value="Send Feedback">
18. </form>
19. </td>
20. </tr>
21. </table>
22. </body>
23. </html>

This is the form presented to the web site visitor. There are only three fields, but you could obviously have as many as you wanted to on your own form.

When the web site visitor clicks the Send Feedback button, the data entered into the three fields is sent to processData.php.

processData.php

1. <?php
2. // This page sends the feedback entered in the form to an email address
3. $title=$_REQUEST['title'];
4. $comments=$_REQUEST['comments'];
5. $from=$_REQUEST['from'];
6. // Email feedback to a specified email address
7. $email = "someone@somewhere.com";
8. // The subject
9. $subject = "Feedback from website";
10. // The message
11. $message = "Title:\n\n".
12. "$title\n\n".
13. "Comments:\n\n".
14. "$comments\n\n".
15. "From:\n\n".
16. "$from\n\n";
17. mail($email, $subject, $message, "From: $from");
18. ?>
19. <html>
20. <head>
21. </head>
22. <body>
23. Thank you for your feedback.
24. <br>
25. Kind Regards
26. </body>
27. </html>

There are two main areas to this web page: a PHP script at the top and an HTML area at the bottom. The PHP script gets the data from the form and puts them into three variables ($title, $comments, and $from). A subject variable ($subject) is also defined. The PHP mail function processes these variables and generates an email message that is sent to the email address defined in $email.

The bit of HTML at the bottom of the web page simply displays a message to the web site visitor after the email has been sent.


Author: John Dixon
John Dixon Technology Ltd







Go back to PHP Tutorials home page

Go back to Tutorials home page



Earnings Tracker is John Dixon Technology's FREE open source accounting / bookkeeping software tool.

Aimed at UK contractors and freelancers, Earnings Tracker enables you to perform many bookkeeping and accounting tasks, helping you to keep track of your company's earnings and outgoings.

The software is written in PHP and MySQL and is available to use for FREE online, or as a FREE download.

As it is written in open source software, you are free to modify the code yourself, enabling you to produce a customized version of Earnings Tracker that fits your own specification.

Earnings Tracker can also be used simply as a dividend, corporation tax, or VAT calculator.

Need free accounting software
 



JDT

© 2007-2009 - John Dixon Technology Ltd

Privacy Statement

Terms & Conditions