Witam.
Nie mogę zmusić poniższego skryptu do wyświetlania treści wiadomości z poprawnymi polskimi znakami utf-8
Wydaje mi się, że chodzi o złe kodowanie AJAXU.
Proszę o pomoc i z góry sedecznie dziękuje.
Plik contact.js
  1. (function($){
  2.  
  3. $(document).ready(function() {
  4.  
  5. /* ---------------------------------------------- /*
  6. * Contact form ajax
  7. /* ---------------------------------------------- */
  8.  
  9. $('#contact-form').find('input,textarea').jqBootstrapValidation({
  10. preventSubmit: true,
  11. submitError: function($form, event, errors) {
  12. // additional error messages or events
  13. },
  14. submitSuccess: function($form, event) {
  15. event.preventDefault();
  16. // encoding:"UTF-8",
  17. // dataType:"html",
  18. // contentType: "text/plain; charset=UTF-8",
  19.  
  20. // dataType:"html", contentType: "text/plain; charset=UTF-8" } )
  21. var submit = $('#contact-form submit');
  22. var ajaxResponse = $('#contact-response');
  23.  
  24. var name = $("input#cname").val();
  25. var email = $("input#cemail").val();
  26. var message = $("textarea#cmessage").val();
  27.  
  28. $.ajax({
  29. type: 'POST',
  30. url: 'assets/php/contact.php',
  31. // contentType: "application/json; charset=utf-8",
  32. dataType: 'json',
  33. data: {
  34. name: name,
  35. email: email,
  36. message: message,
  37. },
  38. cache: false,
  39. beforeSend: function(result) {
  40. submit.empty();
  41. submit.append('<i class="fa fa-cog fa-spin"></i> Wait...');
  42. },
  43. success: function(result) {
  44. if(result.sendstatus == 1) {
  45. ajaxResponse.html(result.message);
  46. $form.fadeOut(500);
  47. } else {
  48. ajaxResponse.html(result.message);
  49. }
  50. }
  51. });
  52. }
  53. });
  54.  
  55. });
  56.  
  57. })(jQuery);

Plik contact.php
  1. <?php
  2. $subject = "=?UTF-8?B?".base64_encode("Wiadomość z mojej witryny od ".$_POST['name'])."?=";
  3. $naglowki ="From: name <email>\r\n".
  4. "MIME-Version: 1.0" . "\r\n" .
  5. "Content-type: text/html; charset=UTF-8" . "\r\n";
  6. $to = "adres@firma.pl";
  7. if (isset($_POST["name"]) && isset($_POST["email"]) && isset($_POST["message"])) {
  8. $content = "Nazywam sie: " . $_POST["name"] . "\r\n";
  9. $content .= "Moj adres email: " . $_POST["email"] . "\r\n";
  10. $content .= "Wiadomosc: " . "\r\n" . $_POST["message"];
  11. if (mail($to, $subject, $content, $_POST["email"], $naglowki)) {
  12. $result = array(
  13. "message" => "Listy wysłany.",
  14. "sendstatus" => 1
  15. );
  16. echo json_encode($result);
  17. } else {
  18.  
  19. $result = array(
  20. "message" => "Niestety, coś jest nie tak.",
  21. "sendstatus" => 0
  22. );
  23. echo json_encode($result);
  24. }
  25. }
  26. ?>