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


PHP Message::getHeaders方法代码示例

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


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

示例1: getMessage

 public function getMessage()
 {
     $message = new Message();
     $message->addTo('zf-devteam@zend.com', 'ZF DevTeam')->addCc('matthew@zend.com')->addBcc('zf-crteam@lists.zend.com', 'CR-Team, ZF Project')->addFrom(array('zf-devteam@zend.com', 'Matthew' => 'matthew@zend.com'))->setSender('ralph.schindler@zend.com', 'Ralph Schindler')->setSubject('Testing Zend\\Mail\\Transport\\Sendmail')->setBody('This is only a test.');
     $message->getHeaders()->addHeaders(array('X-Foo-Bar' => 'Matthew'));
     return $message;
 }
开发者ID:haoyanfei,项目名称:zf2,代码行数:7,代码来源:FileTest.php

示例2: sendMail

 /**
  * @param ZendMail\Message $message
  * @param string $emailAlias
  * @param array $variables
  * @return ZendMail\Message
  * @throws Exception\RuntimeException
  */
 public function sendMail(ZendMail\Message $message, $emailAlias, array $variables = array())
 {
     $plain = $this->renderMessage($emailAlias, Config::TYPE_PLAIN, $variables);
     $html = $this->renderMessage($emailAlias, Config::TYPE_HTML, $variables);
     $body = new Mime\Message();
     if (!empty($html) && !empty($plain)) {
         $htmlPart = new Mime\Part($html);
         $htmlPart->type = 'text/html';
         $plainPart = new Mime\Part($plain);
         $plainPart->type = 'text/plain';
         $body->setParts(array($plainPart, $htmlPart));
     } elseif (!empty($html)) {
         $htmlPart = new Mime\Part($html);
         $htmlPart->type = 'text/html';
         $body->setParts(array($htmlPart));
     } else {
         $plainPart = new Mime\Part($plain);
         $plainPart->type = 'text/plain';
         $body->setParts(array($plainPart));
     }
     $from = $this->getConfig()->getFrom($emailAlias);
     $message->setSubject($this->getSubject($emailAlias, $variables))->setEncoding('UTF-8')->setBody($body)->setFrom($from['email'], $from['name']);
     if (count($body->getParts()) == 2) {
         $message->getHeaders()->get('content-type')->setType('multipart/alternative');
     }
     if (null === ($transport = $this->getTransport())) {
         throw new Exception\RuntimeException('No transport could be alocated');
     }
     $transport->send($message);
     return $message;
 }
开发者ID:SalesAndOrders,项目名称:zf2-mail,代码行数:38,代码来源:Service.php

示例3: generateMessage

 /**
  *
  */
 private function generateMessage()
 {
     //Reply to
     if ($this->config["defaults"]["reply_to"] && is_null($this->email->getReplyTo())) {
         $this->message->addReplyTo($this->config["defaults"]["reply_to"], $this->config["defaults"]["reply_to_name"]);
     }
     /*
      * Produce a list of template vars
      */
     $this->templateVars = array_merge($this->config["template_vars"], $this->email->toArray());
     //If not layout, use default
     if (!$this->email->getHtmlLayoutName()) {
         $this->email->setHtmlLayoutName($this->config["defaults"]["html_layout_name"]);
     }
     /*
      * If not sender, use default
      */
     if (!is_null($this->email->getFrom())) {
         $this->message->setFrom($this->email->getFrom(), $this->email->getFromName());
     } else {
         $this->message->setFrom($this->config["defaults"]["from_email"], $this->config["defaults"]["from_name"]);
     }
     /*
      * Force the mailing as header if we have a mailing
      */
     if (!is_null($this->mailing)) {
         $this->message->getHeaders()->addHeaderLine('X-Mailjet-Campaign', DEBRANOVA_HOST . '-mailing-' . $this->mailing->getId());
     }
 }
开发者ID:debranova,项目名称:general,代码行数:32,代码来源:EmailService.php

示例4: setBody

 /**
  * Sets the message body
  * @param \Zend\Mime\Part|\Zend\Mime\Message|string $body Email body
  * @param string $charset
  * @return $this Returns this MailService for chaining purposes
  * @throws InvalidArgumentException
  * @see \AcMailer\Service\MailServiceInterface::setBody()
  */
 public function setBody($body, $charset = null)
 {
     if (is_string($body)) {
         // Create a Mime\Part and wrap it into a Mime\Message
         $mimePart = new Mime\Part($body);
         $mimePart->type = $body != strip_tags($body) ? Mime\Mime::TYPE_HTML : Mime\Mime::TYPE_TEXT;
         $mimePart->charset = $charset ?: self::DEFAULT_CHARSET;
         $body = new Mime\Message();
         $body->setParts([$mimePart]);
     } elseif ($body instanceof Mime\Part) {
         // Overwrite the charset if the Part object if provided
         if (isset($charset)) {
             $body->charset = $charset;
         }
         // The body is a Mime\Part. Wrap it into a Mime\Message
         $mimeMessage = new Mime\Message();
         $mimeMessage->setParts([$body]);
         $body = $mimeMessage;
     }
     // If the body is not a string or a Mime\Message at this point, it is not a valid argument
     if (!is_string($body) && !$body instanceof Mime\Message) {
         throw new InvalidArgumentException(sprintf('Provided body is not valid. It should be one of "%s". %s provided', implode('", "', ['string', 'Zend\\Mime\\Part', 'Zend\\Mime\\Message']), is_object($body) ? get_class($body) : gettype($body)));
     }
     // The headers Content-type and Content-transfer-encoding are duplicated every time the body is set.
     // Removing them before setting the body prevents this error
     $this->message->getHeaders()->removeHeader('contenttype');
     $this->message->getHeaders()->removeHeader('contenttransferencoding');
     $this->message->setBody($body);
     return $this;
 }
开发者ID:acelaya,项目名称:zf2-acmailer,代码行数:38,代码来源:MailService.php

示例5: send

 function send($recipients, $type = 'mail')
 {
     global $tikilib, $prefs;
     $logslib = TikiLib::lib('logs');
     $this->mail->getHeaders()->removeHeader('to');
     foreach ((array) $recipients as $to) {
         $this->mail->addTo($to);
     }
     if ($prefs['zend_mail_handler'] == 'smtp' && $prefs['zend_mail_queue'] == 'y') {
         $query = "INSERT INTO `tiki_mail_queue` (message) VALUES (?)";
         $bindvars = array(serialize($this->mail));
         $tikilib->query($query, $bindvars, -1, 0);
         $title = 'mail';
     } else {
         try {
             tiki_send_email($this->mail);
             $title = 'mail';
         } catch (Zend\Mail\Exception\ExceptionInterface $e) {
             $title = 'mail error';
         }
         if ($title == 'mail error' || $prefs['log_mail'] == 'y') {
             foreach ($recipients as $u) {
                 $logslib->add_log($title, $u . '/' . $this->mail->getSubject());
             }
         }
     }
     return $title == 'mail';
 }
开发者ID:rjsmelo,项目名称:tiki,代码行数:28,代码来源:tikimaillib.php

示例6: convert

 /**
  * 
  * @param Message $message
  * @return ZendMessage
  */
 public static function convert(Message $message)
 {
     $mailMessage = new ZendMessage();
     $mailMessage->setSubject($message->getSubject());
     $mailMessage->setFrom($message->getFrom());
     $mailMessage->setTo($message->getTo());
     $mailMessage->setCc($message->getCc());
     $mailMessage->setBcc($message->getBcc());
     $mailMessage->setReplyTo($message->getReplyTo());
     $mailMessage->getHeaders()->addHeaders($message->getHeaders());
     if ($mailMessage->getSender()) {
         $mailMessage->setSender($message->getSender());
     }
     if ($message->isMultipart()) {
         $mimePart = new MimeMessage();
         if ($message->getBodyHtml()) {
             $part = new Part($message->getBodyHtml());
             $part->charset = $message->getCharset();
             $part->encoding = $message->getEncoding();
             $part->type = Mime::TYPE_HTML;
             $mimePart->addPart($part);
         }
         if ($message->getBodyText()) {
             $part = new Part($message->getBodyText());
             $part->charset = $message->getCharset();
             $part->encoding = $message->getEncoding();
             $part->type = Mime::TYPE_TEXT;
             $mimePart->addPart($part);
         }
         foreach ($message->getAttachments() as $attachment) {
             $mimePart->addPart($attachment->asMimePart());
         }
         foreach ($message->getParts() as $part) {
             $mimePart->addPart($part);
         }
         $mailMessage->setBody($mimePart);
     } else {
         $mailMessage->getHeaders()->addHeaderLine('Content-Type', $message->getContentType());
         $mailMessage->setEncoding($message->getEncoding());
         $mailMessage->setBody($message->getFilledBody());
     }
     return $mailMessage;
 }
开发者ID:alex-oleshkevich,项目名称:zf-extras,代码行数:48,代码来源:MessageConverter.php

示例7: sendMessage

 protected function sendMessage()
 {
     $oMessage = new Message();
     $oMessage->setEncoding('UTF-8')->addFrom($this->_sFrom)->addTo($this->_sEmailAddress)->setSubject($this->_sSubject)->setBody($this->_oBody);
     $oHeaders = $oMessage->getHeaders();
     $oHeaders->removeHeader('Content-Type');
     $oHeaders->addHeaderLine('Content-Type', 'text/html; charset=UTF-8');
     $this->_oTransport->send($oMessage);
     $this->clearAll();
 }
开发者ID:lstaszak,项目名称:zf2main,代码行数:10,代码来源:Mail.php

示例8: getNewMessage

 /**
  * 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;
 }
开发者ID:bbeckman,项目名称:NDL-VuFind2,代码行数:16,代码来源:Mailer.php

示例9: testDefaultDateHeaderEncodingIsAlwaysAscii

 /**
  * @group ZF2-507
  */
 public function testDefaultDateHeaderEncodingIsAlwaysAscii()
 {
     $this->message->setEncoding('utf-8');
     $headers = $this->message->getHeaders();
     $header = $headers->get('date');
     $date = date('r');
     $date = substr($date, 0, 16);
     $test = $header->getFieldValue();
     $test = substr($test, 0, 16);
     $this->assertEquals($date, $test);
 }
开发者ID:nuklehed,项目名称:zf2,代码行数:14,代码来源:MessageTest.php

示例10: createMessage

 /**
  * @param ZendMailInterface $mail
  *
  * @return Mail\Message
  */
 protected function createMessage(ZendMailInterface $mail)
 {
     $message = new Mail\Message();
     $message->getHeaders()->addHeaders($mail->getHeaders());
     $message->setTo($mail->getTo());
     $message->setCc($mail->getCc());
     $message->setBcc($mail->getBcc());
     $message->setFrom($mail->getFrom());
     $message->setReplyTo($mail->getReplyTo());
     $message->setSubject($mail->getSubject());
     $message->setBody($this->messageCreator->createMessage($mail));
     return $message;
 }
开发者ID:phpro,项目名称:zf-mail-manager,代码行数:18,代码来源:ZendMailAdapter.php

示例11: sendMail

 /**
  * @param string $to
  * @param string $toName
  * @param string $subject
  * @param string $message
  * @param string $from
  * @param string $fromName
  *
  * @return bool|FlashMessenger
  */
 public function sendMail($to, $toName, $subject, $message, $from, $fromName)
 {
     $transport = new SmtpTransport();
     $options = new SmtpOptions(['host' => $this->settings->__invoke('mail', 'host'), 'name' => $this->settings->__invoke('mail', 'name'), 'connection_class' => $this->settings->__invoke('mail', 'connection_class'), 'connection_config' => ['username' => $this->settings->__invoke('mail', 'username'), 'password' => $this->settings->__invoke('mail', 'password'), 'ssl' => $this->settings->__invoke('mail', 'ssl')], 'port' => $this->settings->__invoke('mail', 'port')]);
     $htmlPart = new MimePart($message);
     $htmlPart->type = 'text/html';
     $body = new MimeMessage();
     $body->setParts([$htmlPart]);
     $mail = new Message();
     $mail->setFrom($from, $fromName);
     $mail->addTo($to, $toName);
     $mail->setSubject($subject);
     $mail->setEncoding('UTF-8');
     $mail->setBody($body);
     $mail->getHeaders()->addHeaderLine('MIME-Version: 1.0');
     $mail->getHeaders()->addHeaderLine('Content-Type', 'text/html; charset=UTF-8');
     try {
         $transport->setOptions($options);
         $transport->send($mail);
         return true;
     } catch (\Exception $e) {
         return $this->flashMessenger->addMessage('Email not send', 'error');
     }
 }
开发者ID:samsonasik,项目名称:unnamed,代码行数:34,代码来源:Mailing.php

示例12: 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

示例13: enviar

 public function enviar()
 {
     $body = $this->assunto;
     $htmlPart = new MimePart($body);
     $htmlPart->type = "text/html";
     $textPart = new MimePart($body);
     $textPart->type = "text/plain";
     $body = new MimeMessage();
     $body->setParts(array($textPart, $htmlPart));
     $message = new Mail\Message();
     $message->setFrom($this->rementente);
     $message->addTo($this->destinatario);
     $message->setSubject($this->titulo);
     $message->setEncoding("UTF-8");
     $message->setBody($body);
     $message->getHeaders()->get('content-type')->setType('multipart/alternative');
     $transport = new Mail\Transport\Sendmail();
     $transport->send($message);
 }
开发者ID:publicidademorrinhos,项目名称:ModeloZend2,代码行数:19,代码来源:EnviarEmail.php

示例14: setBody

 /**
  * @param string | \Zend\View\Model\ViewModel | Mime\Part $body
  * @return $this
  */
 public function setBody($body, $charset = null)
 {
     $mimeMessage = new Mime\Message();
     $finalBody = null;
     if (is_string($body)) {
         // Create a Mime\Part and wrap it into a Mime\Message
         $mimePart = new Mime\Part($body);
         $mimePart->type = $body != strip_tags($body) ? Mime\Mime::TYPE_HTML : Mime\Mime::TYPE_TEXT;
         $mimePart->charset = $charset ?: self::DEFAULT_CHARSET;
         $mimeMessage->setParts([$mimePart]);
         $finalBody = $mimeMessage;
     } elseif ($body instanceof Mime\Part) {
         // Overwrite the charset if the Part object if provided
         if (isset($charset)) {
             $body->charset = $charset;
         }
         // The body is a Mime\Part. Wrap it into a Mime\Message
         $mimeMessage->setParts([$body]);
         $finalBody = $mimeMessage;
     } elseif ($body instanceof ViewModel) {
         $view = new View();
         $view->setResponse(new Response());
         $view->getEventManager()->attach(new PhpRendererStrategy($this->renderer));
         $view->render($body);
         $content = $view->getResponse()->getContent();
         $mimePart = new Mime\Part($content);
         $mimePart->type = Mime\Mime::TYPE_HTML;
         $mimePart->charset = $charset ?: self::DEFAULT_CHARSET;
         $mimeMessage->setParts([$mimePart]);
         $finalBody = $mimeMessage;
     } else {
         throw new InvalidArgumentException(sprintf('Provided body is not valid. It should be one of "%s". %s provided', implode('", "', ['string', 'Zend\\Mime\\Part', 'Zend\\Mime\\Message', 'Zend\\View\\Model\\ViewModel']), is_object($body) ? get_class($body) : gettype($body)));
     }
     // The headers Content-type and Content-transfer-encoding are duplicated every time the body is set.
     // Removing them before setting the body prevents this error
     $this->message->getHeaders()->removeHeader('contenttype');
     $this->message->getHeaders()->removeHeader('contenttransferencoding');
     $this->message->setBody($finalBody);
     return $this;
 }
开发者ID:WasabiLib,项目名称:Mail,代码行数:44,代码来源:Mail.php

示例15: sendMail

 public function sendMail($mail)
 {
     // Build the message body
     $mimeParts = array();
     foreach ($mail->getParts() as $part) {
         $mimePart = new MimePart($part->getContent());
         $mimePart->type = $part->getType();
         $mimeParts[] = $mimePart;
     }
     $body = new MimeMessage();
     $body->setParts($mimeParts);
     // Build the message.
     $message = new Mail\Message();
     $message->setBody($body);
     // Set the participants
     foreach ($mail->getParticipants() as $participant) {
         if ($participant->getComposition() == 'to') {
             $message->addTo($participant->getAddress(), $participant->getName());
         }
         if ($participant->getComposition() == 'cc') {
             $message->addCc($participant->getAddress(), $participant->getName());
         }
         if ($participant->getComposition() == 'bcc') {
             $message->addBcc($participant->getAddress(), $participant->getName());
         }
         if ($participant->getComposition() == 'from') {
             $message->addFrom($participant->getAddress(), $participant->getName());
         }
     }
     // Set the subject
     $message->setSubject($mail->getSubject());
     $contentType = $mail->getContentType();
     if ($contentType) {
         $message->getHeaders()->get('content-type')->setType($contentType);
     }
     // Create the transport and send.
     $transport = new SmtpTransport();
     $transport->setOptions(new SmtpOptions($this->options));
     $transport->send($message);
 }
开发者ID:srayner,项目名称:civmail,代码行数:40,代码来源:MailService.php


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