-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 = "...@gmail.com";
 $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
  • And what's the error you're getting? – mrun Apr 02 '17 at 14:34
  • There are no error. Polish characters doesn't work correctly e.g Tre¶ć wiadomo¶ci: ąść – Rafał Sokalski Apr 02 '17 at 14:35
  • Check if your php file is in utf-8 encoding, also check the "Content-type:" header of incoming message at gmail. – umka Apr 02 '17 at 15:07
  • Message subject should be mime-encoded in any way. – umka Apr 02 '17 at 15:09
  • Yes, I saved in utf-8 encoding. Gmail header: X-PHP-Originating-Script: 2211:send_email.php From: ...@gmail.com MIME-Version: 1.0 Content-type: text/html; charset=UTF-8 Message-Id: Date: Sun, 02 Apr 2017 17:34:37 +0200 – Rafał Sokalski Apr 02 '17 at 15:38

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