Php Feedback Form w/ Session and Browser Info


/ Published in: PHP
Save to your folder(s)



Copy this code and paste it in your HTML
  1. <? include("browser_class.php"); ?> //include class from here http://snipplr.com/view/35627/php-browser-detection-class/
  2. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  3. <html xmlns="http://www.w3.org/1999/xhtml">
  4. <head>
  5. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  6. <title>Untitled Document</title>
  7. <link rel="stylesheet" href="attSearch.css" type="text/css" />
  8. <style>
  9. body {width:400px;margin:0px auto;text-align:left!important}
  10. h2 {color:green;}
  11. </style>
  12. </head>
  13.  
  14. <body style="background:none!important;">
  15. <?php
  16. // declare values
  17. $loc = $_COOKIE['location'];
  18. $contact_email = $_POST['EmailAddress'];
  19. $contact_subject = $_POST['Subject'];
  20. $contact_name = $_POST['FullName'];
  21. $contact_message = $_POST['Message'];
  22. $contact_custname = $_SESSION['businessName'];
  23. $contact_accno = $_SESSION['accountNo'];
  24. $mydate = date ( 'l, F d Y g:i A',time()+240 );
  25. // where to send e-mail to
  26. $to = 'youremail@yourprovider.com';
  27.  
  28. // e-mail subject
  29. $subject = "Feedback from $contact_custname";
  30.  
  31. // e-mail message
  32. $message = "You have received feedback:
  33. "."----------------------------------------------
  34. "
  35. ."Contact Name: $contact_name
  36. "
  37. ."Business Name: $contact_accno, $contact_custname
  38. "
  39. ."Subject: $contact_subject
  40. "
  41. ."Submitted: $mydate
  42. "
  43. ."From IP: {$_SERVER['REMOTE_ADDR']}
  44. "
  45. ."URL: $loc
  46. "
  47. ."Browser: $Browser->Name $Browser->Version
  48. "
  49. ."Message: $contact_message";
  50.  
  51. $headers = "From: $contact_name <$contact_email>\n"
  52. ."Reply-To: $contact_email\n"
  53. ."X-Mailer: PHP/".phpversion();
  54.  
  55. // check for validation, then send the e-mail
  56. if(empty($contact_name) || empty($contact_email) || empty($contact_subject) || empty($contact_message)) {
  57. echo '<h2>Have feedback?</h2>
  58. <form method="post" action="">
  59. <table id="Form-Details">
  60. <tbody>
  61. <tr><td width="20%">Your Name:</td><td><input type="text" name="FullName" size="40" /></td></tr>
  62. <tr><td width="20%">Subject:</td><td><select name="Subject">
  63. <option value="Feedback">Feedback</option>
  64. <option value="Suggestion">Suggestion</option>
  65. <option value="Bug Report">Bug Report</option>
  66. <option value="Question">Question</option>
  67. </select>
  68. </td></tr>
  69. <tr><td width="20%">Email:</td><td colspan="3"><input type="text" name="EmailAddress" size="40" /></td></tr>
  70. <tr><td colspan="4">Message:</td></tr>
  71. <tr><td colspan="4"><textarea rows="6" name="Message" cols="47" class="input"></textarea></td></tr>
  72. <tr><td colspan="4" align="right"><input type="submit" value="Submit Feedback" /></td></tr>
  73. </tbody>
  74. </table>
  75. </form>';
  76. } elseif(!ereg("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $contact_email)) {
  77. echo "<h2 style='font-weight:bold;color:red;'>ERROR: Please enter a valid e-mail address.</h2>";
  78. } else {
  79. mail( $to, $subject, $message, $headers );
  80. echo "<h2>Message Sent!</h2><br /><p>$contact_name,<br /><br />Thank you for your feedback, we will get back to you as soon as possible using $contact_email.";
  81. }
  82. ?>
  83. </body>
  84. </html>

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.