Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: Polskie czcionki w formularzu mailowym
Forum PHP.pl > Forum > PHP
Kzajko
Nie mając dużego doświadczenia z php sciągnąłem z internetu gotowy skrypt umożliwiający wysyłania wiadomości po wypełnieniu formularza na stronie internetowej. Wszystko działa ok za wyjątkiem polskich czcionek. Emaile przychodza z z dziwnymi znakami, które pojawiają sie tam zamiast polskich czcionek.

Domyslam się ze trzeba wpisac linijke lub dwie kodu, który sprawi że polskie czcionki pojawią się. Jak to można zrobic?

  1. <?php
  2. $my_email = "abc@yahoo.com";
  3. $continue = "/";
  4. $errors = array();
  5.  
  6. // Remove $_COOKIE elements from $_REQUEST.
  7.  
  8. if(count($_COOKIE)){foreach(array_keys($_COOKIE) as $value){unset($_REQUEST[$value]);}}
  9.  
  10. // Validate email field.
  11.  
  12. if(isset($_REQUEST['email']) && !empty($_REQUEST['email']))
  13. {
  14.  
  15. $_REQUEST['email'] = trim($_REQUEST['email']);
  16.  
  17. if(substr_count($_REQUEST['email'],"@") != 1 || stristr($_REQUEST['email']," ")){$errors[] = "Email address is invalid";}else{$exploded_email = explode("@",$_REQUEST['email']);if(empty($exploded_email[0]) || strlen($exploded_email[0]) > 64 || empty($exploded_email[1])){$errors[] = "Email address is invalid";}else{if(substr_count($exploded_email[1],".") == 0){$errors[] = "Email address is invalid";}else{$exploded_domain = explode(".",$exploded_email[1]);if(in_array("",$exploded_domain)){$errors[] = "Email address is invalid";}else{foreach($exploded_domain as $value){if(strlen($value) > 63 || !preg_match('/^[a-z0-9-]+$/i',$value)){$errors[] = "Email address is invalid"; break;}}}}}}
  18.  
  19. }
  20.  
  21. // Check referrer is from same site.
  22.  
  23. if(!(isset($_SERVER['HTTP_REFERER']) && !empty($_SERVER['HTTP_REFERER']) && stristr($_SERVER['HTTP_REFERER'],$_SERVER['HTTP_HOST']))){$errors[] = "You must enable referrer logging to use the form";}
  24.  
  25. // Check for a blank form.
  26.  
  27. function recursive_array_check_blank($element_value)
  28. {
  29.  
  30. global $set;
  31.  
  32. if(!is_array($element_value)){if(!empty($element_value)){$set = 1;}}
  33. else
  34. {
  35.  
  36. foreach($element_value as $value){if($set){break;} recursive_array_check_blank($value);}
  37.  
  38. }
  39.  
  40. }
  41.  
  42. recursive_array_check_blank($_REQUEST);
  43.  
  44. if(!$set){$errors[] = "You cannot send a blank form";}
  45.  
  46. unset($set);
  47.  
  48. // Display any errors and exit if errors exist.
  49.  
  50. if(count($errors)){foreach($errors as $value){print "$value<br>";} exit;}
  51.  
  52. if(!defined("PHP_EOL")){define("PHP_EOL", strtoupper(substr(PHP_OS,0,3) == "WIN") ? "r\n" : "\n");}
  53.  
  54. // Build message.
  55.  
  56. function build_message($request_input){if(!isset($message_output)){$message_output ="";}if(!is_array($request_input)){$message_output = $request_input;}else{foreach($request_input as $key => $value){if(!empty($value)){if(!is_numeric($key)){$message_output .= str_replace("_"," ",ucfirst($key)).": ".build_message($value).PHP_EOL.PHP_EOL;}else{$message_output .= build_message($value).", ";}}}}return rtrim($message_output,", ");}
  57.  
  58. $message = build_message($_REQUEST);
  59.  
  60. $message = stripslashes($message);
  61.  
  62. $subject = "Email ze strony internetowej";
  63.  
  64. $subject = stripslashes($subject);
  65.  
  66. $from_name = "";
  67.  
  68. if(isset($_REQUEST['name']) && !empty($_REQUEST['name'])){$from_name = stripslashes($_REQUEST['name']);}
  69.  
  70. $headers = "From: {$from_name} <{$_REQUEST['email']}>";
  71.  
  72. mail($my_email,$subject,$message,$headers);
  73. ?>
Matte
Dodaj do nagłówków coś takiego:
  1. <?php
  2. Content-Type: text/plain; charset=us-ascii
  3. ?>

gdzie zamiast us-ascii wstawisz oczywiście odpowiednie kodowanie (takie w którym masz zapisany plik) ; )
Kzajko
Wstawiłem

  1. <?php
  2. Content-Type: text/html; charset=UTF-8
  3. ?>


i teraz otrzymuje komunikat:

Parse error: syntax error, unexpected ':' in /public_html/FormToEmail.php on line 2
TomASS
Na samym dole masz:
  1. <?php
  2. $headers = "From: ";
  3. mail($my_email,$subject,$message,$headers);
  4. ?>


daj w $headers:
  1. <?php
  2. $headers =     "MIME-Version: 1.0r\n"
  3.             ."Content-type: text/html; charset=utf-8r\n"
  4.                 . 'From: {$from_name} <{$_REQUEST['email']}>' . "r\n"
  5.                ."X-Mailer: PHP/" . phpversion();
  6. ?>


gdzie w charset=utf-8 daj takie kodowanie w jakim zakodowane są znaki
Kzajko
Po wstawieniu dostaję komunikat o "string error" Czy trzeba to jakoś przeformatowac?
erix
string" title="Zobacz w manualu PHP" target="_manual i zobacz, jak zachowują się poszczególne rodzaje cudzysłowów.
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.