0

I have a questionnaire form on the web. After filling in this form, I send it to me by email, using the PHP function mail(). The form body and the data it contains, including the private message are displayed correctly on gmail.com. The problem, however, occurs in the header of the email itself. Some characters are displayed incorrectly. Here is a sample header:

$headers = "Content-Type:text/html; charset=utf-8\r\n";
$headers .= "From:" .$email . "\r\n";
$headers .= "Reply:" . $email . "\r\n";
$headers .= "X-Mailer: PHP/". phpversion() . "\r\n" ;

Required display of email subject:

Nový dotaz -- námět, od Fořt Petr <p.fort1990@gmail.com>

Simultaneous displaying of the subject:

Nový dotaz -- námÄ☒t od: FoÅ☒t Petr <p.fort1990@gmail.com>

The squared times symbol is more like a rectangle.

Is anything wrong? Or where should I look for a mistake?

Petr Fořt Fru-Fru
  • 858
  • 2
  • 8
  • 23

2 Answers2

0

I'm not sure \r\n works on all platforms

see : Which line break in php mail header, \r\n or \n?

instead

("xxx\r\n\yyy");

use

Header('xxx');
Header('yyy');

or use PHP_EOL, not "\r\n"

Eric
  • 608
  • 4
  • 11
0

Problem solved. My hosting provider uses different character encoding for the headers - I can't explain why, but the following php function will do it all.

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

And now all you have to do is send an email using the mail () method in combination with the method defined above recode_to_utf8(). Like this:

mail(recode_to_utf8($mail_to), recode_to_utf8($subject), recode_to_utf8($message), recode_to_utf8($headers));

I hope it helps others if they have the same problem as me.

Petr Fořt Fru-Fru
  • 858
  • 2
  • 8
  • 23