E
E
Evgeny Petrov2018-03-12 21:23:38
PHP
Evgeny Petrov, 2018-03-12 21:23:38

How to fix encoding problem?

Send code:

spoiler
<?

$key = md5($password);					
          $mail='
          <style>
.msgBody{width: 60%;margin-left: 20%;border-radius: 10px;background: #fff;color: #222;font-family: Tahoma;border: 1px solid #ebebeb;overflow: hidden;}
.msgBody .header{width: 100%;padding-top: 20px;padding-bottom: 20px;background: #2a394f;}	.msgBody .content{width: 100%;padding-top: 80px;padding-bottom: 80px;text-align: center;}
.msgBody .content .btn{width: 40%;margin-left: 30%;height: 30px;line-height: 30px;font-size: 18px;color: #fff;background: #0fa8f4;border-radius: 7px;cursor: pointer;padding-top: 20px;padding-bottom: 20px;text-align: center;margin-top: 40px;}
.msgBody .content a{text-decoration: none;}
</style>
<div class="msgBody">
  <div class="header">
    <img src="http://domain.ru/img/logo.png" style="width: 30%; height: auto; margin-left: 35%;">		
  </div>
  <div class="content">
    '.$name.', здравствуйте!<br>
    Для активации нажмите на кнопку ниже:<br>
    <a href="http://domain.ru/activate.php?key='.$key.'&l='.$phone.'"><div class="btn">Активировать аккаунт</div></a>
  </div>
</div>';
          $mail=convert_cyr_string($mail,"w","k");
          $hed="Content-Type: text/html; charset=KOI8-R;
          From: infoMail<[email protected]>;
          To: Клиент;
          Subject: Активация;
          Content-Type: text/html; charset=KOI8-R";
          $hed=convert_cyr_string($hed,"w","k");					 
          mail("[email protected]","Активация",$mail,$hed);

?>

I send to KOI8-R, but krakozyabry comes

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Rsa97, 2018-03-13
@borgore

According to the standard, only characters from the main ASCII set (0x00-0x7F) should be used in email headers. All other characters must be encoded.
If the letter contains an HTML part, then it is highly desirable to add a PLAIN part corresponding to the text. The letter type must be multipart/alternative.
If these conditions are not observed, the probability of getting the letter into spam increases sharply.
It is better to use UTF-8 as the most universal encoding.

$fromName = "=?UTF-8?B?" . base64_encode($fromName) . "?=";
$toName = "=?UTF-8?B?" . base64_encode($toName) . "?=";
$subject = "=?UTF-8?B?" . base64_encode($subject) . "?=";
$boundary = md5(rand());
$headers = "From: {$fromName} <${fromEmail}>\r\n".
           "MIME-Version: 1.0\r\n" .
           "Content-type: multipart/alternative; boundary={$boundary}\r\n"; 
$message = "\r\n--{$boundary}\r\n" .
           "Content-Type: text/plain; charset=UTF-8\r\n\r\n" .
           $plainMessage .
           "\r\n--{$boundary}\r\n" .
           "Content-Type: text/html; charset=UTF-8\r\n\r\n" .
           $htmlMessage .
           "\r\n--{$boundary}--\r\n";
mail("{$toName} <{$toEmail}>", $subject, $message, $headers);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question