Exemple #1
0
 public function testProvidingParametersIntroducesHeaderFolding()
 {
     $header = new ContentType();
     $header->setType('application/x-unit-test');
     $header->addParameter('charset', 'us-ascii');
     $string = $header->toString();
     $this->assertContains("Content-Type: application/x-unit-test;\r\n", $string);
     $this->assertContains(";\r\n charset=\"us-ascii\"", $string);
 }
Exemple #2
0
 /**
  * Get a blank email message object.
  *
  * @return Message
  */
 public function getNewMessage()
 {
     $message = new Message();
     $message->setEncoding('UTF-8');
     $headers = $message->getHeaders();
     $ctype = new ContentType();
     $ctype->setType('text/plain');
     $ctype->addParameter('charset', 'UTF-8');
     $headers->addHeader($ctype);
     return $message;
 }
 /**
  * @param string $subject
  * @param string $plain
  * @param string $html
  * @param string $messageId
  *
  * @return \Zend\Mail\Message
  */
 public function createMessage($subject, $plain, $html, $messageId)
 {
     $mail = $this->getMessageClass();
     $mail->setFrom(\Yii::$app->params['mailFromEmail'], \Yii::$app->params['mailFromName']);
     $mail->setSubject($subject);
     $mail->setEncoding('UTF-8');
     $mId = new \Zend\Mail\Header\MessageId();
     $mId->setId($messageId);
     $mail->getHeaders()->addHeader($mId);
     if ($html == '') {
         $mail->setBody($plain);
         $content = new \Zend\Mail\Header\ContentType();
         $content->setType('text/plain');
         $content->addParameter('charset', 'UTF-8');
         $mail->getHeaders()->addHeader($content);
     } else {
         $html = '<!DOCTYPE html><html>
         <head><meta charset="utf-8"><title>' . Html::encode($subject) . '</title>
         </head><body>' . $html . '</body></html>';
         $converter = new \TijsVerkoyen\CssToInlineStyles\CssToInlineStyles($html);
         $converter->setStripOriginalStyleTags(true);
         $converter->setUseInlineStylesBlock(true);
         $converter->setEncoding('UTF-8');
         $converter->setCleanup(false);
         $converter->setExcludeMediaQueries(true);
         $contentHtml = $converter->convert();
         $contentHtml = preg_replace("/ data\\-[a-z0-9_-]+=\"[^\"]*\"/siu", "", $contentHtml);
         $textPart = new \Zend\Mime\Part($plain);
         $textPart->type = 'text/plain';
         $textPart->charset = 'UTF-8';
         $htmlPart = new \Zend\Mime\Part($contentHtml);
         $htmlPart->type = 'text/html';
         $htmlPart->charset = 'UTF-8';
         $mimem = new \Zend\Mime\Message();
         $mimem->setParts([$textPart, $htmlPart]);
         $mail->setBody($mimem);
         /** @var ContentType $contentType */
         $contentType = $mail->getHeaders()->get('content-type');
         $contentType->setType('multipart/alternative');
     }
     return $mail;
 }