S
S
Sergey Baharev2016-11-23 00:07:49
PHP
Sergey Baharev, 2016-11-23 00:07:49

Why is the message encoding incorrect?

I use this code to send letters, but no matter how I change the text encoding, the body of the letter looks like a set of incomprehensible characters.
mailer class - here

require_once 'class.phpmailer.php';
    $subject = iconv(mb_detect_encoding($subject), 'windows-1251 , $subject);
    $body = iconv(mb_detect_encoding($body), 'windows-1251', $body);
    $subject = '=?windows-1251?B?' . base64_encode($subject) . '?=';
    $mail = new PHPMailer();
    $mail->isSMTP();
    $mail->Host = "mx1.hostinger.ru";
    $mail->SMTPDebug = 2;
    $mail->SMTPAuth = true;
    $mail->Port = порт;
    $mail->Username = "юзер";
    $mail->Password = "пароль";
    $mail->setFrom(($noreply ? 'noreply' : 'mail') . '@мой домен', 'ля ля ля');
    $mail->addReplyTo("мой адрес", "Ля ля ля");
    $mail->Subject = $subject;
    $mail->AltBody = "В письме используется HTML!";
    $mail->msgHTML($body);
    foreach ($users as $user) {
        $mail->addAddress($user);
    }
    if (!$mail->send()) {
        return "Ошибка: " . $mail->ErrorInfo;
    } else {
        return "Отослано!";
    }

Answer the question

In order to leave comments, you need to log in

3 answer(s)
S
Sergey Baharev, 2016-11-24
@Sergey-Dertan

Decided: the top class has the Encoding property, my IDE is case sensitive, so don't suggest it.

D
d-virt, 2016-11-23
@d-virt

Well, if you pay attention to the first two lines, namely here:
Then it follows that you are trying to convert to this encoding:
String concatenation

V
Vladimir Dubrovin, 2016-11-23
@z3apa3a

The text and HTML parts must have a Content-Type with the appropriate encoding, such as
Content-Type: text/html; charset="windows-1251"
most likely, your text encoding (windows-1251) does not match the encoding specified in the title of the corresponding part.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question