2

I send email with PHP's mail() function. I need to have the from field encoded in UTF-8 so I set these mail headers:

function mail_headers($from, $contentType = "text/plain") {
    $headers = "From: ".mime_header_encode($from)."\n";
    $headers .= 'Reply-To: '.mime_header_encode($from)."\n";
    $headers .= 'MIME-Version: 1.0' ."\n";
    $headers .= 'Content-Type: '.$contentType.'; charset=utf-8' ."\n";
    $headers .= 'Content-Transfer-Encoding: 8bit'. "\n";

    return $headers;
}

function mime_header_encode($text, $encoding = "utf-8") {
    return "=?$encoding?Q?" . imap_8bit($text) . "?=";
}

It works good in my PC but not so good on production server. It doesn't recognize encoded string =?utf-8?Q?Website name <info@myshop.com>?= as a valid email so it tries to make it better. The server will finally send an email with this part of header:

From: =?utf-8?Q?Website name <info@myshop.com>,
  ?=@hosting-domain.com

With this headers, email recipient see another strange sender (the string after comma). Can I make PHP not to touch my email string?

Thank you!

hek2mgl
  • 152,036
  • 28
  • 249
  • 266
koubic
  • 597
  • 1
  • 11
  • 23

1 Answers1

0

The php function mb_encode_mimeheader() is intended to encode the mime headers according to the php.ini directive 'mbstring.internal_encoding'. If just using mb_encode_mimeheader() does not help you should check the correct setting of this directive.

Also you should read the comments on the site I linked. This may help too.

hek2mgl
  • 152,036
  • 28
  • 249
  • 266