PHP and Russian letters

What happens to Russian letters when sending via a PHP request to ... mail, for example? "hard-coded" Russian letters are displayed correctly, but from a textboxex form with hieroglyphs:

HTML page:

<tr>
 <td style="width: 280px"> </td>
 <td><input type="text" id="workContent"/></td>
</tr>

PHP page:

$WorkContent = $_REQUEST["workContent"]; // 
// ...
$WorkContentLabel = " ";
// ...
$message .= $WorkContentLabel . ":\t" . $WorkContent . "\n";
// ...
// email stuff (data below changed)
$to = "test@gmail.com";
$from = "me@domain.com";
$from_header = "From: Russian site command ";

$subject = "Message with russian letters";
$subject = '=?utf-8?B?'.$subject.'?=';
$message .= $subject;

// send message
mail($to, $subject, $message, $from_header);

The user enters some content in the text box: alt text http://lh3.ggpht.com/_1TPOP7DzY1E/S1y6Y0wb9tI/AAAAAAAAC88/OkdMQkO47HQ/s800/works.png

and submits the form.

What will I get (in GMAIL):

 :       1)ЎѕґµЂ¶°Ѕµ 2)RABOT

So, the hard-coded Russian text is OK, sent by the Russian text form is NOK , the ASCII text sent by the form is OK.

Does anyone know what could be causing this weird coding behavior?

EDIT: used

$subject = "    - subject with russian letters";
$subject = '=?UTF-8?B?' . base64_encode($subject) . '?=';
$message .= $subject;

, ÿ - http://lh6.ggpht.com/_1TPOP7DzY1E/S1zFqFe9ohI/AAAAAAAAC9E/PZ7C4JtEHTU/s800/subject.png

+3
3

base64_encode() $subject, :

$subject = '=?UTF-8?B?' . base64_encode($subject) . '?=';

, .php, UTF-8 .


: PHP?

+8

:

  • HTML- ( <meta http-equiv..>)
  • PHP/HTML/ ( )
  • ( ) ( )
  • ( ) ( )

UTF-8 .

+3

Like what Alix said about base64 in the encoded word RFC2047 in the Subject line, you also need to tell the mail server to expect UTF-8 encoded text to be sent to the mail body, adding headers:

MIME-Version: 1.0
Content-Type: text/plain;charset=utf-8

otherwise, it might be a mistake to guess before the mail program.

+1
source

Source: https://habr.com/ru/post/1729815/


All Articles