Advertisement
Guest User

Untitled

a guest
Nov 22nd, 2014
197
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.42 KB | None | 0 0
  1.  
  2.  
  3.  
  4. <?php
  5. /* Set e-mail recipient */
  6. $myemail = "gibekrecords@gmail.com";
  7.  
  8. /* Check all form inputs using check_input function */
  9. $name = check_input($_POST['inputName'], "Your Name");
  10. $email = check_input($_POST['inputEmail'], "Your E-mail Address");
  11. $subject = check_input($_POST['inputSubject'], "Message Subject");
  12. $message = check_input($_POST['inputMessage'], "Your Message");
  13.  
  14. /* If e-mail is not valid show error message */
  15. if (!preg_match("/([\w\-]+\@[\w\-]+\.[\w\-]+)/", $email))
  16. {
  17. show_error("Invalid e-mail address");
  18. }
  19. /* Let's prepare the message for the e-mail */
  20.  
  21. $subject = $email."Someone has sent you a message";
  22.  
  23. $message = "
  24.  
  25. Someone has sent you a message using your contac form:
  26.  
  27. Name: $name
  28. Email: $email
  29. Subject: $subject
  30.  
  31. Message:
  32.  
  33. $message
  34.  
  35. ";
  36.  
  37. /* Send the message using mail() function */
  38. mail($myemail, $subject, $message);
  39.  
  40. /* Redirect visitor to the thank you page */
  41. header('Location: alert-page.html');
  42. exit();
  43.  
  44. /* Functions we used */
  45. function check_input($data, $problem='')
  46. {
  47. $data = trim($data);
  48. $data = stripslashes($data);
  49. $data = htmlspecialchars($data);
  50. if ($problem && strlen($data) == 0)
  51. {
  52. show_error($problem);
  53. }
  54. return $data;
  55. }
  56.  
  57. function show_error($myError)
  58. {
  59. ?>
  60. <html>
  61. <body>
  62.  
  63. <p>Please correct the following error:</p>
  64. <strong><?php echo $myError; ?></strong>
  65. <p>Hit the back button and try again</p>
  66.  
  67. </body>
  68. </html>
  69. <?php
  70. exit();
  71. }
  72. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement