Advertisement
Guest User

Untitled

a guest
Jun 14th, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.25 KB | None | 0 0
  1. //////////////////////////////
  2. // front.js ///
  3. ////////////////////////////////
  4. function contactForm() {
  5. $("#contact-form").submit(function () {
  6.  
  7. var url = "contact.php"; // the script where you handle the form input.
  8.  
  9. $.ajax({
  10. type: "POST",
  11. url: url,
  12. data: $(this).serialize(), // serializes the form's elements.
  13. success: function (data)
  14. {
  15. var messageAlert = 'alert-' + data.type;
  16. var messageText = data;
  17. var alertBox = '<div class="alert ' + messageAlert + ' alert-dismissable animated bounceIn"><button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>' + messageText + '</div>';
  18. if (messageAlert!=0 && messageText!=0) {
  19. $('#contact-form').find('.messages').html(alertBox);
  20. }
  21. }
  22. });
  23. return false; // avoid to execute the actual submit of the form.
  24. });
  25. }
  26.  
  27. ////////////////////////////////
  28. // contact.php ///
  29. ////////////////////////////////
  30. <?php
  31.  
  32. /**
  33. * configure here
  34. */
  35. $from = $_POST['email'];
  36. $to = 'Szymon_Piszczatowski <piszczatowskiszymon@gmail.com>';
  37. $subject = 'Nowa wiadomość z portfolio';
  38. $fields = array('name' => 'Imie', 'surname' => 'Nazwisko', 'phone' => 'Telefon', 'email' => 'Email', 'message' => 'Wiadomość');
  39. $htmlHeader = '';
  40. $htmlFooter = '';
  41. $okMessage = 'Contact form succesfully submitted. Thank you, I will get back to you soon!';
  42. $htmlContent = '<h1>New message from contact form</h1>';
  43.  
  44.  
  45. /* DO NOT EDIT BELOW */
  46.  
  47. /* use classes */
  48.  
  49.  
  50.  
  51. $htmlContent .= '<table>';
  52. foreach ($_POST as $key => $value) {
  53.  
  54. if (isset($fields[$key])) {
  55. $htmlContent .= "<tr><th>$fields[$key]</th><td>$value</td></tr>";
  56. }
  57. }
  58. $htmlContent .= '</table>';
  59.  
  60. /* compose html body */
  61.  
  62. $htmlBody = $htmlHeader . $htmlContent . $htmlFooter;
  63.  
  64. $headers[] = 'MIME-Version: 1.0';
  65. $headers[] = 'Content-type: text/html; charset=iso-8859-1';
  66. $headers[] = 'To: Szymon Piszczatowski <piszczatowskiszymon@gmail.com>';
  67. $headers[] = 'From: piszczatowskiszymon.pl <piszczatowskiszymon@gmail.com>';
  68.  
  69. if(mail($to, $subject, $htmlBody, implode("\r\n", $headers))){
  70. echo( $okMessage);
  71. }else {
  72. header($_SERVER['SERVER_PROTOCOL'] . ' 401 Unauthorized', true, 401);
  73. die('401 Unauthorized');
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement