Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> Problem z konwertowaniem UTF-8 na iso
Gadziu
post
Post #1





Grupa: Zarejestrowani
Postów: 49
Pomógł: 1
Dołączył: 13.08.2011

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


Witam,
mam taki problem. Na stronie mam formularz kontaktowy napisanyw php. Strona ustawiona ma utf-8. W skrypcie formularza mam ustawione konwertowanie z utf-8 na iso, no i konwerutuję dobrze tytuł, adresata, ale już sama treść znika po pierwszym polskim znaku. Czyli np. oryginalna wiadomość to "Nowa wiadomość ze strony", to na skrzynce pojawia mi się tylko "Nowa wiadomo". Tutaj kody formularza:
  1. <?php
  2.  
  3. class mirvanosContact {
  4. var $content = '';
  5. var $template = '';
  6. var $mail_email = '';
  7. var $mail_name = '';
  8. var $mail_content = '';
  9.  
  10. public function __construct() {
  11. if(!file_exists('mirvanos_contact_config.php')) {
  12. $m = 'Brak pliku konfiguracyjnego mirvanos_contact_config.php !';
  13. echo $this->errorMessage($m);
  14. echo $this->alertMessage($m);
  15. }
  16. require_once('mirvanos_contact_config.php');
  17. if(!file_exists('mirvanos_contact_template.html')) {
  18. $m = 'Brak pliku szablonu mirvanos_contact_template.html !';
  19. echo $this->errorMessage($m);
  20. echo $this->alertMessage($m);
  21. }
  22. $this->template = file_get_contents('mirvanos_contact_template.html');
  23. if(defined('USE_CAPTCHA') AND USE_CAPTCHA) {
  24. $captcha = file_get_contents('mirvanos_contact_captcha.html');
  25. $this->template = str_replace('<!--CAPTCHA-->', $captcha, $this->template);
  26. }
  27. // Uwaga !
  28. $this->template = "\n".'<!-- Skrypt kontaktu by mirvanos.org -->'."\n".$this->template;
  29. if(defined('INCLUDE_CSS') AND strlen(INCLUDE_CSS)>0)
  30. echo '<style type="text/css">'."\n".file_get_contents(INCLUDE_CSS)."\n".'</style>';
  31.  
  32. if(isset($_POST['mirvanos_content']) AND !empty($_POST['mirvanos_content']))
  33. $this->parse();
  34. else
  35. $this->content .= $this->template;
  36. }
  37.  
  38. private function parse() {
  39. if(!isset($_POST['mirvanos_email']) OR empty($_POST['mirvanos_email']) OR !$this->checkEmail(trim($_POST['mirvanos_email']))) {
  40. $m = 'Proszę, podaj prawidłowy adres e-mail';
  41. $this->content .= $this->errorMessage($m);
  42. $this->content .= $this->alertMessage($m);
  43. $this->content .= $this->template;
  44. return false;
  45. }
  46. $this->mail_email = trim($_POST['mirvanos_email']);
  47.  
  48. if(!isset($_POST['mirvanos_name']) OR empty($_POST['mirvanos_name'])) {
  49. $m = 'ProszÄ™, podaj swoje imiÄ™ i nazwisko';
  50. $this->content .= $this->errorMessage($m);
  51. $this->content .= $this->alertMessage($m);
  52. $this->content .= $this->template;
  53. return false;
  54. }
  55. $this->mail_name = strip_tags(trim($_POST['mirvanos_name']));
  56.  
  57. if(defined('USE_CAPTCHA') AND USE_CAPTCHA)
  58. if(!isset($_POST['mirvanos_antibot']) OR !$this->checkCode($_POST['mirvanos_antibot'])) {
  59. $m = 'Proszę, przepisać tekst z obrazka poprawnie';
  60. $this->content .= $this->errorMessage($m);
  61. $this->content .= $this->alertMessage($m);
  62. $this->content .= $this->template;
  63. return false;
  64. }
  65.  
  66. $this->mail_content = 'Nowa wiadomość od <b> '.$this->mail_name.' </b> <br />'."\n";
  67. $this->mail_content .= 'Adres email <a href="'.$this->mail_email.'">'.$this->mail_email.' </a> <br />'."\n";
  68. $this->mail_content .= 'Adres IP <b> '.$_SERVER["REMOTE_ADDR"].' </b> <br />'."\n\n";
  69. $this->mail_content .= " <br /><br />\n\n ";
  70. $this->mail_content .= trim( $_POST['mirvanos_content'] );
  71.  
  72. if(USE_ICONV_CONVERT) {
  73. $this->mail_content = iconv('UTF-8', 'ISO-8859-2', $this->mail_content);
  74. $this->mail_name = iconv('UTF-8', 'ISO-8859-2', $this->mail_name);
  75. }
  76.  
  77. if($this->sendMail()) {
  78. $this->mail_email = '';
  79. $this->mail_name = '';
  80. $this->mail_content = '';
  81. $this->template = '';
  82. if(defined('USE_CAPTCHA') AND USE_CAPTCHA)
  83. unset($_SESSION['AntitokenID']);
  84. }
  85. }
  86.  
  87. private function checkEmail($email='') {
  88. return eregi("^[_.0-9a-z-]+@([0-9a-z][0-9a-z-]+.)+[a-z]{2,4}$" , $email );
  89. }
  90.  
  91. private function checkCode($code='')
  92. {
  93. if(empty($code)) return false;
  94. if(!isset($_SESSION['AntitokenID']) OR empty($_SESSION['AntitokenID']))
  95. return false;
  96. if($_SESSION['AntitokenID']!=$code)
  97. return false;
  98. return true;
  99. }
  100.  
  101. private function sendMail() {
  102. require_once(CLASS_PHPMAILER);
  103. $mail = new PHPMailerLite();
  104. $mail->isMail();
  105. $mail->setFrom($this->mail_email, $this->mail_name);
  106. $mail->CharSet = 'iso-8859-2';
  107. if(USE_ICONV_CONVERT)
  108. {
  109. $mail->Subject = iconv('UTF-8', 'ISO-8859-2', MAIL_SUBJECT);
  110. }
  111. else
  112. $mail->Subject = MAIL_SUBJECT;
  113. $mail->MsgHTML( $this->mail_content );
  114. $mail->AddAddress(ADRES_EMAIL, TWOJA_NAZWA);
  115.  
  116. if(!$mail->Send()) {
  117. $m = 'WystÄ‌piĹ‚ bĹ‚Ä‌d w wysyĹ‚ce maila :( '.$mail->ErrorInfo." <br /> \n";
  118. $this->content .= $this->errorMessage($m);
  119. $this->content .= $this->alertMessage($m);
  120. return false;
  121. }
  122. // Clear all addresses and attachments
  123. $mail->ClearAddresses();
  124. $mail->ClearAttachments();
  125. $m = WIADOMOSC_ZOSTALA_WYSLANA;
  126. $this->content .= $this->errorMessage($m);
  127. $this->content .= $this->alertMessage($m);
  128. return true;
  129. }
  130.  
  131. private function alertMessage($message='') {
  132. return '<script type="text/javascript">
  133. alert(\''.$message.'\');
  134. </script>'."\n";
  135. }
  136. private function errorMessage($message='') {
  137. return '<b class="mirvanos_error">'.$message.'</b>';
  138. }
  139.  
  140. public function getHtml() {
  141. return $this->content;
  142. }
  143.  
  144. public function getMailName() {
  145. return $this->mail_name;
  146. }
  147. public function getMailEmail() {
  148. return $this->mail_email;
  149. }
  150. public function getMailContent() {
  151. return $this->mail_content;
  152. }
  153.  
  154.  
  155. }


  1. <?php
  2. // sciezka do styli formularza, mozna dac pusta
  3. define('INCLUDE_CSS', 'css/mirvanos_contact.css');
  4. // sciezka do klasy phpmailera
  5. define('CLASS_PHPMAILER', 'class.phpmailer-lite.php');
  6. //temat maila
  7. define('MAIL_SUBJECT', 'Nowa wiadomość z xxx');
  8. // Twoj adres email, na niego przyjda wiadomosci
  9. define('ADRES_EMAIL', 'xxx@xxx.pl');
  10. // Twoje Imie i nazwisko - aby mail ladnie wygladal :)
  11. define('TWOJA_NAZWA', 'xxx');
  12. // Komunikat na stronie po wyslaniu maila
  13. define('WIADOMOSC_ZOSTALA_WYSLANA', 'Dziękujemy! Wiadomość została wysłana - Postaramy się odpowiedzieć jak najszybciej. ');
  14. // czy uzywac obrazkow CAPTCHA do zabezpieczenia przed botami - zalecane
  15. define('USE_CAPTCHA', TRUE);
  16. // zmiana z utf8 na iso-8859-2
  17. define('USE_ICONV_CONVERT', TRUE);
Go to the top of the page
+Quote Post

Posty w temacie


Closed TopicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 10.10.2025 - 19:24