P
P
psiklop2020-07-06 02:13:58
PHPMailer
psiklop, 2020-07-06 02:13:58

Phpmailer krakozyabry instead of Cyrillic?

Such letters come, the letter is in UTF-8
.

I use Phpmailer with SMTP sending, as the mail function flies into spam.
Googled and tried everything to no avail.

$mail = new PHPMailer(true);

    try {			
      $mail->charSet = "UTF-8";
      $mail->isSMTP();
      $mail->Host = 'ssl://smtp.yandex.ru';
      $mail->SMTPAuth = true;
      $mail->Username = $mail_settings["smtp"]["login"];
      $mail->Password = $mail_settings["smtp"]["pass"];
      $mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS;
      $mail->Port = 465;
      
      $mail->setFrom($shop_email, $shortshopname);
      $mail->addAddress($email);
      $mail->addReplyTo($reply, $reply_a);

      $mail->isHTML(true);
      $mail->Subject = $theme;
      $mail->Body = $body;
      $text = \Soundasleep\Html2Text::convert($body, array('ignore_errors' => true));
      $mail->AltBody = $text;

      if ($mail->send()) $response = true;
    } catch (Exception $e) {}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
psiklop, 2020-07-11
@psiklop

I wrote my own function that translates Cyrillic into HTML codes, while I use it this way

$mail->Subject = "=?UTF-8?B?".base64_encode($theme)."?=";
$mail->Body = func_сyrillic_html_encode($body);

function func_сyrillic_html_encode($text)  {
  $patterns = preg_split("/(?<!^)(?!$)/u", "АБВГДЕЖЗИЙКЛМНОПРСТУФХЦЧШЩЪЫЬЭЮЯабвгдежзийклмнопрстуфхцчшщъыьэюя");
  $html = array();
  foreach ($patterns as $i => $letter) {
    $patterns[$i] = "/$letter/u";
    $html[] = "&#".($i+1040).";";
  }		
  return preg_replace($patterns, $html, $text);
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question