Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [PHP]Formularz, brak polskich znaków, (znowu ten temat, ale nic nie pomaga)
julss
post 29.10.2012, 16:06:09
Post #1





Grupa: Zarejestrowani
Postów: 13
Pomógł: 0
Dołączył: 17.10.2006

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


Wiem że 100 razy był ten temat.
Ale żadne dodawania "$headers .= 'Content-Transfer-Encoding: 8bit'. "\n\r\n";0" nie pomaga...
Na wszystkie maile przychodzi wiadomość z polskimi znakami, tylko na poczta.home.pl przychodzą krzaki...
Spójrzcie proszę na mój kod...

  1. <?php session_start(); ?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  5.  
  6. <?php
  7.  
  8. if(isset($_POST['email'])) {
  9.  
  10. $email_to = "moj@email";
  11. $email_subject = "Tytul Maila";
  12.  
  13. function died($error) {
  14. // your error code can go here
  15. echo "We're sorry, but there's errors found with the form you submitted.<br />..Przykro nam, w wypełnionym formularzu pojawił się błąd.<br /><br />";
  16. echo $error."<br /><br />";
  17. echo "Please go back and fix these errors.<br />..Proszę wrócić i ponowie wypełnić formularz.<br />";
  18. die();
  19. }
  20.  
  21. // validation expected data exists
  22. if(!isset($_POST['name']) ||
  23. !isset($_POST['surname']) ||
  24. !isset($_POST['email']) ||
  25. !isset($_POST['occupation']) ||
  26. !isset($_POST['comments']) ||
  27. !isset($_POST['institution'])) {
  28. died('We are sorry, but there appears to be a problem with the form you submitted.<br />..Przykro nam, w wypełnionym formularzu pojawił się błąd.');
  29. }
  30.  
  31. $name = $_POST['name']; // required
  32. $surname = $_POST['surname']; // required
  33. $email_from = $_POST['email']; // required
  34. $occupation = $_POST['occupation']; // not required
  35. $institution = $_POST['institution']; // not required
  36. $institution = $_POST['institution']; // not required
  37. $comments = $_POST['comments']; // not required
  38.  
  39.  
  40. $error_message = "";
  41. $email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
  42. if(!preg_match($email_exp,$email_from)) {
  43. $error_message .= 'The Email Address you entered does not appear to be valid.<br /> ..Podany adres mailowy jest błędny.<br />';
  44. }
  45. $string_exp = "/^[A-Za-ząćęłńóśźżĄĆĘŁŃÓŚŹŻ .'-]+$/";
  46. if(!preg_match($string_exp,$name)) {
  47. $error_message .= 'The First Name you entered does not appear to be valid.<br />..Imię jest błędne.<br />';
  48. }
  49. if(!preg_match($string_exp,$surname)) {
  50. $error_message .= 'The Last Name you entered does not appear to be valid.<br />..Nazwisko jest błędne.<br />';
  51. }
  52.  
  53. if(strlen($error_message) > 0) {
  54. died($error_message);
  55. }
  56. $email_message = "Form details below.\n\n";
  57.  
  58. function clean_string($string) {
  59. $bad = array("content-type","bcc:","to:","cc:","href");
  60. return str_replace($bad,"",$string);
  61. }
  62.  
  63.  
  64. $email_message .= "Name: ".clean_string($name)."\n";
  65. $email_message .= "Surname: ".clean_string($surname)."\n";
  66. $email_message .= "Email: ".clean_string($email_from)."\n";
  67. $email_message .= "Occupation: ".clean_string($occupation)."\n";
  68. $email_message .= "Institution: ".clean_string($institution)."\n";
  69. $email_message .= "Comment: ".clean_string($comments)."\n";
  70.  
  71. // create email headers
  72.  
  73. $headers = 'From: '.$email_from."\r\n".
  74. 'Reply-To: '.$email_from."\r\n" .
  75. 'X-Mailer: PHP/' . phpversion();
  76. @mail($email_to, $email_subject, $email_message, $headers);
  77.  
  78.  
  79. $headers .= 'MIME-Version: 1.0' ."\r\n";
  80. $headers .= 'Content-Type: text/HTML; charset=ISO-8859-1' . "\r\n";
  81. $headers .= 'Content-Transfer-Encoding: 8bit'. "\n\r\n";
  82. $headers .= $text . "\r\n";
  83.  
  84. ?>
  85.  
  86. <?php
  87. }
  88. die();
  89. ?>
  90.  
  91.  


Ten post edytował julss 29.10.2012, 16:07:44
Go to the top of the page
+Quote Post
misterious
post 29.10.2012, 17:03:25
Post #2





Grupa: Zarejestrowani
Postów: 52
Pomógł: 2
Dołączył: 7.10.2012

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


Pierwsze co mi na myśl wpadło - Jakie kodowanie masz ustawione w EDYTORZE?, nie w kodzie
Go to the top of the page
+Quote Post
julss
post 29.10.2012, 17:10:00
Post #3





Grupa: Zarejestrowani
Postów: 13
Pomógł: 0
Dołączył: 17.10.2006

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


Pisze w Dreamweaver.
Tam mam ustawione "Domyślne kodowanie: Unicode: UTF-8" i "Dołącz sygnaturę Unicode (BOM)"
Go to the top of the page
+Quote Post
Mega_88
post 29.10.2012, 17:33:20
Post #4





Grupa: Zarejestrowani
Postów: 360
Pomógł: 34
Dołączył: 20.08.2011

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


Proponuje Ci przerzucić się na PHP Mailer --> http://phpmailer.worxware.com/index.php?pg=phpmailer Sam do jakiegoś czasu korzystałem z PHPMail i zawsze był problem z polskimi znakami.
Klasa na początku może wydawać się cieżka do zrozumienia, ale poświęcisz 10 minut i na pewno sobie poradzisz z nią, a problem z polskimi znakami zniknie raz na zawsze smile.gif Zerknij bo naprawdę warto, a jak będziesz miał jakieś pytania to pisz na pewno ktoś Ci pomoże z PHPMailer bo odnośnie PHPMail i polskich znaków w temacie to wątpie żebyś znalazł rozwiązanie.
Go to the top of the page
+Quote Post
kayman
post 29.10.2012, 17:40:52
Post #5





Grupa: Zarejestrowani
Postów: 556
Pomógł: 40
Dołączył: 20.07.2012
Skąd: Warszawa

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


jak całość jest kodowana w UTF-8 to i to powinno być w UTF-8

  1. $headers .= 'Content-Type: text/HTML; charset=UTF-8' . "\r\n";

Go to the top of the page
+Quote Post
julss
post 29.10.2012, 17:44:05
Post #6





Grupa: Zarejestrowani
Postów: 13
Pomógł: 0
Dołączył: 17.10.2006

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


eh.. niestety, nie pomogło
Go to the top of the page
+Quote Post
kayman
post 29.10.2012, 17:56:01
Post #7





Grupa: Zarejestrowani
Postów: 556
Pomógł: 40
Dołączył: 20.07.2012
Skąd: Warszawa

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


masz mój formularz kontaktowy, kodowanie utf-8 i dokumentu i maila

  1. $header = 'From: '.$_POST['name'].' <'.$_POST['mail'].'>'.PHP_EOL;
  2. $header .= "MIME-Version: 1.0".PHP_EOL;
  3. $header .= "Content-type: text/html; charset=UTF-8".PHP_EOL;
  4.  
  5. $tresc = '<html><head><title>Wiadomość e-mail</title></head><body>';
  6. $tresc .='<p>Wiadomość od: '. $_POST['name']. ' <a href="mailto:'.$_POST['mail'].'">'.$_POST['mail'].'</a></p>';
  7. $tresc .='<p><b>Treść wiadomości:</b></p>';
  8. $tresc .='<p>'.nl2br($_POST['tresc']).'</p>';
  9. $tresc .='</body></html>';
  10.  
  11. $title = 'Wiadomośc ze strony '. $mojastrona. ' od ' . $_POST['name'];
  12.  
  13. $mymail = 'jakiś@mail.pl'
  14.  
  15. mail($mymail, $title, $tresc, $header)
  16.  
Go to the top of the page
+Quote Post

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

 



RSS Wersja Lo-Fi Aktualny czas: 23.04.2024 - 16:34