0

I know there are a lot of solutions posted here, but nothing seems to work for me.

$headers = 'From: '.$HOST_EMAIL."\r\n" .
    'Reply-To: ' .$HOST_EMAIL. "\r\n" .
    'X-Mailer: PHP/' . phpversion() . "\r\n" .
    'MIME-Version: 1.0' . "\r\n" . 
    'Content-type: text/html; charset=utf-8' . "\r\n".
    'Content-Transfer-Encoding: 8bit';        
mail($to, '=?UTF-8?B?'.base64_encode($subject).'?=', $body, $headers);

And the message comes like "Slaptaþodþio prisiminimas" (þ instead of ž) in subject and "Paspauskite �i� nuorod�, kad pasikeistum�te slapta�od�: nuoroda" instead of other Lithuanian letters in the message body.

aemdy
  • 3,702
  • 6
  • 34
  • 49
  • Why are you `base64_encode()`ing data that you have stated to be `Content-Transfer-Encoding: 8bit`? – DaveRandom Jan 21 '12 at 23:51
  • I don't know exactly what is the problem, but I can advice you to your PHPMailer, it is a very easy to use library, that performs great under any circumstances. http://phpmailer.worxware.com/ (I'm not biased) – Yaron U. Jan 22 '12 at 00:44
  • What have you tried that didn't work? Have you tried http://stackoverflow.com/questions/7669668/how-to-use-special-characters-in-recipients-name-when-using-phps-mail-function/7670192#7670192? – deceze Jan 22 '12 at 01:04
  • PHPmail didn't help me either. – aemdy Jan 22 '12 at 10:46
  • Are you sure your subject is UTF-8 encoded? – EricSchaefer Jan 07 '14 at 13:33

2 Answers2

3

Try

"=?UTF-8?B?".base64_encode($subject)."?="."\r\n"
laalto
  • 150,114
  • 66
  • 286
  • 303
  • Saved my day! Actually if I use "show original" in Gmail, I can see exactly the same trick it used for handling non-ascii mail subject. – ChandlerQ May 28 '14 at 04:57
0

The easiest solution for this and future mail problems will be, if you use an mailer class like phpmailer. The build-in mail function isn't compatible with todays email standards and lacks of feature (like you see). Afaik phpmailer has excellent support for utf8, and other encoding as well.

Corubba
  • 2,229
  • 24
  • 30
  • For some reasons I can't (I have also similiar problem that have author) user PHPMailer, and I am stuck with mail function. Is there a way to send mails with utf-8 support? I have funny issue cause some mail have utf-support, and some don't (body or title have issues with utf-8 characters, but there are mails that send body with utf-8 and title not) – pawel-kuznik Jun 21 '12 at 17:59