Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [PHP][JavaScript]Formularz kontaktowy – polskie kodowanie utf-8
preibx
post
Post #1





Grupa: Zarejestrowani
Postów: 18
Pomógł: 0
Dołączył: 25.09.2006

Ostrzeżenie: (0%)
-----


Witam.
Proszę o pomoc w uzupełnieniu poniższego skryptu o wysyłanie listów z polskimi znakami.
Z góry serdecznie dziękuje.
Plik contact.php
  1. <?php
  2. $to = "adres@firma.pl";
  3. $subject = "List wysłany z formularza";
  4.  
  5. if (isset($_POST["name"]) && isset($_POST["email"]) && isset($_POST["message"])) {
  6.  
  7. $content = "Nazywam się: " . $_POST["name"] . "\r\n";
  8. $content .= "Mój adres email: " . $_POST["email"] . "\r\n";
  9. $content .= "Treść wiadomości " . "\r\n" . $_POST["message"];
  10.  
  11. if (mail($to, $subject, $content, $_POST["email"])) {
  12.  
  13. $result = array(
  14. "message" => "Listy wysłany.",
  15. "sendstatus" => 1
  16. );
  17.  
  18. echo json_encode($result);
  19.  
  20. } else {
  21.  
  22. $result = array(
  23. "message" => "Niestety, coś jest nie tak.",
  24. "sendstatus" => 0
  25. );
  26.  
  27. echo json_encode($result);
  28.  
  29. }
  30.  
  31. }
  32.  
  33. ?>

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.  
  17. var submit = $('#contact-form submit');
  18. var ajaxResponse = $('#contact-response');
  19.  
  20. var name = $("input#cname").val();
  21. var email = $("input#cemail").val();
  22. var message = $("textarea#cmessage").val();
  23.  
  24. $.ajax({
  25. type: 'POST',
  26. url: 'assets/php/contact.php',
  27. dataType: 'json',
  28. data: {
  29. name: name,
  30. email: email,
  31. message: message,
  32. },
  33. cache: false,
  34. beforeSend: function(result) {
  35. submit.empty();
  36. submit.append('<i class="fa fa-cog fa-spin"></i> Wait...');
  37. },
  38. success: function(result) {
  39. if(result.sendstatus == 1) {
  40. ajaxResponse.html(result.message);
  41. $form.fadeOut(500);
  42. } else {
  43. ajaxResponse.html(result.message);
  44. }
  45. }
  46. });
  47. }
  48. });
  49.  
  50. });
  51.  
  52. })(jQuery);

Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 23.08.2025 - 15:50