Advertisement
Guest User

Contact_me php und js

a guest
Sep 7th, 2016
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.28 KB | None | 0 0
  1. CONTACT_ME.php
  2.  
  3. <?php
  4. // Check for empty fields
  5. if(empty($_POST['name']) ||
  6. empty($_POST['email']) ||
  7. empty($_POST['phone']) ||
  8. empty($_POST['message']) ||
  9. !filter_var($_POST['email'],FILTER_VALIDATE_EMAIL))
  10. {
  11. echo "No arguments Provided!";
  12. return false;
  13. }
  14.  
  15. $name = strip_tags(htmlspecialchars($_POST['name']));
  16. $email_address = strip_tags(htmlspecialchars($_POST['email']));
  17. $phone = strip_tags(htmlspecialchars($_POST['phone']));
  18. $message = strip_tags(htmlspecialchars($_POST['message']));
  19.  
  20. // Create the email and send the message
  21. $to = 'unrundead-designs@majesticpredators.de'; // Add your email address inbetween the '' replacing yourname@yourdomain.com - This is where the form will send a message to.
  22. $email_subject = "Website Contact Form: $name";
  23. $email_body = "You have received a new message from your website contact form.\n\n"."Here are the details:\n\nName: $name\n\nEmail: $email_address\n\nPhone: $phone\n\nMessage:\n$message";
  24. $headers = "From: noreply@majesticpredators.de\n"; // This is the email address the generated message will be from. We recommend using something like noreply@yourdomain.com.
  25. $headers .= "Reply-To: $email_address";
  26. mail($to,$email_subject,$email_body,$headers);
  27. return true;
  28. ?>
  29. -------
  30. -------
  31. -------
  32. CONTACT_ME.js
  33.  
  34. // Contact Form Scripts
  35.  
  36. $(function() {
  37.  
  38. $("#contactForm input,#contactForm textarea").jqBootstrapValidation({
  39. preventSubmit: true,
  40. submitError: function($form, event, errors) {
  41. // additional error messages or events
  42. },
  43. submitSuccess: function($form, event) {
  44. event.preventDefault(); // prevent default submit behaviour
  45. // get values from FORM
  46. var name = $("input#name").val();
  47. var email = $("input#email").val();
  48. var phone = $("input#phone").val();
  49. var message = $("textarea#message").val();
  50. var firstName = name; // For Success/Failure Message
  51. // Check for white space in name for Success/Fail message
  52. if (firstName.indexOf(' ') >= 0) {
  53. firstName = name.split(' ').slice(0, -1).join(' ');
  54. }
  55. $.ajax({
  56. url: "././mail/contact_me.php",
  57. type: "POST",
  58. data: {
  59. name: name,
  60. phone: phone,
  61. email: email,
  62. message: message
  63. },
  64. cache: false,
  65. success: function() {
  66. // Success message
  67. $('#success').html("<div class='alert alert-success'>");
  68. $('#success > .alert-success').html("<button type='button' class='close' data-dismiss='alert' aria-hidden='true'>&times;")
  69. .append("</button>");
  70. $('#success > .alert-success')
  71. .append("<strong>Your message has been sent. </strong>");
  72. $('#success > .alert-success')
  73. .append('</div>');
  74.  
  75. //clear all fields
  76. $('#contactForm').trigger("reset");
  77. },
  78. error: function() {
  79. // Fail message
  80. $('#success').html("<div class='alert alert-danger'>");
  81. $('#success > .alert-danger').html("<button type='button' class='close' data-dismiss='alert' aria-hidden='true'>&times;")
  82. .append("</button>");
  83. $('#success > .alert-danger').append("<strong>Es tut mir Leid " + firstName + ", Zurzeit ist der Server für die Emails nicht Verbunden. Wir Arbeiten dran! Probier es in 2 Stunden nochmal");
  84. $('#success > .alert-danger').append('</div>');
  85. //clear all fields
  86. $('#contactForm').trigger("reset");
  87. },
  88. });
  89. },
  90. filter: function() {
  91. return $(this).is(":visible");
  92. },
  93. });
  94.  
  95. $("a[data-toggle=\"tab\"]").click(function(e) {
  96. e.preventDefault();
  97. $(this).tab("show");
  98. });
  99. });
  100.  
  101.  
  102. /*When clicking on Full hide fail/success boxes */
  103. $('#name').focus(function() {
  104. $('#success').html('');
  105. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement