Advertisement
Guest User

Untitled

a guest
Mar 23rd, 2014
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.05 KB | None | 0 0
  1. <?php
  2.  
  3. function test_input($data){
  4.  
  5. $data = trim($data);
  6. $data = stripslashes($data);
  7. $data = htmlspecialchars($data);
  8.  
  9. return $data;
  10. }
  11.  
  12. function clean_string($string) {
  13.  
  14. $bad = array("content-type","bcc:","to:","cc:","href");
  15. return str_replace($bad,"",$string);
  16.  
  17. }
  18.  
  19.  
  20. // define variables and set to empty values
  21. $first_nameErr = $last_nameErr = $emailErr = $overviewErr = "";
  22. $first_name = $last_name = $email = $overview = "";
  23.  
  24. if(isset($_POST['email'])) {
  25.  
  26. $email_to = "myself@mydomain.com";
  27. $email_subject = "Contact us - My company's name";
  28. {
  29.  
  30. if (empty($_POST["first_name"]))
  31. {$first_nameErr = "(First Name is required)";}
  32.  
  33. else
  34. {$first_name = test_input($_POST["first_name"]);
  35.  
  36. // check if name only contains letters and whitespace
  37. if (!preg_match("/^[a-zA-Z ]*$/",$first_name))
  38. {
  39. $first_name = "(Only letters and white space allowed)";
  40. }
  41. }
  42.  
  43. if (empty($_POST["last_name"]))
  44. {$last_nameErr = "(Last Name is required)";}
  45.  
  46. else
  47. {$last_name = test_input($_POST["last_name"]);
  48.  
  49. // check if name only contains letters and whitespace
  50. if (!preg_match("/^[a-zA-Z ]*$/",$last_name))
  51. {
  52. $last_name = "(Only letters and white space allowed)";
  53. }
  54. }
  55.  
  56. if (empty($_POST["email"]))
  57. {$emailErr = "(Email ID is required)";}
  58.  
  59. else
  60. {$email = test_input($_POST["email"]);
  61.  
  62. // check if e-mail address syntax is valid
  63. if (!preg_match("/([w-]+@[w-]+.[w-]+)/",$email))
  64. {
  65. $emailErr = "(Invalid email format)";
  66. }
  67. }
  68.  
  69. if (empty($_POST["overview"]))
  70. {$overviewErr = "(Overview is required)";}
  71.  
  72. else
  73. {$overview = test_input($_POST["overview"]);
  74.  
  75. // check if name only contains letters and whitespace
  76. if (!preg_match("/^[a-zA-Z ]*$/",$overview))
  77. {
  78. $overview = "(Only letters and white space allowed)";
  79. }
  80. }
  81.  
  82. }
  83.  
  84. //Email & SEND INFO
  85. $email_message = "Form details below.nn";
  86.  
  87. $email_message .= "First Name: ".clean_string($first_name)."n";
  88.  
  89. $email_message .= "Last Name: ".clean_string($last_name)."n";
  90.  
  91. $email_message .= "Email: ".clean_string($email)."n";
  92.  
  93. $email_message .= "Services: ".clean_string(implode(', ', $service))."n";
  94.  
  95. $email_message .= "Overview: ".clean_string($overview)."n";
  96.  
  97.  
  98.  
  99.  
  100.  
  101. // create email headers
  102.  
  103. $headers = 'From: '.$email_from."rn".
  104.  
  105. 'Reply-To: '.$email_from."rn" .
  106.  
  107. 'X-Mailer: PHP/' . phpversion();
  108.  
  109. mail($email_to, $email_subject, $email_message, $headers);
  110.  
  111. ?>
  112.  
  113.  
  114.  
  115. <!-- Success HTML -->
  116.  
  117. Thank you for contacting us. We will be in touch with you very soon.
  118.  
  119. <?php
  120.  
  121. }
  122.  
  123. ?>
  124.  
  125. <?php
  126.  
  127. function test_input($data) {
  128. $data = trim($data);
  129. $data = stripslashes($data);
  130. $data = htmlspecialchars($data);
  131. return $data;
  132. }
  133.  
  134. function clean_string($string) {
  135. $bad = array("content-type","bcc:","to:","cc:","href");
  136. return str_replace($bad,"",$string);
  137. }
  138.  
  139. // define variables and set to empty values
  140. $first_nameErr = $last_nameErr = $emailErr = $overviewErr = "";
  141. $first_name = $last_name = $email = $overview = "";
  142.  
  143. if(isset($_POST['email'])) {
  144. $email_to = "myself@mydomain.com";
  145. $email_subject = "Contact us - My company's name";
  146. }
  147.  
  148. if (empty($_POST["first_name"])) {
  149. $first_nameErr = "(First Name is required)";
  150. } else {
  151. $first_name = test_input($_POST["first_name"]);
  152. }
  153.  
  154. // check if name only contains letters and whitespace
  155. if (!preg_match("/^[a-zA-Z ]*$/",$first_name)) {
  156. $first_name = "(Only letters and white space allowed)";
  157. }
  158.  
  159. if (empty($_POST["last_name"])) {
  160. $last_nameErr = "(Last Name is required)";
  161. } else {
  162. $last_name = test_input($_POST["last_name"]);
  163. }
  164.  
  165. // check if name only contains letters and whitespace
  166. if (!preg_match("/^[a-zA-Z ]*$/",$last_name)) {
  167. $last_name = "(Only letters and white space allowed)";
  168. }
  169.  
  170. if (empty($_POST["email"])) {
  171. $emailErr = "(Email ID is required)";
  172. } else {
  173. $email = test_input($_POST["email"]);
  174. }
  175.  
  176. // check if e-mail address syntax is valid
  177. if (!preg_match("/([w-]+@[w-]+.[w-]+)/",$email)) {
  178. $emailErr = "(Invalid email format)";
  179. }
  180.  
  181. if (empty($_POST["overview"])) {
  182. $overviewErr = "(Overview is required)";
  183. } else {
  184. $overview = test_input($_POST["overview"]);
  185. }
  186.  
  187. // check if name only contains letters and whitespace
  188. if (!preg_match("/^[a-zA-Z ]*$/",$overview)) {
  189. $overview = "(Only letters and white space allowed)";
  190. }
  191.  
  192.  
  193. //Email & SEND INFO
  194. $email_message = "Form details below.nn";
  195. $email_message .= "First Name: ".clean_string($first_name)."n";
  196. $email_message .= "Last Name: ".clean_string($last_name)."n";
  197. $email_message .= "Email: ".clean_string($email)."n";
  198. $email_message .= "Services: ".clean_string(implode(', ', $service))."n";
  199. $email_message .= "Overview: ".clean_string($overview)."n";
  200.  
  201.  
  202. // create email headers
  203. $headers = 'From: '.$email_from."rn".
  204. 'Reply-To: '.$email_from."rn" .
  205. 'X-Mailer: PHP/' . phpversion();
  206.  
  207. mail($email_to, $email_subject, $email_message, $headers);
  208.  
  209.  
  210. if ($first_nameErr || $last_nameErr || $emailErr || $overviewErr) {
  211. echo "Thank you for contacting us. We will be in touch with you very soon.";
  212. } else {
  213. echo "There are some errors in your form: " . $first_nameErr . ', ' . $last_nameErr . ', ' . $emailErr . ', ' . $overviewErr;
  214. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement