当前位置: 首页>>代码示例>>PHP>>正文


PHP Message::getBody方法代码示例

本文整理汇总了PHP中Zend\Mail\Message::getBody方法的典型用法代码示例。如果您正苦于以下问题:PHP Message::getBody方法的具体用法?PHP Message::getBody怎么用?PHP Message::getBody使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Zend\Mail\Message的用法示例。


在下文中一共展示了Message::getBody方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: render

 /**
  * @param Message $message
  * @return Message
  */
 public function render(Message $message)
 {
     $viewModel = new ViewModel($this->variables);
     $viewModel->setTemplate($this->template);
     $helperPluginManager = $this->renderer->getHelperPluginManager();
     /** @var HeadTitle $helper */
     $helper = $helperPluginManager->get('HeadTitle');
     // replace headTitle
     $headTitle = new HeadTitle();
     $headTitle->setAutoEscape(false);
     $helperPluginManager->setAllowOverride(true);
     $helperPluginManager->setService('HeadTitle', $headTitle);
     if (!$message->getBody()) {
         $message->setBody(new MimeMessage());
     }
     $text = new Part($this->renderer->render($viewModel));
     $text->charset = 'UTF-8';
     $text->boundary = $message->getBody()->getMime()->boundary();
     $text->encoding = Mime::ENCODING_BASE64;
     $text->type = Mime::TYPE_HTML;
     $message->getBody()->addPart($text);
     $message->setSubject($headTitle->renderTitle());
     // hack for ZF
     $message->setBody($message->getBody());
     // restore original helper
     $helperPluginManager->setService('HeadTitle', $helper);
     return $message;
 }
开发者ID:enlitepro,项目名称:enlite-mail,代码行数:32,代码来源:Template.php

示例2: injectFiles

 /**
  * Inject files to message
  *
  * @param Message $message
  * @param array $files Paths to files
  */
 public function injectFiles(Message $message, $files)
 {
     foreach ($files as $file) {
         $attachment = new Part(fopen($file, 'r'));
         $attachment->type = mime_content_type($file);
         $attachment->encoding = Mime::ENCODING_BASE64;
         $attachment->disposition = Mime::DISPOSITION_ATTACHMENT;
         $attachment->filename = basename($file);
         $attachment->boundary = $message->getBody()->getMime()->boundary();
         $message->getBody()->addPart($attachment);
     }
     // hack for ZF
     $message->setBody($message->getBody());
 }
开发者ID:enlitepro,项目名称:enlite-mail,代码行数:20,代码来源:MailService.php

示例3: send

 /**
  * Send a mail message
  *
  * @param Mail\Message $message
  * @return array
  */
 public function send(Mail\Message $message)
 {
     $this->getMandrillClient();
     $body = $message->getBody();
     $attachments = [];
     switch (true) {
         case $body instanceof Message:
             $bodyHtml = $this->getHtmlPart($body);
             $bodyText = $this->getTextPart($body);
             $attachments = $this->getAttachments($body);
             break;
         case is_string($body):
             $bodyHtml = $body;
             $bodyText = $message->getBodyText();
             break;
         case is_object($body):
             $bodyHtml = $body->__toString();
             $bodyText = $message->getBodyText();
             break;
         default:
             throw new Exception\InvalidArgumentException(sprintf('"%s" expectes a body that is a string, an object or a Zend\\Mime\\Message; received "%s"', __METHOD__, is_object($body) ? get_class($body) : gettype($body)));
             break;
     }
     $message = ['html' => $bodyHtml, 'text' => $bodyText, 'subject' => $message->getSubject(), 'from_email' => $message->getFrom()->current()->getEmail(), 'from_name' => $message->getFrom()->current()->getName(), 'to' => array_merge($this->mapAddressListToArray($message->getTo(), 'to'), $this->mapAddressListToArray($message->getCc(), 'cc'), $this->mapAddressListToArray($message->getBcc(), 'bcc')), 'headers' => $message->getHeaders()->toArray(), 'subaccount' => $this->options->getSubAccount(), 'attachments' => $attachments];
     return $this->mandrillClient->messages->send($message);
 }
开发者ID:ripaclub,项目名称:zf2-mailman,代码行数:32,代码来源:Mandrill.php

示例4: send

 public function send(SmtpTransport $transport = null, Message $message, array $attachments = array())
 {
     if ($transport == null) {
         $transport = new Sendmail();
     }
     $content = $message->getBody();
     $parts = $attachments;
     $parts = array();
     $bodyMessage = new \Zend\Mime\Message();
     $multiPartContentMessage = new \Zend\Mime\Message();
     $text = new Part(html_entity_decode(strip_tags(str_replace("<br />", "\n", $content))));
     $text->type = "text/plain";
     $text->encoding = Mime::ENCODING_QUOTEDPRINTABLE;
     $text->charset = 'UTF-8';
     $multiPartContentMessage->addPart($text);
     $html = new Part($content);
     $html->type = Mime::TYPE_HTML;
     $html->encoding = Mime::ENCODING_QUOTEDPRINTABLE;
     $html->charset = 'utf-8';
     $multiPartContentMessage->addPart($html);
     $multiPartContentMimePart = new Part($multiPartContentMessage->generateMessage());
     $multiPartContentMimePart->type = 'multipart/alternative;' . PHP_EOL . ' boundary="' . $multiPartContentMessage->getMime()->boundary() . '"';
     $bodyMessage->addPart($multiPartContentMimePart);
     foreach ($attachments as $attachment) {
         $bodyMessage->addPart($attachment);
     }
     $message->setBody($bodyMessage);
     $message->setEncoding("UTF-8");
     $transport->send($message);
 }
开发者ID:kristjanAnd,项目名称:SimpleIV,代码行数:30,代码来源:MailService.php

示例5: addAttachment

 function addAttachment($data, $filename, $mimetype)
 {
     $body = $this->mail->getBody();
     if (!$body instanceof \Zend\Mime\Message) {
         $this->convertBodyToMime($body);
         $body = $this->mail->getBody();
     }
     $attachment = new Zend\Mime\Part($data);
     $attachment->setFileName($filename);
     $attachment->setType($mimetype);
     $attachment->setEncoding(Zend\Mime\Mime::ENCODING_BASE64);
     $attachment->setDisposition(Zend\Mime\Mime::DISPOSITION_INLINE);
     $body->addPart($attachment);
 }
开发者ID:rjsmelo,项目名称:tiki,代码行数:14,代码来源:tikimaillib.php

示例6: attachFiles

 /**
  * Attaches files to the message if any
  */
 private function attachFiles()
 {
     if (count($this->attachments) === 0) {
         return;
     }
     // Get old message parts
     $mimeMessage = $this->message->getBody();
     if (is_string($mimeMessage)) {
         $originalBodyPart = new Mime\Part($mimeMessage);
         $originalBodyPart->type = $mimeMessage != strip_tags($mimeMessage) ? Mime\Mime::TYPE_HTML : Mime\Mime::TYPE_TEXT;
         // A Mime\Part body will be wraped into a Mime\Message, ensuring we handle a Mime\Message after this point
         $this->setBody($originalBodyPart);
         $mimeMessage = $this->message->getBody();
     }
     $oldParts = $mimeMessage->getParts();
     // Generate a new Mime\Part for each attachment
     $attachmentParts = [];
     $info = new \finfo(FILEINFO_MIME_TYPE);
     foreach ($this->attachments as $key => $attachment) {
         if (!is_file($attachment)) {
             continue;
             // If checked file is not valid, continue to the next
         }
         // If the key is a string, use it as the attachment name
         $basename = is_string($key) ? $key : basename($attachment);
         $part = new Mime\Part(fopen($attachment, 'r'));
         $part->id = $basename;
         $part->filename = $basename;
         $part->type = $info->file($attachment);
         $part->encoding = Mime\Mime::ENCODING_BASE64;
         $part->disposition = Mime\Mime::DISPOSITION_ATTACHMENT;
         $attachmentParts[] = $part;
     }
     $body = new Mime\Message();
     $body->setParts(array_merge($oldParts, $attachmentParts));
     $this->message->setBody($body);
 }
开发者ID:WasabiLib,项目名称:Mail,代码行数:40,代码来源:Mail.php

示例7: testMaySetNullBody

 public function testMaySetNullBody()
 {
     $this->message->setBody(null);
     $this->assertNull($this->message->getBody());
 }
开发者ID:nuklehed,项目名称:zf2,代码行数:5,代码来源:MessageTest.php

示例8: extractAttachments

 /**
  * Extract all attachments from a message
  *
  * Attachments are detected in the Mime message where
  * the type of the mime part is not text/plain or
  * text/html.
  *
  * @param  Message $message
  * @return \Zend\Mime\Part[]|array
  */
 protected function extractAttachments(Message $message)
 {
     $body = $message->getBody();
     // If body is not a MimeMessage object, then the body is just the text version
     if (is_string($body) || !$body instanceof MimeMessage) {
         return array();
     }
     $filter = array('text/plain', 'text/html');
     $attachments = array();
     foreach ($body->getParts() as $part) {
         if (!in_array($part->type, $filter) || $part->disposition === Mime::DISPOSITION_ATTACHMENT) {
             $attachments[] = $part;
         }
     }
     return $attachments;
 }
开发者ID:erik-maas,项目名称:SlmMail,代码行数:26,代码来源:AbstractMailService.php

示例9: __construct

 /**
  * @param MailMessage $message
  */
 public function __construct(MailMessage $message)
 {
     $this->message = $message;
     $this->textBody = $message->getBody();
 }
开发者ID:bix0r,项目名称:Stjornvisi,代码行数:8,代码来源:Attacher.php

示例10: grabMatchesFromEmail

 /**
  * Grab From Email
  *
  * Return the matches of a regex against the raw email
  *
  * @return void
  * @author Koen Punt
  **/
 protected function grabMatchesFromEmail(Message $email, $regex)
 {
     preg_match($regex, $email->getBody(), $matches);
     $this->assertNotEmpty($matches, "No matches found for {$regex}");
     return $matches;
 }
开发者ID:fetch,项目名称:zend-mail-codeception-module,代码行数:14,代码来源:ZendMail.php

示例11: send

 public function send(Message $message, array $attachments = array())
 {
     if ($this->getConfiguration()->getSendAllMailsToBcc() !== null) {
         $message->addBcc($this->getConfiguration()->getSendAllMailsToBcc());
     }
     if ($this->getConfiguration()->getSendAllMailsTo() != null) {
         $message->setTo($this->getConfiguration()->getSendAllMailsTo());
     }
     $content = $message->getBody();
     $bodyMessage = new \Zend\Mime\Message();
     $multiPartContentMessage = new \Zend\Mime\Message();
     $text = new Part(strip_tags($content));
     $text->type = Mime::TYPE_TEXT;
     $text->encoding = Mime::ENCODING_QUOTEDPRINTABLE;
     $multiPartContentMessage->addPart($text);
     $html = new Part($content);
     $html->type = Mime::TYPE_HTML;
     $html->encoding = Mime::ENCODING_QUOTEDPRINTABLE;
     $html->charset = 'utf-8';
     $multiPartContentMessage->addPart($html);
     $multiPartContentMimePart = new Part($multiPartContentMessage->generateMessage());
     $multiPartContentMimePart->charset = 'UTF-8';
     $multiPartContentMimePart->type = 'multipart/alternative';
     $multiPartContentMimePart->boundary = $multiPartContentMessage->getMime()->boundary();
     $bodyMessage->addPart($multiPartContentMimePart);
     foreach ($attachments as $attachment) {
         $bodyMessage->addPart($attachment);
     }
     $message->setBody($bodyMessage);
     $message->setEncoding("UTF-8");
     $this->transport->send($message);
 }
开发者ID:bitweb,项目名称:mail,代码行数:32,代码来源:MailService.php

示例12: getBodyHash

 /**
  * Get Message body (sha1) hash.
  *
  * @param Message $message
  * @return string
  */
 private function getBodyHash(Message $message)
 {
     return base64_encode(pack("H*", sha1($message->getBody())));
 }
开发者ID:fastnloud,项目名称:zf2-dkim,代码行数:10,代码来源:Signer.php

示例13: convertZFMail

 /**
  * Create `Mandrill message` from `ZF message`.
  *
  * @param ZendMessage $zfMessage
  *
  * @return Message
  */
 public static function convertZFMail(ZendMessage $zfMessage)
 {
     $mandrillMessage = new self();
     // GET HTML MIME PART
     $messageHtmlPart = $messageTextPart = null;
     $mimeParts = $zfMessage->getBody()->getParts();
     foreach ($mimeParts as $mimePart) {
         switch ($mimePart->getType()) {
             case ZendMime::TYPE_HTML:
                 $messageHtmlPart = $mimePart->getContent();
                 break;
             case ZendMime::TYPE_TEXT:
                 $messageTextPart = $mimePart->getContent();
                 break;
         }
     }
     // text part
     if ($messageTextPart !== null) {
         $mandrillMessage->text = $messageTextPart;
     }
     // html part
     if ($messageHtmlPart !== null) {
         $mandrillMessage->html = $messageHtmlPart;
     }
     // subject
     if ($zfMessage->getSubject() !== null) {
         $mandrillMessage->subject = $zfMessage->getSubject();
     }
     // from
     if ($zfMessage->getFrom()->count()) {
         $mandrillMessage->from_email = $zfMessage->getFrom()->current()->getEmail();
         $mandrillMessage->from_name = $zfMessage->getFrom()->current()->getName();
     }
     // reply-to
     if ($zfMessage->getReplyTo()->count()) {
         $mandrillMessage->headers = ['Reply-To' => $zfMessage->getReplyTo()->current()->getEmail()];
     }
     // to
     if ($zfMessage->getTo()->count()) {
         foreach ($zfMessage->getTo() as $to) {
             $mandrillMessage->addRecipient(new Recipient($to->getEmail(), null, Recipient::RECIPIENT_TYPE_TO));
         }
     }
     // cc
     if ($zfMessage->getCc()->count()) {
         foreach ($zfMessage->getCc() as $cc) {
             $mandrillMessage->addRecipient(new Recipient($cc->getEmail(), null, Recipient::RECIPIENT_TYPE_CC));
         }
     }
     // bcc
     if ($zfMessage->getBcc()->count()) {
         foreach ($zfMessage->getBcc() as $bcc) {
             $mandrillMessage->addRecipient(new Recipient($bcc->getEmail(), null, Recipient::RECIPIENT_TYPE_BCC));
         }
     }
     return $mandrillMessage;
 }
开发者ID:freax,项目名称:mandrill-zend2,代码行数:64,代码来源:Message.php


注:本文中的Zend\Mail\Message::getBody方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。