Witam, od 2 dni borykam się z problemem w PHP. Mam skrypt parsera XML który wczytuje dane z RSS i następnie sparsowane wysyła mailem. Problem jest z ustawieniem polskich znaków w skrypcie. W mailu dostaję tekst z krzakami zamiast polskich znaków, nie obcina wyrazów.

Problem jest w tym pliku PHP 
  1. <?php
  2.  
  3.  
  4.  
  5. // Global variables for function use.
  6. $GLOBALS['title'] = false;
  7. $GLOBALS['link'] = false;
  8. $GLOBALS['description'] = false;
  9. $GLOBALS['titletext'] = null;
  10. $GLOBALS['linktext'] = null;
  11. $GLOBALS['desctext'] = null;
  12. $GLOBALS['email_body'] = '';
  13.  
  14. $GLOBALS['email_body'] .= '<html>
  15. <body><table width="100%" cellpadding="3" cellspacing="1" border="0" align="center">';
  16. $GLOBALS['email_body'] .= ' <tr>';
  17. // Add a title for the newsletters here
  18. $GLOBALS['email_body'] .= ' <th align="left"></th>';
  19. $GLOBALS['email_body'] .= ' </tr>';
  20. $GLOBALS['email_body'] .= ' <tr>';
  21. $GLOBALS['email_body'] .= ' <td class="row1" width="100%">';
  22. $GLOBALS['email_body'] .= ' <font face="arial">';
  23. // Add some HTML for store specials here
  24. $GLOBALS['email_body'] .= ' ';
  25.  
  26.  
  27. // function: startElement
  28. // Deals with the starting element
  29. function startElement( $parser, $tagName, $attrs ) {
  30. // By setting global variable of tag name
  31. // I can determine which tag I am currently
  32. // parsing.
  33. switch( $tagName ) {
  34. case 'TITLE':
  35. $GLOBALS['title'] = true;
  36. break;
  37. case 'LINK':
  38. $GLOBALS['link'] = true;
  39. break;
  40. case 'DESCRIPTION':
  41. $GLOBALS['description'] = true;
  42. break;
  43. }
  44. }
  45.  
  46. // function: endElement
  47. // Deals with the ending element
  48. function endElement( $parser, $tagName ) {
  49. // By noticing the closing tag,
  50. // I can print out the data that I want.
  51. switch( $tagName ) {
  52. case 'TITLE':
  53. //echo "<p><b>" . $GLOBALS['titletext'] . "</b><br/>";
  54. $GLOBALS['email_body'] .= "<p><b><a href=\"". $GLOBALS['linktext'] . "\">" . $GLOBALS['titletext'] . "</a></b><br/>";
  55. $GLOBALS['title'] = false;
  56. $GLOBALS['titletext'] = "";
  57. break;
  58. case 'LINK':
  59. //echo "Link: <a href=\"". $GLOBALS['linktext'] . "\">" . $GLOBALS['linktext'] . "</a><br/>";
  60. $GLOBALS['email_body'] .= " ";
  61. $GLOBALS['link'] = false;
  62. $GLOBALS['linktext'] = "";
  63. break;
  64. case 'DESCRIPTION':
  65. //echo "Desc: " . $GLOBALS['desctext'] . "</p>";
  66. $GLOBALS['email_body'] .= "Opis: " . $GLOBALS['desctext'] . "</p>";
  67. $GLOBALS['description'] = false;
  68. $GLOBALS['desctext'] = "";
  69. break;
  70. }
  71.  
  72. }
  73.  
  74. // function: charElement
  75. // Deals with the character elements (text)
  76. function charElement( $parser, $text ) {
  77. // Verify the tag that text belongs to.
  78. // I set the global tag name to true
  79. // when I am in that tag.
  80. if( $GLOBALS['title'] == true ) {
  81. $GLOBALS['titletext'] .= $text;
  82. } else if( $GLOBALS['link'] == true ) {
  83. $GLOBALS['linktext'] .= $text;
  84. } else if( $GLOBALS['description'] == true ) {
  85. $GLOBALS['desctext'] .= $text;
  86. }
  87. }
  88.  
  89. // Create an xml parser
  90. $xmlParser = xml_parser_create();
  91. // Create an xml parser
  92. $xmlParser2 = xml_parser_create();
  93.  
  94.  
  95. // Set up element handler
  96. xml_set_element_handler( $xmlParser, "startElement", "endElement" );
  97. // Set up element handler
  98. xml_set_element_handler( $xmlParser2, "startElement", "endElement" );
  99.  
  100.  
  101. // Set up character handler
  102. xml_set_character_data_handler( $xmlParser, "charElement" );
  103. // Set up character handler
  104. xml_set_character_data_handler( $xmlParser2, "charElement" );
  105.  
  106. // ********************************************************************************
    **********
  107. // Input the URL for XML RSS feed below - any RSS feed should work
  108. // Open connection to RSS XML file for parsing.
  109. $fp = fopen( "adres RSS", "r" )
  110. or die( "Cannot read RSS data file." );
  111. // ********************************************************************************
    **********
  112.  
  113. // Parse XML data from RSS file.
  114. while( $data = fread( $fp, 4096 ) ) {
  115. xml_parse( $xmlParser, $data, feof( $fp ) );
  116. }
  117.  
  118. // ********************************************************************************
    **********
  119. // Use this for a second feed
  120. // Open connection to RSS XML file for parsing.
  121. /* $fp2 = fopen( "http://some.second.rss.feed", "r" )
  122.   or die( "Cannot read RSS data file." );
  123.  
  124.   // Parse XML data from RSS file.
  125.   while( $data2 = fread( $fp2, 4096 ) ) {
  126.   xml_parse( $xmlParser2, $data2, feof( $fp2 ) );
  127.   }
  128. */
  129. // ********************************************************************************
    **********
  130.  
  131. // Close file open handler
  132. fclose( $fp );
  133.  
  134. // ********************************************************************************
    **********
  135. // Use this for a second feed
  136. // Close file open handler
  137. /* fclose( $fp2 );*/
  138. // ********************************************************************************
    **********
  139.  
  140.  
  141. // Free xml parser from memory
  142. xml_parser_free( $xmlParser );
  143.  
  144. // ********************************************************************************
    **********
  145. // Use this for a second feed
  146. // Free xml parser from memory
  147. /* xml_parser_free( $xmlParser2 );*/
  148. // ********************************************************************************
    **********
  149.  
  150. // ********************************************************************************
    **********
  151. // Put unsubscribe information here
  152. $GLOBALS['email_body'] .= ('
  153. <br>
  154. </font>
  155. </td>
  156. </tr>
  157. </table></body></html>
  158. ');
  159. // ********************************************************************************
    **********
  160.  
  161. echo $GLOBALS['email_body'];
  162. // ********************************************************************************
    **********
  163. // Add email subjest here, remove date if you want (delete . date("m.d.y") to remove date)
  164. $subject = ' - ' . date("d.m.y");
  165. // ********************************************************************************
    **********
  166.  
  167. // ********************************************************************************
    **********
  168. // Add who the email is from
  169. $from = 'OD';
  170. // ********************************************************************************
    **********
  171.  
  172. // ********************************************************************************
    **********
  173. // Add store email address here
  174. $from_email = 'OD';
  175. // ********************************************************************************
    **********
  176.  
  177. // IMPORTANT***********************************************************************
    **********
  178. // Uncomment this section after testing
  179. $sql = 'SELECT `customers_firstname` , `customers_lastname` , `customers_email_address` '
  180. . ' FROM `customers` '
  181. . ' WHERE `customers_newsletter` = 1';
  182. $result = mysql_query($sql)or die (mysql_error());
  183.  
  184. while ($row = mysql_fetch_array($result)) {
  185. $name = $row['customers_firstname'] .' '. $row['customers_lastname'];
  186. $email = $row['customers_email_address'];
  187.  
  188. // IMPORTANT***********************************************************************
    **********
  189. // To test change $email to 'store@email.com'
  190. newsletter_mail($name, 'do kogo wyslac', $subject, $GLOBALS['email_body'], $from, $from_email);
  191. // ********************************************************************************
    **********
  192.  
  193. // IMPORTANT***********************************************************************
    **********
  194. // Uncomment this section after testing
  195. }
  196.  
  197. // Function to send out the newsletters
  198. function newsletter_mail($to_name, $to_email_address, $email_subject, $email_text, $from_email_name, $from_email_address) {
  199. if (SEND_EMAILS != 'true') return false;
  200.  
  201. // Instantiate a new mail object
  202. $message = new email(array('X-Mailer: SeekShopping Mailer'));
  203.  
  204. // Build the text version
  205. $text =(email_text);$message->add_html($email_text, $text);
  206.  
  207. // Send message
  208. $message->build_message();
  209. $message->send($to_name, $to_email_address, $from_email_name, $from_email_address, $email_subject, 'od- email ');
  210. }
  211.  
  212. mysql_close($linkid);
  213. ?>