Advertisement
hidemystuff

contact.php

Jun 1st, 2015
258
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.04 KB | None | 0 0
  1. <?php
  2.  
  3. if(isset($_POST['email'])) {
  4. $email_to = "hidemystuff.com@gmail.com";
  5. $email_subject = "HideMyStuff contact msg";
  6. function died($error) {
  7. echo htmlspecialchars("There seems to be an error with what you've submitted...");
  8. echo htmlspecialchars($error."<br /><br />");
  9. die();
  10.  
  11. }
  12. if(!isset($_POST['name']) ||
  13. !isset($_POST['email']) ||
  14. !isset($_POST['comments'])) {
  15. died('It looks something isn't filled out...');
  16. }
  17. $name = $_POST['name']; // required
  18. $email_from = $_POST['email']; // required
  19. $comments = $_POST['comments']; // required
  20.  
  21.  
  22.  
  23. $error_message = "";
  24.  
  25. $email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
  26.  
  27. if(!preg_match($email_exp,$email_from)) {
  28.  
  29. $error_message .= 'The email address you entered does not appear to be valid.<br />';
  30.  
  31. }
  32.  
  33. $string_exp = "/^[A-Za-z .'-]+$/";
  34.  
  35. if(!preg_match($string_exp,$name)) {
  36.  
  37. $error_message .= 'The name you entered does not appear to be valid.<br />';
  38.  
  39. }
  40.  
  41. if(strlen($comments) < 2) {
  42.  
  43. $error_message .= 'The comments you entered do not appear to be valid.<br />';
  44.  
  45. }
  46.  
  47. if(strlen($error_message) > 0) {
  48.  
  49. died($error_message);
  50.  
  51. }
  52.  
  53. $email_message = "Form details below.\n\n";
  54.  
  55.  
  56.  
  57. function clean_string($string) {
  58.  
  59. $bad = array("content-type","bcc:","to:","cc:","href");
  60.  
  61. return str_replace($bad,"",$string);
  62.  
  63. }
  64.  
  65.  
  66.  
  67. $email_message .= "Name: ".clean_string($name)."\n";
  68.  
  69. $email_message .= "Email: ".clean_string($email_from)."\n";
  70.  
  71. $email_message .= "Comments: ".clean_string($comments)."\n";
  72.  
  73.  
  74.  
  75.  
  76.  
  77. // create email headers
  78.  
  79. $headers = 'From: '.$email_from."\r\n".
  80.  
  81. 'Reply-To: '.$email_from."\r\n" .
  82.  
  83. 'X-Mailer: PHP/' . phpversion();
  84.  
  85. @mail($email_to, $email_subject, $email_message, $headers);
  86.  
  87. ?>
  88.  
  89.  
  90.  
  91. echo htmlspecialchars("Message submitted! Thank you for contacting us.");
  92.  
  93.  
  94.  
  95. <?php
  96.  
  97. }
  98.  
  99. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement