E
E
EVOSandru62015-04-03 12:57:48
Yii
EVOSandru6, 2015-04-03 12:57:48

Where in Yii PHPMailer class to set headers?

Good afternoon,
Where is the encoding set in this class?
There is this snippet:

$from = '[email protected]';
                $body =
                    "\n\n\t Фирма: ".$model->firm . '<br>'
                    ."\n\n\t Город: ".$model->city . '<br>'
                    ."\n\n\t Телефон: ".$model->phone .'<br>'
                    ."\n\n\t Контактное лицо: ".$model->name .'<br>'
                    ."\n\n\t Email: ".$model->email;
                $body = "=?utf-8?B?".base64_encode($body)."?=";
                $subject = "=?utf-8?B?".base64_encode('Запрос прайс-листа oт '.$model->name)."?="; // Кодируем тему (во избежание проблем с кодировкой)

// тут в цикле отправляю email на необходимые адреса
foreach(Yii::app()->params['email'] as $key => $email){
       //mail($email, $subject, $body, $headers);
       My::mailsend($email, $from ,$subject,$body);
        }

My::mailsend() method:
static function mailsend($to,$from,$subject,$message){
        $mail=Yii::app()->Smtpmail;
        $mail->SetFrom($from, 'FirmaName');
        $mail->Subject = $subject;
        $mail->MsgHTML($message);
        $mail->AddAddress($to, "");
        if(!$mail->Send()) 
            echo "Mailer Error: " . $mail->ErrorInfo;
    }

After sending the data from the form, a letter with the correct encoding for Subject comes to the mail , and here is the body (the text of the letter) : : test Email : [email protected] Slavic letters are displayed incorrectly. How can this be fixed? I used to use a simple mail () function, but hosting has new standards, you need to go through smtp authorization. In the first case, headers with encoding and the rest were passed to the mail() function. Tried to encode $body like done with $subject. In this case, the following text arrives:



=? Utf-8? B? CgoJINCk0LjRgNC80LA6IHRlc3Q8YnI + CgoJINCT0L7RgNC + 0LQ6IHRlc3Q8YnI + CgoJINCi0LXQu9C10YTQvtC9OiB0ZXN0PGJyPgoKCSDQmtC + 0L3RgtCw0LrRgtC90L7QtSDQu9C40YbQvjogdGVzdDxicj4KCgkgRW1haWw6IHRlc3RAdGVzdC5reg ==? =

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Evgeny Dozhdikov, 2015-04-03
@EVOSandru6

If this is your PHPMAiler, then you don't need to base64-encode body and subject yourself.
https://github.com/PHPMailer/PHPMailer

$mail->CharSet = 'UTF-8'; // Кодировка текста
$mail->Encoding = 'base64'; // в каком виде передавать сообщение, оно само закодирует base64 по правилам.
$mail->addCustomHeader($header . ':' . $value); // Добавление своего заголовка

Do all these machinations in the static function mailsend

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question