Chciałem skorzystać z prostego formularza PHP do wysyłania wiadomości przez formularz kontaktowy na stronie. Wygląda on następująco:
Kod
<?php
// This is the script for sending email.
// change the email address below to your own email address.
$mailTo = 'email@email.pl';
$name = htmlspecialchars($_POST['name']);
$mailFrom = htmlspecialchars($_POST['email']);
$subject = 'Wiadomość ze strony WWW'.htmlspecialchars($_POST['Subject']);
$message_text = htmlspecialchars($_POST['message']);
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=utf-8' . "\r\n";
$headers = "From: $name <$mailFrom>\n";
$headers .= "Reply-To: $name <$mailFrom>\n";
$message = $message_text;
mail($mailTo, $subject, $message, $headers );
?>
// This is the script for sending email.
// change the email address below to your own email address.
$mailTo = 'email@email.pl';
$name = htmlspecialchars($_POST['name']);
$mailFrom = htmlspecialchars($_POST['email']);
$subject = 'Wiadomość ze strony WWW'.htmlspecialchars($_POST['Subject']);
$message_text = htmlspecialchars($_POST['message']);
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=utf-8' . "\r\n";
$headers = "From: $name <$mailFrom>\n";
$headers .= "Reply-To: $name <$mailFrom>\n";
$message = $message_text;
mail($mailTo, $subject, $message, $headers );
?>
Jednak po wysłaniu wiadomości na maila przychodzą krzaki zamiast polskich znaków w treści wiadomości (nadawca i temat są wyświetlane poprawnie):
Kod
A teraz polskie znaki siÄ pojawiÄ
? ĹóşźÄ
Mam ustawiony chyba poprawny charset w headers. Sprawdzałem też kodowanie formularza - oba pliki (html i php) są kodowane w UTF-8.
Co tu robię nie tak? W jaki sposób mogę to naprawić?