Advertisement
Guest User

Untitled

a guest
Dec 10th, 2011
252
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.64 KB | None | 0 0
  1. <?php
  2. /* Set e-mail recipient */
  3. $myemail = "hot_dog_36@hotmail.com";
  4.  
  5. /* Check all form inputs using check_input function */
  6. $yourname = check_input($_POST['yourname'], "Enter your name");
  7. $subject = check_input($_POST['subject'], "Write a subject");
  8. $email = check_input($_POST['email']);
  9. $website = check_input($_POST['website']);
  10. $likeit = check_input($_POST['likeit']);
  11. $how_find = check_input($_POST['how']);
  12. $comments = check_input($_POST['comments'], "Write your comments");
  13. $message = "Hello!
  14.  
  15. Your contact form has been submitted by:
  16.  
  17. Name: $yourname
  18. E-mail: $email
  19. URL: $website
  20.  
  21. Like the website? $likeit
  22. How did he/she find it? $how_find
  23.  
  24. Comments:
  25. $comments
  26.  
  27. End of message
  28. ";
  29.  
  30. /* If e-mail is not valid show error message */
  31. if (!preg_match("/([\w\-]+\@[\w\-]+\.[\w\-]+)/", $email))
  32. {
  33. show_error("E-mail address not valid");
  34. }
  35.  
  36. /* If URL is not valid set $website to empty */
  37. if (!preg_match("/^(https?:\/\/+[\w\-]+\.[\w\-]+)/i", $website))
  38. {
  39. $website = '';
  40. }
  41.  
  42. /* Send the message using mail() function */
  43. mail($myemail, $subject, $message);
  44.  
  45. /* Redirect visitor to the thank you page */
  46. header('Location: thanks.htm');
  47. exit();
  48.  
  49. /* Functions we used */
  50. function check_input($data, $problem='')
  51. {
  52. $data = trim($data);
  53. $data = stripslashes($data);
  54. $data = htmlspecialchars($data);
  55. if ($problem && strlen($data) == 0)
  56. {
  57. show_error($problem);
  58. }
  59. return $data;
  60. }
  61.  
  62. function show_error($myError)
  63. {
  64. ?>
  65.  
  66. <html>
  67. <body>
  68. <b>Please correct the following error:</b><br />
  69. <?php echo $myError; ?>
  70. </body>
  71. </html>
  72.  
  73. <?php
  74. exit();
  75. }
  76. ?>
  77.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement