A
A
AntonGoretskiy2014-09-18 17:45:46
Zend Framework
AntonGoretskiy, 2014-09-18 17:45:46

Zf2 how to fix encoding issue when sending Zend\Mail\Message?

I send a message like this:

$body = 'тест';
        $textPart = new MimePart($body);
        $textPart->type = "text/html";
        $textPart->encoding = Zend\Mime\Mime::ENCODING_BASE64;
        $body = new MimeMessage();
        $body->setParts(array($textPart));
       
        $message = new \Zend\Mail\Message();
        $message->setFrom('[email protected]');
        $message->addTo('[email protected]');
        $message->setSubject('Получен новый');
        $message->setEncoding('UTF-8');
        $message->setBody($body);
        $smtpOptions = new \Zend\Mail\Transport\SmtpOptions();

        $smtpOptions->setHost('smtp.gmail.com')
                    ->setConnectionClass('login')
                    ->setName('smtp.gmail.com')
                    ->setConnectionConfig(array(
                                       'username' => '',
                                       'password' => '',
                                       'ssl' => 'tls',
                                     )
                          );

        $transport = new \Zend\Mail\Transport\Smtp($smtpOptions);
        $transport->send($message);

In this case, the text of the message "test" is displayed as "Q P5Q Q", and everything is fine in the subject.
Thanks in advance

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
AntonGoretskiy, 2014-09-18
@AntonGoretskiy

$headers = $message->getHeaders();
        $headers->removeHeader('Content-Type');
        $headers->addHeaderLine('Content-Type', 'text/html; charset=UTF-8');

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question