Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: [HTML][PHP]UTF8 i PHP
Forum PHP.pl > Forum > Przedszkole
MrSeefeld
Witam!

Na mojej stronie znajduje sie formularz kontaktowy php. Mimo ze strona ma wspisane UTF8 od mailach zamiast polskich znakow przychodza krzaczki.

Formularz znajduje sie na stronie: Formularz Kontaktowy

A tutaj kod obciety o zbedne rzeczy :

  1. <?php
  2. //If the form is submitted
  3. if(isset($_POST['submit'])) {
  4.  
  5. //Check to make sure that the name field is not empty
  6. if(trim($_POST['contactname']) == '') {
  7. $hasError = true;
  8. } else {
  9. $name = trim($_POST['contactname']);
  10. }
  11.  
  12. //Check to make sure that the subject field is not empty
  13. if(trim($_POST['subject']) == '') {
  14. $hasError = true;
  15. } else {
  16. $subject = trim($_POST['subject']);
  17. }
  18.  
  19. //Check to make sure sure that a valid email address is submitted
  20. if(trim($_POST['email']) == '') {
  21. $hasError = true;
  22. } else if (!eregi("^[A-Z0-9._%-]+@[A-Z0-9._%-]+\.[A-Z]{2,4}$", trim($_POST['email']))) {
  23. $hasError = true;
  24. } else {
  25. $email = trim($_POST['email']);
  26. }
  27.  
  28. //Check to make sure comments were entered
  29. if(trim($_POST['message']) == '') {
  30. $hasError = true;
  31. } else {
  32. if(function_exists('stripslashes')) {
  33. $comments = stripslashes(trim($_POST['message']));
  34. } else {
  35. $comments = trim($_POST['message']);
  36. }
  37. }
  38.  
  39. //If there is no error, send the email
  40. if(!isset($hasError)) {
  41. $emailTo = 'email@email.com'; //Put your own email address here
  42. $body = "Name: $name \n\nEmail: $email \n\nSubject: $subject \n\nComments:\n $comments";
  43. $headers = 'From: www.email.com <'.$emailTo.'>' . "\r\n" . 'Reply-To: ' . $email;
  44.  
  45. mail($emailTo, $subject, $body, $headers);
  46. $emailSent = true;
  47. }
  48. }
  49. ?>
  50.  
  51. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  52. <html xmlns="http://www.w3.org/1999/xhtml">
  53. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  54. <title>Slough Web Design</title>
  55. <link href="css/style.css" rel="stylesheet" type="text/css" />
  56. <link href="css/contact-form-styles.css" rel="stylesheet" type="text/css" />
  57. </head>
  58. <body><div id="outer-wrapper">
  59. <!-- top start -->
  60.  
  61. <!-- top end -->
  62.  
  63. <!-- header start -->
  64.  
  65.  
  66. <!-- header end -->
  67.  
  68. <!-- content start -->
  69.  
  70.  
  71.  
  72. <div id="contact-wrapper">
  73.  
  74. <?php if(isset($hasError)) { //If errors are found ?>
  75. <p class="error">Please check if you have filled all the fields with valid information. Thank you.</p>
  76. <?php } ?>
  77.  
  78. <?php if(isset($emailSent) && $emailSent == true) { //If email is sent ?>
  79. <p><strong>Email Successfully Sent!</strong></p>
  80. <p>Thank you <strong><?php echo $name;?></strong> for using my contact form! Your email was successfully sent and I will be in touch with you soon.</p>
  81. <?php } ?>
  82.  
  83. <form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>" id="contactform">
  84. <div>
  85. <label for="name"><strong>Name:</strong></label>
  86. <input type="text" size="50" name="contactname" id="contactname" value="" class="required" />
  87. </div>
  88.  
  89. <div>
  90. <label for="email"><strong>Email:</strong></label>
  91. <input type="text" size="50" name="email" id="email" value="" class="required email" />
  92. </div>
  93.  
  94. <div>
  95. <label for="subject"><strong>Subject:</strong></label>
  96. <input type="text" size="50" name="subject" id="subject" value="" class="required" />
  97. </div>
  98.  
  99. <div>
  100. <label for="message"><strong>Message:</strong></label>
  101. <textarea rows="5" cols="50" name="message" id="message" class="required"></textarea>
  102. </div>
  103. <div>
  104. <input class="submitbutton" type="submit" value="Send Message" name="submit" />
  105. </div>
  106. </form>
  107. </div>
  108.  
  109.  
  110.  
  111.  
  112. </div>
  113.  
  114.  
  115.  
  116. </div>
  117.  
  118.  
  119.  
  120. <!-- content end -->
  121.  
  122. <!-- footer start -->
  123.  
  124. <!-- footer end -->
  125. </div>
  126.  
  127. </body>
  128. </html>
zelu
musisz ustawić kodowanie dla maila. Było już kilka razy na forum, poszukaj. Albo użyj PHPMailera smile.gif
XP'ek
jakim programem pracujesz ? jak coś ściągnij np. notatnik ++ i sprawdź bo czasami masz kodowanie utf ustawione w meta tagach a strona zapisana jest jako kodowana zachodnioeuropejski smile.gif


zaznaczone na czerwono kodowanie pliku winksmiley.jpg
krispak
Sprobuj dostawic do tego
  1. $headers .= 'From: www.email.com <'.$emailTo.'>' . "\r\n" . 'Reply-To: ' . $email;

jeszcze to
  1. $headers .= 'Content-type: text/html; charset=UTF-8\r\n';


A jak nie to polecam klase Phpmailer

Pozdrawiam
MrSeefeld
Dzieki wszystkim za uwage!

Pracuje w Dreaweaverze.. sprawdzilem kodowanie.. ustawione na UTF-8.

Moze wyda wam sie to smieszne pytanie ale w ktorym miejscu dokumentu mam wstawic te dwa komentarze php? Zaraz po otwarciu znacznika php?


Jesli tak, to juz probowalem i polskich znakow w mailu nadal brak.
XP'ek
ja bym to wstawił tylko tu w końcu do tego to się odnosi
  1. #
  2. if(!isset($hasError)) {
  3. $emailTo = 'email@email.com'; //Put your own email address here
  4. $body = "Name: $name \n\nEmail: $email \n\nSubject: $subject \n\nComments:\n $comments";
  5. $headers = 'From: www.email.com <'.$emailTo.'>' . "\r\n" . 'Reply-To: ' . $email;
  6.  
  7. mail($emailTo, $subject, $body, $headers);
  8. $emailSent = true;
  9. }



=edit=

ja u siebie mam tak to zrobione smile.gif

  1. <?
  2. if (count($_POST))
  3. {
  4. ////////// USTAWIENIA //////////
  5. $email = 'asiakowalska@wp.pl'; // Adres e-mail adresata
  6. $subject = 'Nazwa Strony: Wiadomość ze Strony.'; // Temat listu
  7. $message = 'Dziękujemy za wysłanie formularza'; // Komunikat
  8. $error = 'Wystąpił błąd podczas wysyłania formularza'; // Komunikat błędu
  9. $charset = 'utf-8'; // Strona kodowa
  10. //////////////////////////////
  11.  
  12. $head =
  13. "MIME-Version: 1.0\r\n" .
  14. "Content-Type: text/plain; charset=$charset\r\n" .
  15. "Content-Transfer-Encoding: 8bit";
  16. $body = '';
  17. foreach ($_POST as $name => $value)
  18. {
  19. if (is_array($value))
  20. {
  21. for ($i = 0; $i < count($value); $i++)
  22. {
  23. $body .= "$name:" . (get_magic_quotes_gpc() ? stripslashes($value[$i]) : $value[$i]) . "\r\n";
  24. }
  25. }
  26. else $body .= "$name:" . (get_magic_quotes_gpc() ? stripslashes($value) : $value) . "\r\n";
  27. }
  28. echo mail($email, "=?$charset?B?" . base64_encode($subject) . "?=", $body, $head) ? $message : $error;
  29. }
  30. ?>


a komunikaty o podaniu wartości pola nie lepiej dać w js ? smile.gif
krispak
Nie, w miejscu odpowiedzialnym za wysylanie meila.
Czyli:
  1. if(!isset($hasError)) {
  2. $emailTo = 'email@email.com'; //Put your own email address here
  3. $body = "Name: $name \n\nEmail: $email \n\nSubject: $subject \n\nComments:\n $comments";
  4. $headers .= 'From: www.email.com <'.$emailTo.'>' . "\r\n" . 'Reply-To: ' . $email;
  5. $headers .= 'Content-type: text/html; charset=UTF-8\r\n';
  6. mail($emailTo, $subject, $body, $headers);
  7. $emailSent = true;
  8. }

MrSeefeld
  1. <?php
  2. //If the form is submitted
  3. if(isset($_POST['submit'])) {
  4.  
  5. //Check to make sure that the name field is not empty
  6. if(trim($_POST['contactname']) == '') {
  7. $hasError = true;
  8. } else {
  9. $name = trim($_POST['contactname']);
  10. }
  11.  
  12. //Check to make sure that the subject field is not empty
  13. if(trim($_POST['subject']) == '') {
  14. $hasError = true;
  15. } else {
  16. $subject = trim($_POST['subject']);
  17. }
  18.  
  19. //Check to make sure sure that a valid email address is submitted
  20. if(trim($_POST['email']) == '') {
  21. $hasError = true;
  22. } else if (!eregi("^[A-Z0-9._%-]+@[A-Z0-9._%-]+\.[A-Z]{2,4}$", trim($_POST['email']))) {
  23. $hasError = true;
  24. } else {
  25. $email = trim($_POST['email']);
  26. }
  27.  
  28. //Check to make sure comments were entered
  29. if(trim($_POST['message']) == '') {
  30. $hasError = true;
  31. } else {
  32. if(function_exists('stripslashes')) {
  33. $comments = stripslashes(trim($_POST['message']));
  34. } else {
  35. $comments = trim($_POST['message']);
  36. }
  37. }
  38.  
  39. //If there is no error, send the email
  40. if(!isset($hasError)) {
  41. $emailTo = 'info@sloughwebdesign.com'; //Put your own email address here
  42. $body = "Name: $name \n\nEmail: $email \n\nSubject: $subject \n\nComments:\n $comments";
  43. $headers .= 'From: www.sloughwebdesign.com <'.$emailTo.'>' . "\r\n" . 'Reply-To: ' . $email; //poprawka
  44. $headers .= 'Content-type: text/html; charset=UTF-8\r\n'; // poprawka
  45. mail($emailTo, $subject, $body, $headers);
  46. $emailSent = true;
  47. }
  48. }
  49. ?>


Poprawione w wyzej wymienionych miejscach. Niestety dalej nie pokazuje polskich znakow;/ Czy ma jakiekolwiek znaczenie ze serwer znajduje sie w USA?
XP'ek
sprawdź sobie ten skrypt on działa na 100% z polskimi bo używam jeśli będą to będziemy dalej kopać z twoim skryptem co jest nie tak

  1. <script type='text/javascript'>
  2. function validate(t)
  3. {
  4. if(t.Temat.value == '')
  5. {
  6. alert('Proszę o podanie Tematu Wiadomości.');
  7. t.Temat.select();
  8. return false;
  9. }
  10. if(t.email.value == '')
  11. {
  12. alert('Proszę o podanie kontaktu');
  13. t.email.select();
  14. return false;
  15. }
  16. if(t.Treść.value == '')
  17. {
  18. alert('Proszę o podanie treści maila');
  19. t.Treść.select();
  20. return false;
  21. }
  22. }
  23. </script>
  24. <?
  25. if (count($_POST))
  26. {
  27. ////////// USTAWIENIA //////////
  28. $email = 'kola@wp.pl'; // Adres e-mail adresata
  29. $subject = 'Strona: Wiadomość ze Strony.'; // Temat listu
  30. $message = 'Dziękujemy za wysłanie formularza'; // Komunikat
  31. $error = 'Wystąpił błąd podczas wysyłania formularza'; // Komunikat błędu
  32. $charset = 'utf-8'; // Strona kodowa
  33. //////////////////////////////
  34.  
  35. $head =
  36. "MIME-Version: 1.0\r\n" .
  37. "Content-Type: text/plain; charset=$charset\r\n" .
  38. "Content-Transfer-Encoding: 8bit";
  39. $body = '';
  40. foreach ($_POST as $name => $value)
  41. {
  42. if (is_array($value))
  43. {
  44. for ($i = 0; $i < count($value); $i++)
  45. {
  46. $body .= "$name:" . (get_magic_quotes_gpc() ? stripslashes($value[$i]) : $value[$i]) . "\r\n";
  47. }
  48. }
  49. else $body .= "$name:" . (get_magic_quotes_gpc() ? stripslashes($value) : $value) . "\r\n";
  50. }
  51. echo mail($email, "=?$charset?B?" . base64_encode($subject) . "?=", $body, $head) ? $message : $error;
  52. }
  53. ?>
  54. <form action="" method="post" onSubmit='return validate(this);'>
  55.  
  56. <table border='0' cellpadding='5' cellspacing='0' width='100%'><tr>
  57. <td valign='top' align='right' class='small_gray_text'>temat: </td>
  58. <td valign='top'><input type='text' name='Temat' class='form'></td>
  59. </tr><tr>
  60. <td valign='top' align='right' class='small_gray_text'>e-mail: </td>
  61. <td valign='top'><input type='text' name='email' class='form'></td>
  62. </tr><tr>
  63. <td valign='top' align='right' class='small_gray_text'>telefon: </td>
  64. <td valign='top'><input type='text' name='gsm' class='form'></td>
  65. </tr><tr>
  66. <td valign='top' align='right' class='small_gray_text'>treść: </td>
  67. <td valign='top'><textarea name='Treść' class='form'></textarea></td>
  68. </tr><tr>
  69. <td> </td>
  70. <td><input type='submit' value='wyślij' name='send' class='formb'></td>
  71. </tr></table>
  72.  
  73. </form>
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.