Advertisement
Guest User

Untitled

a guest
Sep 25th, 2015
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.35 KB | None | 0 0
  1. $("#send-mail").click(function () {
  2.  
  3. var name = $('input#name').val(); // get the value of the input field
  4. var error = false;
  5. if (name == "" || name == " ") {
  6. $('#err-name').show(500);
  7. $('#err-name').delay(4000);
  8. $('#err-name').animate({
  9. height: 'toggle'
  10. }, 500, function () {
  11. // Animation complete.
  12. });
  13. error = true; // change the error state to true
  14. }
  15.  
  16. var emailCompare = /^([a-z0-9_.-]+)@([da-z.-]+).([a-z.]{2,6})$/; // Syntax to compare against input
  17. var email = $('input#email').val().toLowerCase(); // get the value of the input field
  18. if (email == "" || email == " " || !emailCompare.test(email)) {
  19. $('#err-email').show(500);
  20. $('#err-email').delay(4000);
  21. $('#err-email').animate({
  22. height: 'toggle'
  23. }, 500, function () {
  24. // Animation complete.
  25. });
  26. error = true; // change the error state to true
  27. }
  28.  
  29.  
  30. var comment = $('textarea#comment').val(); // get the value of the input field
  31. if (comment == "" || comment == " ") {
  32. $('#err-comment').show(500);
  33. $('#err-comment').delay(4000);
  34. $('#err-comment').animate({
  35. height: 'toggle'
  36. }, 500, function () {
  37. // Animation complete.
  38. });
  39. error = true; // change the error state to true
  40. }
  41.  
  42. if (error == false) {
  43. var dataString = $('#contact-form').serialize(); // Collect data from form
  44. $.ajax({
  45. url: $('#contact-form').attr('action'),
  46. type: "POST",
  47. data: dataString,
  48. timeout: 6000,
  49. error: function (request, error) {
  50.  
  51. },
  52. success: function (response) {
  53. response = $.parseJSON(response);
  54. if (response.success) {
  55. $('#successSend').show();
  56. $("#name").val('');
  57. $("#email").val('');
  58. $("#comment").val('');
  59. } else {
  60. $('#errorSend').show();
  61. }
  62. }
  63. });
  64. return false;
  65. }
  66.  
  67. return false; // stops user browser being directed to the php file
  68. });
  69.  
  70. <?php
  71.  
  72. include 'functions.php';
  73.  
  74. if (!empty($_POST)){
  75.  
  76. $data['success'] = true;
  77. $_POST = multiDimensionalArrayMap('cleanEvilTags', $_POST);
  78. $_POST = multiDimensionalArrayMap('cleanData', $_POST);
  79.  
  80. //your email adress
  81. $emailTo ="viacon@hotmail.com"; //"yourmail@yoursite.com";
  82.  
  83. //from email adress
  84. $emailFrom ="contact@yoursite.com"; //"contact@yoursite.com";
  85.  
  86. //email subject
  87. $emailSubject = "contacto teklife";
  88.  
  89. $name = $_POST["name"];
  90. $email = $_POST["email"];
  91. $comment = $_POST["comment"];
  92. if($name == "")
  93. $data['success'] = false;
  94.  
  95. if (!preg_match("/^[_.0-9a-zA-Z-]+@([0-9a-zA-Z][0-9a-zA-Z-]+.)+[a-zA-Z]{2,6}$/i", $email))
  96. $data['success'] = false;
  97.  
  98.  
  99. if($comment == "")
  100. $data['success'] = false;
  101.  
  102. if($data['success'] == true){
  103.  
  104. $message = "NAME: $name<br>
  105. EMAIL: $email<br>
  106. COMMENT: $comment";
  107.  
  108.  
  109. $headers = "MIME-Version: 1.0" . "rn";
  110. $headers .= "Content-type:text/html; charset=utf-8" . "rn";
  111. $headers = 'From: TEKLIFE <jsparrow@blackpearl.com>' . PHP_EOL .
  112. $headers .= "Reply-to: <$email>".
  113. 'X-Mailer: PHP/' . phpversion();
  114.  
  115.  
  116. mail($emailTo, $emailSubject, $message, $headers);
  117.  
  118. $data['success'] = true;
  119. echo json_encode($data);
  120. }
  121. }
  122.  
  123. <div id="successSend" class="alert alert-success invisible">
  124. <strong>Well done!</strong>Your message has been sent.</div>
  125. <div id="errorSend" class="alert alert-error invisible">There was an error.</div>
  126. <form id="contact-form" method="post" action="http://guara.webposicionamientoweb.com.mx/pluton/php/mail.php">
  127. <div class="control-group">
  128. <div class="controls">
  129. <input class="span12" type="text" id="name" name="name" placeholder="* Your name..." />
  130. <div class="error left-align" id="err-name">Please enter name.</div>
  131. </div>
  132. </div>
  133. <div class="control-group">
  134. <div class="controls">
  135. <input class="span12" type="email" name="email" id="email" placeholder="* Your email..." />
  136. <div class="error left-align" id="err-email">Please enter valid email adress.</div>
  137. </div>
  138. </div>
  139. <div class="control-group">
  140. <div class="controls">
  141. <textarea class="span12" name="comment" id="comment" placeholder="* Comments..."></textarea>
  142. <div class="error left-align" id="err-comment">Please enter your comment.</div>
  143. </div>
  144. </div>
  145. <div class="control-group">
  146. <div class="controls">
  147. <button id="send-mail" class="message-btn">Send message</button>
  148. </div>
  149. </div>
  150. </form>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement