Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: [PHP] Brak polskich znaków w wiadomości
Forum PHP.pl > Forum > Przedszkole
d0m1n1k_
Witam,

zgodnie z tym co znalazłem na forum, poprawiłem skrypt mailowy (dodałem Content-type: text/html; charset=UTF-8)

  1. <?
  2.  
  3. // Replace this with your own email address
  4. $to="dominik@adddd.pl";
  5.  
  6. // Extract form contents
  7. $name = $_POST['name'];
  8. $email = $_POST['email'];
  9. $website = $_POST['website'];
  10. $subject = $_POST['subject'];
  11. $message = $_POST['message'];
  12.  
  13. // Validate email address
  14. function valid_email($str) {
  15. return ( ! preg_match("/^([a-z0-9\+_\-]+)(\.[a-z0-9\+_\-]+)*@([a-z0-9\-]+\.)+[a-z]{2,6}$/ix", $str)) ? FALSE : TRUE;
  16. }
  17.  
  18. // Return errors if present
  19. $errors = "";
  20.  
  21. if($name =='') { $errors .= "name,"; }
  22. if(valid_email($email)==FALSE) { $errors .= "email,"; }
  23. if($message =='') { $errors .= "message,"; }
  24.  
  25. // Send email
  26. if($errors =='') {
  27.  
  28. $headers = "Content-type: text/html; charset=UTF-8 \r\n";
  29. $headers = 'Od: add <no-reply@add.com>'. "\r\n" .
  30. 'Reply-To: '.$email.'' . "\r\n" .
  31. 'X-Mailer: PHP/' . phpversion();
  32. $email_subject = "Website Contact Form: $email";
  33. $message="Wiadomosc od: $name \n\nEmail: $email \n\nWebsite: $website \n\nSubject: $subject \n\nMessage:\n\n $message";
  34.  
  35. mail($to, $email_subject, $message, $headers);
  36. echo "true";
  37.  
  38. } else {
  39. echo $errors;
  40. }
  41.  
  42. ?>



Tak czy tak, nadal niema polskich znaków tylko krzaczki i kwadraty.
Z góry dziękuję za pomoc smile.gif
Tomplus
Sprawdź w jakim kodowaniu jest wysyłana treść, pewnie nie jest to UTF-8, a jak coś możesz z konwertować tekst przy użyciu: iconv

d0m1n1k_
Poradziłem sobie.
Zmieniłem kolejność i zapisałem content w jednej $headers

  1. <?
  2.  
  3. // Replace this with your own email address
  4. $to="dominik@composix.pl";
  5.  
  6. // Extract form contents
  7. $name = $_POST['name'];
  8. $email = $_POST['email'];
  9. $website = $_POST['website'];
  10. $subject = $_POST['subject'];
  11. $message = $_POST['message'];
  12.  
  13. // Validate email address
  14. function valid_email($str) {
  15. return ( ! preg_match("/^([a-z0-9\+_\-]+)(\.[a-z0-9\+_\-]+)*@([a-z0-9\-]+\.)+[a-z]{2,6}$/ix", $str)) ? FALSE : TRUE;
  16. }
  17.  
  18. // Return errors if present
  19. $errors = "";
  20.  
  21. if($name =='') { $errors .= "name,"; }
  22. if(valid_email($email)==FALSE) { $errors .= "email,"; }
  23. if($message =='') { $errors .= "message,"; }
  24.  
  25. // Send email
  26. if($errors =='') {
  27.  
  28. $headers = 'Od: FluidApp <no-reply@fluidapp.com>'. "\r\n" .
  29. 'Content-type: text/html; charset=UTF-8'. "\r\n".
  30. 'Reply-To: '.$email.'' . "\r\n" .
  31. 'X-Mailer: PHP/' . phpversion();
  32. $email_subject = "Website Contact Form: $email";
  33. $message="Wiadomosc od: $name \n\nEmail: $email \n\nWebsite: $website \n\nSubject: $subject \n\nMessage:\n\n $message";
  34.  
  35. mail($to, $email_subject, $message, $headers);
  36. echo "true";
  37.  
  38. } else {
  39. echo $errors;
  40. }
  41.  
  42. ?>
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.