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.  
  27. // e-mail subject
  28. $subject = "Feedback from $contact_custname";
  29.  
  30. // e-mail message
  31. $message = "You have received feedback:
  32. "."----------------------------------------------
  33. "
  34. ."Contact Name: $contact_name
  35. "
  36. ."Business Name: $contact_accno, $contact_custname
  37. "
  38. ."Subject: $contact_subject
  39. "
  40. ."Submitted: $mydate
  41. "
  42. ."From IP: {$_SERVER['REMOTE_ADDR']}
  43. "
  44. ."URL: $loc
  45. "
  46. ."Browser: $Browser->Name $Browser->Version
  47. "
  48. ."Message: $contact_message";
  49.  
  50. $headers = "From: $contact_name <$contact_email>\n"
  51. ."Reply-To: $contact_email\n"
  52. ."X-Mailer: PHP/".phpversion();
  53.  
  54. // check for validation, then send the e-mail
  55. if(empty($contact_name) || empty($contact_email) || empty($contact_subject) || empty($contact_message)) {
  56. echo '<h2>Have feedback?</h2>
  57. <form method="post" action="">
  58. <table id="Form-Details">
  59. <tbody>
  60. <tr><td width="20%">Your Name:</td><td><input type="text" name="FullName" size="40" /></td></tr>
  61. <tr><td width="20%">Subject:</td><td><select name="Subject">
  62. <option value="Feedback">Feedback</option>
  63. <option value="Suggestion">Suggestion</option>
  64. <option value="Bug Report">Bug Report</option>
  65. <option value="Question">Question</option>
  66. </select>
  67. </td></tr>
  68. <tr><td width="20%">Email:</td><td colspan="3"><input type="text" name="EmailAddress" size="40" /></td></tr>
  69. <tr><td colspan="4">Message:</td></tr>
  70. <tr><td colspan="4"><textarea rows="6" name="Message" cols="47" class="input"></textarea></td></tr>
  71. <tr><td colspan="4" align="right"><input type="submit" value="Submit Feedback" /></td></tr>
  72. </tbody>
  73. </table>
  74. </form>';
  75. } elseif(!ereg("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $contact_email)) {
  76. echo "<h2 style='font-weight:bold;color:red;'>ERROR: Please enter a valid e-mail address.</h2>";
  77. } else {
  78. mail( $to, $subject, $message, $headers );
  79. 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.";
  80. }
  81. ?>
  82. </body>
  83. </html>

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.