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


PHP Message::addPart方法代码示例

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


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

示例1: send

 public function send($subject, $text, $to, $from = null)
 {
     if (!config('mail.enabled')) {
         return;
     }
     $message = new Message();
     $message->setSubject($subject);
     if ($from) {
         if (is_array($from)) {
             $message->setFrom($from[0], $from[1]);
         } else {
             $message->setFrom($from);
         }
     }
     $message->addTo($to);
     $content = '<html><head><title>' . $subject . '</title></head><body>' . $text . '</body></html>';
     $html = new Mime\Part($content);
     $html->setType(Mime\Mime::TYPE_HTML);
     $html->setCharset('utf-8');
     $mimeMessage = new Mime\Message();
     $mimeMessage->addPart($html);
     foreach ($this->attachments as $attachment) {
         $mimeMessage->addPart($attachment);
     }
     $message->setBody($mimeMessage);
     try {
         $transport = new SmtpTransport(new SmtpOptions(config('mail.options')));
         $transport->send($message);
     } catch (\Exception $e) {
         throw $e;
     }
     return $this;
 }
开发者ID:control-corp,项目名称:brands,代码行数:33,代码来源:Mail.php

示例2: generateBody

 /**
  * Generates the Mail Body
  */
 protected function generateBody()
 {
     $message = new Mime\Message();
     $text = $this->generateHtml();
     $textPart = new Mime\Part($text);
     $textPart->type = 'text/html';
     $textPart->charset = 'UTF-8';
     $textPart->disposition = Mime\Mime::DISPOSITION_INLINE;
     $message->addPart($textPart);
     if (isset($this->application->getContact()->image) && $this->application->getContact()->getImage()->id) {
         /* @var $image \Auth\Entity\UserImage */
         $image = $this->application->getContact()->getImage();
         $part = new Mime\Part($image->getResource());
         $part->type = $image->type;
         $part->encoding = Mime\Mime::ENCODING_BASE64;
         $part->filename = $image->name;
         $part->disposition = Mime\Mime::DISPOSITION_ATTACHMENT;
         $message->addPart($part);
     }
     foreach ($this->application->getAttachments() as $attachment) {
         /* @var $part \Applications\Entity\Attachment */
         $part = new Mime\Part($attachment->getResource());
         $part->type = $attachment->type;
         $part->encoding = Mime\Mime::ENCODING_BASE64;
         $part->filename = $attachment->name;
         $part->disposition = Mime\Mime::DISPOSITION_ATTACHMENT;
         $message->addPart($part);
     }
     $this->setBody($message);
 }
开发者ID:utrenkner,项目名称:YAWIK,代码行数:33,代码来源:Forward.php

示例3: generateBody

 protected function generateBody()
 {
     $message = new Mime\Message();
     $text = $this->generateText();
     $textPart = new Mime\Part($text);
     $textPart->type = 'text/plain';
     $textPart->charset = 'UTF-8';
     $textPart->disposition = Mime\Mime::DISPOSITION_INLINE;
     $message->addPart($textPart);
     if (isset($this->application->contact->image) && $this->application->contact->image->id) {
         $image = $this->application->contact->image;
         $part = new Mime\Part($image->getResource());
         $part->type = $image->type;
         $part->encoding = Mime\Mime::ENCODING_BASE64;
         $part->filename = $image->name;
         $part->disposition = Mime\Mime::DISPOSITION_ATTACHMENT;
         $message->addPart($part);
     }
     foreach ($this->application->attachments as $attachment) {
         $part = new Mime\Part($attachment->getResource());
         $part->type = $attachment->type;
         $part->encoding = Mime\Mime::ENCODING_BASE64;
         $part->filename = $attachment->name;
         $part->disposition = Mime\Mime::DISPOSITION_ATTACHMENT;
         $message->addPart($part);
     }
     $this->setBody($message);
 }
开发者ID:bitrecruiter,项目名称:CrossApplicantManager,代码行数:28,代码来源:Forward.php

示例4: packData

 /**
  * pack tagged array of data to SendMessage format
  *
  *
  * @param Array $mailArray
  *
  * return array of data that will be converted to
  * send message
  *
  * @return Array
  */
 public function packData($mailArray)
 {
     $mimeMail = new Message();
     $textPart = $this->packText($mailArray['text'], $mailArray['header']['content-type']);
     unset($mailArray['header']['content-type']);
     $attachmentParts = $this->packAttachments($mailArray['link']);
     if (count($attachmentParts)) {
         $mimeMail->addPart($textPart);
         foreach ($attachmentParts as $part) {
             $mimeMail->addPart($part);
         }
     } else {
         $mimeMail->addPart($textPart);
     }
     $returnMail = new SendMessage();
     $returnMail->setBody($mimeMail);
     foreach ($mailArray['header'] as $header => $value) {
         switch ($header) {
             case 'references':
                 if (is_array($value)) {
                     $res = '';
                     foreach ($value as $reference) {
                         $res .= $reference . ' ';
                     }
                 } elseif (is_string($value)) {
                     $res = $value;
                 } else {
                     continue;
                 }
                 $headers = $returnMail->getHeaders();
                 $headers->addHeaderLine($header, $res);
                 $returnMail->setHeaders($headers);
                 break;
             case 'bcc':
                 $returnMail->addBcc($value);
                 break;
             case 'cc':
                 $returnMail->addCc($value);
                 break;
             case 'to':
                 $returnMail->addTo($value);
                 break;
             case 'from':
                 $returnMail->addFrom($value);
                 break;
             case 'reply-to':
                 $returnMail->addReplyTo($value);
                 break;
             case 'subject':
                 $returnMail->setSubject($value);
                 break;
             default:
                 $headers = $returnMail->getHeaders();
                 $headers->addHeaderLine($header, $value);
                 $returnMail->setHeaders($headers);
                 break;
         }
     }
     return $returnMail;
 }
开发者ID:modelframework,项目名称:mailservice,代码行数:71,代码来源:DefaultComposeStrategy.php

示例5: createMessage

 /**
  * @param RenderableMailInterface $mail
  *
  * @return Mime\Message
  */
 public function createMessage(RenderableMailInterface $mail)
 {
     $content = $this->getMailBody($mail);
     $message = new Mime\Message();
     $message->addPart($content);
     foreach ($mail->getAttachments() as $name => $file) {
         $attachment = $this->createAttachment($file, $name);
         $message->addPart($attachment);
     }
     return $message;
 }
开发者ID:phpro,项目名称:zf-mail-manager,代码行数:16,代码来源:MailMessageCreator.php

示例6: generate

 public function generate(TemplateInterface $template) : MimeMessage
 {
     $mimeMessage = new MimeMessage();
     $textTemplate = $template->getTextTemplate();
     if ($textTemplate) {
         $textMimePart = $this->createTextMimePart($textTemplate, $template->getParams());
         $mimeMessage->addPart($textMimePart);
     }
     $htmlTemplate = $template->getHtmlTemplate();
     if ($htmlTemplate) {
         $htmlMimePart = $this->createHtmlMimePart($htmlTemplate, $template->getParams());
         $mimeMessage->addPart($htmlMimePart);
     }
     return $mimeMessage;
 }
开发者ID:RiskioFr,项目名称:Mailer,代码行数:15,代码来源:BodyGenerator.php

示例7: send

 protected function send()
 {
     try {
         $message = new Message();
         $para = array_filter(explode(";", str_replace(array(" ", ","), array("", ";"), $this->dados["para"])));
         $message->addTo($para)->addFrom($this->dados["de"]["email"], $this->dados["de"]["nome"])->setSubject($this->dados["assunto"])->addReplyTo($this->dados["replay"]);
         $transport = new SmtpTransport();
         $options = new SmtpOptions(array('host' => 'mail.pessoaweb.com.br', 'connection_class' => 'login', 'connection_config' => array('username' => 'dispatch@pessoaweb.com.br', 'password' => 'd1i2s3p4atch'), 'port' => 587));
         $html = new MimePart($this->dados["body"]);
         $html->type = "text/html";
         $html->charset = "UTF-8";
         $body = new MimeMessage();
         if (isset($this->dados["attachment"])) {
             foreach ($this->dados["attachment"] as $valor) {
                 $attachment = new MimePart($valor["arquivo"]);
                 $attachment->filename = $valor["titulo"];
                 if (isset($valor["tipo"])) {
                     $attachment->type = $valor["tipo"];
                 }
                 $attachment->disposition = Mime::DISPOSITION_ATTACHMENT;
                 $attachment->encoding = Mime::ENCODING_BASE64;
                 $body->setParts(array($attachment));
             }
         }
         $body->addPart($html);
         $message->setBody($body);
         $transport->setOptions($options);
         $transport->send($message);
         return $transport;
     } catch (\Exception $e) {
         debug(array("email" => $e->getMessage()), true);
     }
 }
开发者ID:bhcosta90,项目名称:zend,代码行数:33,代码来源:EmailAbstract.php

示例8: testInvoke

 public function testInvoke()
 {
     $repository = $this->prophesize(RepositoryInterface::class);
     $listener = new LogSending($repository->reveal());
     $event = $this->prophesize(EventInterface::class);
     $message = $this->prophesize(Message::class);
     $event->getParam('message')->willReturn($message->reveal());
     $template = $this->prophesize(Template::class);
     $event->getParam('template')->willReturn($template->reveal());
     $to = new AddressList();
     $to->addFromString('reciever@mail.com');
     $message->getTo()->willReturn($to);
     $from = new AddressList();
     $from->addFromString('sender@mail.com');
     $message->getFrom()->willReturn($from);
     $message->getSubject()->willReturn('Some subject');
     $template->getLayoutId()->willReturn(Template::LAYOUT_DEFAULT);
     $template->getId()->willReturn(Template::FEEDBACK_ANSWER);
     $mimeMessage = new MimeMessage();
     $mimeMessage->addPart(new \Zend\Mime\Part('some body'));
     $message->getBody()->willReturn($mimeMessage);
     $event->getParam('data')->willReturn(['data' => 'x']);
     $repository->add(Argument::type(MailLogEntry::class));
     $listener->__invoke($event->reveal());
 }
开发者ID:t4web,项目名称:mail,代码行数:25,代码来源:LogSendingTest.php

示例9: sendMail

 public function sendMail($mailOptions = array())
 {
     $this->_setMailOptions($mailOptions);
     $text = new Part($this->mailBody);
     $text->type = Mime::TYPE_HTML;
     $mailBodyParts = new MimeMessage();
     $mailBodyParts->addPart($text);
     if (!empty($this->fileNames) && !empty($this->filePaths)) {
         foreach ($this->filePaths as $key => $filePath) {
             $file = new Part(file_get_contents($filePath));
             $file->encoding = Mime::ENCODING_BASE64;
             $file->type = finfo_file(finfo_open(), $filePath, FILEINFO_MIME_TYPE);
             $file->disposition = Mime::DISPOSITION_ATTACHMENT;
             $file->filename = $this->fileNames[$key];
             $mailBodyParts->addPart($file);
         }
     }
     $options = array();
     if ($this->useSMTP === false) {
         $options = new SmtpOptions(array("name" => $this->smtpName, "host" => $this->smtpHost, "port" => $this->smtpPort));
     } else {
         $options = new SmtpOptions(array('name' => $this->smtpName, 'host' => $this->smtpHost, 'port' => $this->smtpPort, 'connection_class' => $this->smtpConnectionClass, 'connection_config' => array('ssl' => $this->smtpSsl, 'username' => $this->smtpUsername, 'password' => $this->smtpPassword)));
     }
     $mail = new Message();
     $mail->setBody($mailBodyParts);
     $mail->setFrom($this->mailFrom, $this->mailFromNickName);
     $mail->addTo($this->mailTo);
     if (!empty($this->mailCc)) {
         $mail->addCc($this->mailCc);
     }
     if (!empty($this->mailBcc)) {
         $mail->addBcc($this->mailBcc);
     }
     $mail->setSubject($this->mailSubject);
     $transport = new SmtpTransport();
     $transport->setOptions($options);
     $emailLogInfo = array('email_to' => $this->mailTo, 'email_from' => $this->mailFrom, 'email_body' => $this->mailBody, 'email_subject' => $this->mailSubject, 'sender_type' => $this->mailSenderType);
     $emailSend = 0;
     try {
         $transport->send($mail);
         $emailSend = 1;
     } catch (\Exception $e) {
         $emailLogInfo['email_error'] = $e->getMessage();
         throw $e;
     }
     return $emailSend;
 }
开发者ID:arvind2110,项目名称:zf2mail,代码行数:47,代码来源:Mail.php

示例10: _setHtmlBody

 private function _setHtmlBody($message = null)
 {
     $objMimePart = new MimePart($message);
     $objMimePart->type = "text/html";
     $objMimeMessage = new MimeMessage();
     $objMimeMessage->addPart($objMimePart);
     return $objMimeMessage;
 }
开发者ID:sydorenkovd,项目名称:e-com.loc,代码行数:8,代码来源:Email.php

示例11: sendEmail

 function sendEmail($to, $subject, $html, $text, $attachments = null)
 {
     // HTML part
     $htmlPart = new Mime\Part($html);
     $htmlPart->setEncoding(Mime\Mime::ENCODING_QUOTEDPRINTABLE);
     $htmlPart->setType(Mime\Mime::TYPE_HTML);
     // Plain text part
     $textPart = new Mime\Part($text);
     $textPart->setEncoding(Mime\Mime::ENCODING_QUOTEDPRINTABLE);
     $textPart->setType(Mime\Mime::TYPE_TEXT);
     $body = new Mime\Message();
     if ($attachments) {
         // With attachments, we need a multipart/related email. First part
         // is itself a multipart/alternative message
         $content = new Mime\Message();
         $content->addPart($textPart);
         $content->addPart($htmlPart);
         $contentPart = new Mime\Part($content->generateMessage());
         $contentPart->setType(Mime\Mime::MULTIPART_ALTERNATIVE);
         $contentPart->setBoundary($content->getMime()->boundary());
         $body->addPart($contentPart);
         $messageType = Mime\Mime::MULTIPART_RELATED;
         // Add each attachment
         foreach ($attachments as $thisAttachment) {
             $attachment = new Mime\Part($thisAttachment['content']);
             $attachment->filename = $thisAttachment['filename'];
             $attachment->type = Mime\Mime::TYPE_OCTETSTREAM;
             $attachment->encoding = Mime\Mime::ENCODING_BASE64;
             $attachment->disposition = Mime\Mime::DISPOSITION_ATTACHMENT;
             $body->addPart($attachment);
         }
     } else {
         // No attachments, just add the two textual parts to the body
         $body->setParts([$textPart, $htmlPart]);
         $messageType = Mime\Mime::MULTIPART_ALTERNATIVE;
     }
     // attach the body to the message and set the content-type
     $message = new Message();
     $message->addTo($to);
     $message->setEncoding($this->encoding);
     $message->addFrom($this->fromEmail, $this->fromName);
     $message->setSubject($subject);
     $message->setBody($body);
     $message->getHeaders()->get('content-type')->setType($messageType);
     $this->getTransport()->send($message);
 }
开发者ID:zetta-code,项目名称:tss-bootstrap,代码行数:46,代码来源:EmailPlugin.php

示例12: testMimeMessageBodyRemainsUnchanged

 public function testMimeMessageBodyRemainsUnchanged()
 {
     $part = new Mime\Part('Foo');
     $message = new Mime\Message();
     $message->addPart($part);
     $this->mailService->setBody($message);
     $this->assertTrue($this->mailService->getMessage()->getBody() instanceof Mime\Message);
     $this->assertEquals($message, $this->mailService->getMessage()->getBody());
 }
开发者ID:quangdungninh,项目名称:zendvnteam,代码行数:9,代码来源:MailServiceTest.php

示例13: sendMail

 public function sendMail()
 {
     if (false === $this->checkMailValidity()) {
         throw new \InvalidArgumentException('E-Mail can not be sent as the required fields where not filled in.');
     }
     $mimeBody = new MimeMessage();
     if ($this->mailBodyHtml instanceof ViewModel) {
         $htmlBodyPart = new MimePart($this->createBodyFromViewModel($this->mailBodyHtml));
         $htmlBodyPart->charset = $this->mailCharset;
         $htmlBodyPart->encoding = $this->mailEncoding;
         $htmlBodyPart->type = 'text/html';
         $mimeBody->addPart($htmlBodyPart);
     }
     if ($this->mailBodyText instanceof ViewModel) {
         $textBodyPart = new MimePart($this->createBodyFromViewModel($this->mailBodyText));
         $textBodyPart->charset = $this->mailCharset;
         $textBodyPart->encoding = $this->mailEncoding;
         $textBodyPart->type = 'text/plain';
         $mimeBody->addPart($textBodyPart);
     }
     $mailMessage = new MailMessage();
     $mailMessage->setBody($mimeBody);
     $mailMessage->setEncoding($this->mailEncoding);
     $mailMessage->setFrom($this->mailFrom);
     $mailMessage->setSender($this->mailFrom);
     $mailMessage->setTo($this->mailTo);
     if ($this->mailBcc != '') {
         $mailMessage->setBcc($this->mailBcc);
     }
     if ($this->mailCc != '') {
         $mailMessage->setCc($this->mailCc);
     }
     $mailMessage->setSubject($this->mailSubject);
     if (2 <= count($mimeBody->getParts())) {
         $mailMessage->getHeaders()->get('content-type')->setType('multipart/alternative');
     }
     try {
         $this->transport->send($mailMessage);
         return true;
     } catch (\Exception $e) {
         throw new \Exception($e);
     }
 }
开发者ID:chateaux,项目名称:toolbox,代码行数:43,代码来源:MailService.php

示例14: assemble

 /**
  * @param string $to
  * @param Template $template
  * @param array $data
  * @return Message
  */
 public function assemble($to, Template $template, array $data)
 {
     $html = new MimePart($template->getBody($data));
     $html->type = "text/html";
     $body = new MimeMessage();
     $body->addPart($html);
     $message = new Message();
     $message->addFrom($this->config['from-email'], $this->config['from-name'])->addTo($to)->setSubject($template->getSubject())->setBody($body)->setEncoding("UTF-8");
     return $message;
 }
开发者ID:t4web,项目名称:mail,代码行数:16,代码来源:Assembler.php

示例15: send

 public function send($alias, $to, $from = null, array $data = null)
 {
     if (!config('mail.enabled')) {
         return;
     }
     $template = $this->getTemplate($alias);
     if (!$template) {
         throw new CoreException('Cannot find template with alias/id: ' . $alias, 404);
     }
     if ($data === null) {
         $data = array();
     }
     $template->setDescription($this->replaceTemplateContent($template->getDescription(), $data));
     $template->setName($this->replaceTemplateContent($template->getName(), $data));
     $preffix = server_url(base_url());
     $content = preg_replace('#background\\: url\\((.*)\\)#', 'background: url(' . $preffix . '$1)', $template->getDescription());
     $content = preg_replace('#\\<img src=\\"(.*)\\"#', '<img src="' . $preffix . '$1"', $content);
     $template->getDescription($content);
     $message = new Message();
     $message->setSubject($template->getName());
     if ($from) {
         $message->setFrom($from);
     }
     $message->addTo($to);
     $content = $template->getDescription();
     $content = '<html><head><title>' . $template->getName() . '</title></head><body>' . $template->getDescription() . '</body></html>';
     $html = new Mime\Part($content);
     $html->setType(Mime\Mime::TYPE_HTML);
     $html->setCharset('utf-8');
     $mimeMessage = new Mime\Message();
     $mimeMessage->addPart($html);
     foreach ($this->attachments as $attachment) {
         $mimeMessage->addPart($attachment);
     }
     $message->setBody($mimeMessage);
     try {
         $transport = new SmtpTransport(new SmtpOptions(config('mail.options')));
         $transport->send($message);
     } catch (\Exception $e) {
         throw $e;
     }
     return $this;
 }
开发者ID:control-corp,项目名称:micro-mail,代码行数:43,代码来源:Templates.php


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