Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2014
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.03 KB | None | 0 0
  1.  
  2. js.js
  3. $('#cform').submit(function(e) {
  4. e.preventDefault();
  5.  
  6. $.ajax({
  7. type: 'POST',
  8. url:'send.php',
  9. data: $('#cform').serialize()
  10. }).
  11. done(function(res) {
  12. $('#errors').bPopup();
  13. $('#errors p').html(res);
  14. $('#cform').val('');
  15.  
  16. }).
  17. fail(function(err) {
  18. $('#errors').bPopup();
  19. $('#errors p').html(err.responseText);
  20. $(".b-close").bPopup().close();
  21.  
  22. });
  23. });
  24. });
  25.  
  26.  
  27. send.php
  28.  
  29. <?php
  30.  
  31. if(isset($_POST['email'])) {
  32.  
  33. $email_to = "dthomasn@gmail.com";
  34. $email_subject = "VERY";
  35.  
  36. function died($error) {
  37. echo "<h1>I am truly sorry, but there appear to be a problem with the information you tried to submit. ";
  38.  
  39. echo "These errors appear below.</h1><p><br /><br />";
  40. echo $error."<br /><br /></p>";
  41. die();
  42. }
  43. if(!isset($_POST['name']) ||
  44. !isset($_POST['email']) ||
  45. !isset($_POST['subject']) ||
  46. !isset($_POST['human']) ||
  47. !isset($_POST['comments'])) {
  48. died('I am truly sorry, but there appears to be a problem with the information you tried to submit.');
  49. }
  50. $name = $_POST['name']; // required
  51. $email_from = $_POST['email']; // required
  52. $subject = $_POST['subject']; // required
  53. $human = $_POST['human']; // not required
  54. $comments = $_POST['comments']; // required
  55.  
  56.  
  57. $error_message = "";
  58. $email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
  59. if(!preg_match($email_exp,$email_from)) {
  60. $error_message .= 'The Email Address you entered was not an email.<br />';
  61. }
  62. $string_exp = "/^[A-Za-z .'-]+$/";
  63. if(!preg_match($string_exp,$name)) {
  64. $error_message .= 'The Name you entered is not a valid name.<br />';
  65. }
  66. if(strlen($subject) < 2) {
  67. $error_message .= 'The Comments you entered do not appear to be valid.<br />';
  68. }
  69. if($human != 10) {
  70. $error_message .= 'Human? Sry but 8ight+2wo is 10 no space for you here robo!<br />';
  71. }
  72. if(strlen($comments) < 2) {
  73. $error_message .= 'The Comments you entered do not appear to be valid.<br />';
  74. }
  75. if(strlen($error_message) > 0) {
  76. died($error_message);
  77. }
  78. $email_message = "Form details below.\n\n";
  79.  
  80.  
  81. function clean_string($string) {
  82. $bad = array("content-type","bcc:","to:","cc:","href");
  83. return str_replace($bad,"",$string);
  84.  
  85. }
  86.  
  87. $email_message .= "Name: ".clean_string($name)."\n";
  88. $email_message .= "Email: ".clean_string($email_from)."\n";
  89. $email_message .= "Subject: ".clean_string($subject)."\n";
  90. $email_message .= "Comments: ".clean_string($comments)."\n";
  91.  
  92. // create email headers
  93.  
  94. $headers = 'From: '.$email_from."\r\n".
  95.  
  96. 'Reply-To: '.$email_from."\r\n" .
  97.  
  98. 'X-Mailer: PHP/' . phpversion();
  99.  
  100. @mail($email_to, $email_subject, $email_message, $headers);
  101.  
  102. ?>
  103. <p class="correct">Thank you for contacting me. We will be in touch very soon.</p>
  104. <?php
  105.  
  106. }
  107.  
  108. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement