Guest User

Untitled

a guest
Jul 11th, 2018
197
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.32 KB | None | 0 0
  1. <?php
  2.  
  3. class ContactPop {
  4. /****** config *********/
  5.  
  6. // the title of the emails that the form sends
  7. var $emailTitle = 'MYSITE Contact Form';
  8.  
  9. var $thankYouMessage = "Thank you for contacting us, we'll get back to you shortly.";
  10.  
  11. /******* end config ********/
  12.  
  13.  
  14. var $error = '';
  15.  
  16. function getFormHtml($ajax = 0) {
  17.  
  18. $postedName = $_POST['name'];
  19. $postedEmail = $_POST['email'];
  20. $postedMessage = $_POST['message'];
  21.  
  22. $sendto = $_POST['subject'];
  23. if ($sendto == 'option1')
  24. { $recipient = 'option1@mail.com'; }
  25. elseif ($sendto == 'option2')
  26. { $recipient = 'option2@mail.com'; }
  27. elseif ($sendto == 'option3')
  28. { $recipient = 'option3@mail.com'; }
  29. elseif ($sendto == 'option4')
  30. { $recipient = 'option4@mail.com'; }
  31. elseif ($sendto == 'optoin5')
  32. { $recipient = 'option5@mail.com'; }
  33.  
  34.  
  35. $formHtml = '';
  36.  
  37. // send congratulations message
  38. if ( isset($_POST['httpReferer']) && !$this->error ) {
  39. $out = '<p id="contact-pop-error" class="formItem">' . $this->thankYouMessage . '</p>';
  40.  
  41. if ( $ajax ) $out .= '<a href="#" class="close-overlay">Close</a>';
  42.  
  43. return $out;
  44. }
  45.  
  46. if ( $this->error ) $formHtml .= '<p id="contact-pop-error" class="formItem">' . $this->error . '</p>';
  47.  
  48.  
  49. $httprefi = $_SERVER["HTTP_REFERER"];
  50.  
  51. $cancelLink = $ajax ? '<a href="#" class="close-overlay">Cancel</a>' : '';
  52.  
  53. $formHtml .= <<<EOT
  54.  
  55. <input type="hidden" name="httpReferer" value="$httprefi" />
  56.  
  57. <div class="formItem">
  58. <label>Pick a relevant subject:</label>
  59. <select class="inputText2" name="subject">
  60. <option class="dropdown" value="option1">option1</option>
  61. <option class="dropdown" value="option2">option2</option>
  62. <option class="dropdown" value="option3">option3</option>
  63. <option class="dropdown" value="option4">option4</option>
  64. <option class="dropdown" value="option5">option5</option>
  65. </select>
  66. </div>
  67.  
  68. <div class="formItem">
  69. <label>Name:</label>
  70. <input type="text" name="name" class="inputText" value="$postedName" size="35" />
  71. </div>
  72.  
  73. <div class="formItem">
  74. <label>Company:</label>
  75. <input type="text" name="company" class="inputText" value="$postedCompany" size="35" />
  76. </div>
  77.  
  78. <div class="formItem">
  79. <label>Email:</label>
  80. <input type="text" name="email" class="inputText" value="$postedEmail" size="35" />
  81. </div>
  82.  
  83. <div class="formItem">
  84. <label>Website:</label>
  85. <input type="text" name="website" class="inputText" value="$postedWebsite" size="35" />
  86. </div>
  87.  
  88. <div class="formItem">
  89. <label>Message:</label>
  90. <textarea name="message" class="textarea" rows="7" cols="38">$postedMessage</textarea>
  91. </div>
  92.  
  93. <div class="formItem">
  94. <input type="submit" value="Send Message" class="submit" />
  95. </div>
  96.  
  97. EOT;
  98.  
  99. return $formHtml;
  100. }
  101.  
  102. function checkEmail($emailAddress) {
  103. if (preg_match('/[^\x00-\x20()<>@,;:\\".[\]\x7f-\xff]+(?:\.[^\x00-\x20()<>@,;:\\".[\]\x7f-\xff]+)*\@[^\x00-\x20()<>@,;:\\".[\]\x7f-\xff]+(?:\.[^\x00-\x20()<>@,;:\\".[\]\x7f-\xff]+)+/i', $emailAddress)){
  104. $emailArray = explode("@",$emailAddress);
  105. if (checkdnsrr($emailArray[1])){
  106. return TRUE;
  107. }
  108. }
  109. return false;
  110. }
  111.  
  112. function processForm() {
  113.  
  114. // check data
  115. if ( !$_POST['name'] ) $this->error .= 'Please enter your name<br />';
  116. if ( !$this->checkEmail( $_POST['email'] ) ) $this->error .= 'Please enter a valid email address<br />';
  117. if ( !$_POST['message'] ) $this->error .= 'Please enter a message<br />';
  118.  
  119. if ( !$this->error ) $this->sendFormEmail();
  120. }
  121.  
  122. function sendFormEmail() {
  123. $message = "Name: " . stripslashes($_POST['name']) .
  124. "\nEmail: " . $_POST['email'] .
  125. "\n\nMessage: " . stripslashes($_POST['message']);
  126.  
  127. if ( $_POST['ajaxForm'] ) $message .= "\n\nFrom a Contact-Pop Form on page: " . $_SERVER["HTTP_REFERER"];
  128. else $message .= "\n\nReferrer: " . $_POST['httpReferer'];
  129.  
  130. $message .= "\n\nBrowser Info: " . $_SERVER["HTTP_USER_AGENT"] .
  131. "\nIP: " . $_SERVER["REMOTE_ADDR"] .
  132. "\n\nDate: " . date("Y-m-d h:i:s");
  133.  
  134. mail($this->sendto, $this->emailTitle, $message, 'From: ' . $_POST['name'] . ' <' . $_POST['email'] . '>');
  135. }
  136. }
  137.  
  138. $contactPop = new ContactPop();
  139.  
  140. if (isset($_POST['httpReferer'])) $contactPop->processForm();
  141.  
  142. // echo the ajax version of the form
  143. if ( isset($_REQUEST['ajaxForm']) && $_REQUEST['ajaxForm']) {
  144. echo $contactPop->getFormHtml(1);
  145. }
  146. // or echo the full page version of the form
  147. else {
  148.  
  149. ?>
  150.  
  151. <?=$contactPop->getFormHtml(); ?>
  152.  
  153. <?php
  154. }
  155. ?>
Add Comment
Please, Sign In to add comment