-1

I have a problem with sending mail from php code. I want to use polish characters in email message. I searched many post on stack with the same problem but nothing works.

<?php
if(isset($_POST['submit'])){
 $to = "[email protected]";
 $from = $_POST['email'];
 $name = $_POST['name'];
 $phone = $_POST['phone'];
 $subject = "Wiadomość ze strony";
 $message = "Imię i Nazwisko: " . $name . "\nTelefon kontaktowy: " . $phone . "\n\nTreść wiadomości:" . "\n\n" . $_POST['msg'];

 $headers = "From: $from \r\n". 
            "MIME-Version: 1.0" . "\r\n" . 
            "Content-type: text/html; charset=UTF-8" . "\r\n";

 mail($to,$subject,$message,$headers);
 header('Location: index.html');
}
?>

I have asked my friend to check on his vps and this code work correctly. So there must be a problem with server. I use linuxpl.com.

I found the solution. Polish characters work fine when I added this line in html form.

accept-charset="ISO-8859-1"
Rafał Sokalski
  • 1,817
  • 2
  • 17
  • 29

1 Answers1

0
mail($to,utf8_decode($subject),utf8_decode($message),utf8_decode($headers));
  • After using this I have sth like this: Tre?? wiadomo?ci: – Rafał Sokalski Apr 02 '17 at 15:24
  • This answer has a lot of room for improvement. Could you explain why you think this would help? Why does UTF decoding things change anything? On an unrelated note, this is the appropriate way to answer questions, I've voted to reject your proposed edit to the question. Adding a solution into the question confuses other people that might look at this question. – HPierce Apr 02 '17 at 15:40
  • In my case i Use html_entity_decode(); – John Max Oct 19 '19 at 12:51