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


PHP Mail\Headers类代码示例

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


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

示例1: send

 function send()
 {
     //第一步: 设置相关的headers
     //1.设置邮件的Content-Type,要不然网站的消息内容里面的html标签会被当做纯文本处理
     $smtpHeaderContentType = new SmtpHeaderContentType();
     $smtpHeaderContentType->setType('text/html');
     //2.设置编码集并添加Content-Type
     $headers = new SmtpHeaders();
     $headers->setEncoding('utf-8');
     $headers->addHeader($smtpHeaderContentType);
     //第二步:设置消息的相关
     $message = new SmtpMessage();
     $message->setHeaders($headers);
     $message->addTo($this->mailTo)->addFrom($this->mailFrom)->setSubject($this->subject)->setBody($this->body);
     //邮件的内容
     //第三步:设置Smtp的相关链接参数
     $smtpOptions = new SmtpOptions();
     $smtpOptions->setHost($this->host)->setPort($this->port)->setConnectionClass('login')->setConnectionConfig(array('username' => $this->username, 'password' => $this->password, 'ssl' => 'ssl'));
     //第四步:加载配置,发送消息
     $smtpTransport = new SmtpTransport();
     $smtpTransport->setOptions($smtpOptions);
     //加载配置
     $smtpTransport->send($message);
     //发送消息
 }
开发者ID:hlkzmy,项目名称:crowdfunding,代码行数:25,代码来源:TencentSmtp.php

示例2: processMessageReference

 /**
  * Retrieves Message Reference
  *
  * @param \Zend\Mail\Headers $headers
  * @return string|null
  */
 protected function processMessageReference($headers)
 {
     $messageReference = null;
     if ($headers->get('references')) {
         preg_match('/<([^<]+)>/', $headers->get('references')->getFieldValue(), $matches);
         $messageReference = $matches[1];
     }
     return $messageReference;
 }
开发者ID:eltrino,项目名称:DiamanteEmailProcessingBundle,代码行数:15,代码来源:AbstractMessageProvider.php

示例3: testSendMinimalMail

 public function testSendMinimalMail()
 {
     $headers = new Headers();
     $headers->addHeaderLine('Date', 'Sun, 10 Jun 2012 20:07:24 +0200');
     $message = new Message();
     $message->setHeaders($headers)->setSender('ralph.schindler@zend.com', 'Ralph Schindler')->setBody('testSendMailWithoutMinimalHeaders')->addTo('zf-devteam@zend.com', 'ZF DevTeam');
     $expectedMessage = "RSET\r\n" . "MAIL FROM:<ralph.schindler@zend.com>\r\n" . "DATA\r\n" . "Date: Sun, 10 Jun 2012 20:07:24 +0200\r\n" . "Sender: Ralph Schindler <ralph.schindler@zend.com>\r\n" . "To: ZF DevTeam <zf-devteam@zend.com>\r\n" . "\r\n" . "testSendMailWithoutMinimalHeaders\r\n" . ".\r\n";
     $this->transport->send($message);
     $this->assertEquals($expectedMessage, $this->connection->getLog());
 }
开发者ID:haoyanfei,项目名称:zf2,代码行数:10,代码来源:SmtpTest.php

示例4: testSendEscapedEmail

 public function testSendEscapedEmail()
 {
     $headers = new Headers();
     $headers->addHeaderLine('Date', 'Sun, 10 Jun 2012 20:07:24 +0200');
     $message = new Message();
     $message->setHeaders($headers)->setSender('ralph.schindler@zend.com', 'Ralph Schindler')->setBody("This is a test\n.")->addTo('zf-devteam@zend.com', 'ZF DevTeam');
     $expectedMessage = "EHLO localhost\r\n" . "MAIL FROM:<ralph.schindler@zend.com>\r\n" . "DATA\r\n" . "Date: Sun, 10 Jun 2012 20:07:24 +0200\r\n" . "Sender: Ralph Schindler <ralph.schindler@zend.com>\r\n" . "To: ZF DevTeam <zf-devteam@zend.com>\r\n" . "\r\n" . "This is a test\r\n" . "..\r\n" . ".\r\n";
     $this->transport->send($message);
     $this->assertEquals($expectedMessage, $this->connection->getLog());
 }
开发者ID:pnaq57,项目名称:zf2demo,代码行数:10,代码来源:SmtpTest.php

示例5: headers

 private function headers()
 {
     $headers = new Headers();
     $messageId = new MessageId();
     $messageId->setId('testId');
     $headers->addHeader($messageId);
     $addressList = new AddressList();
     $addressList->add('test@gmail.com');
     $from = new From();
     $from->setAddressList($addressList);
     $headers->addHeader($from);
     $to = new To();
     $to->setAddressList($addressList);
     $headers->addHeader($to);
     return $headers;
 }
开发者ID:gitter-badger,项目名称:diamantedesk-application,代码行数:16,代码来源:RawMessageProviderTest.php

示例6: headers

 /**
  * Access headers collection
  *
  * Lazy-loads if not already attached.
  * 
  * @return Headers
  */
 public function headers()
 {
     if (null === $this->headers) {
         $this->setHeaders(new Headers());
         $this->headers->addHeaderLine('Date', date('r'));
     }
     return $this->headers;
 }
开发者ID:bradley-holt,项目名称:zf2,代码行数:15,代码来源:Message.php

示例7: getHeaders

 /**
  * Access headers collection
  *
  * Lazy-loads if not already attached.
  *
  * @return Headers
  */
 public function getHeaders()
 {
     if (null === $this->headers) {
         $this->setHeaders(new Headers());
         $date = Header\Date::fromString('Date: ' . date('r'));
         $this->headers->addHeader($date);
     }
     return $this->headers;
 }
开发者ID:yakamoz-fang,项目名称:concrete,代码行数:16,代码来源:Message.php

示例8: mergeDuplicateHeader

 /**
  * Merge duplicate header fields into single headers field.
  * The headers must be AbstractAddressList.
  *
  * @param Headers $headerBag
  * @param HeaderInterface|AbstractAddressList[] $headers
  */
 private function mergeDuplicateHeader(Headers $headerBag, $headers)
 {
     if ($headers instanceof HeaderInterface) {
         // all good
         return;
     }
     // use first headers as base and collect addresses there
     $header = $headers[0];
     unset($headers[0]);
     if (!$header instanceof AbstractAddressList) {
         throw new DomainException(sprintf('Cannot grab address list from headers of type "%s"; not an AbstractAddressList implementation', get_class($header)));
     }
     $addressList = $header->getAddressList();
     foreach ($headers as $h) {
         $addressList->merge($h->getAddressList());
     }
     $headerBag->removeHeader($header->getFieldName());
     $headerBag->addHeader($header);
 }
开发者ID:dabielkabuto,项目名称:eventum,代码行数:26,代码来源:SanitizeHeaders.php

示例9: setExtHeaders

 /**
  * Sets additional message headers
  *
  * @param \Zend\Mail\Headers $headers
  * @param array $data
  */
 protected function setExtHeaders(&$headers, array $data)
 {
     $headers->addHeaderLine(self::UID, $data[self::UID]);
     $headers->addHeaderLine('InternalDate', $data[self::INTERNALDATE]);
 }
开发者ID:xamin123,项目名称:platform,代码行数:11,代码来源:Imap.php

示例10: getHeaders

 /**
  * Access headers collection
  *
  * Lazy-loads if not already attached.
  *
  * @return Headers
  */
 public function getHeaders()
 {
     if (null === $this->headers) {
         if ($this->mail) {
             $part = $this->mail->getRawHeader($this->messageNum);
             $this->headers = Headers::fromString($part);
         } else {
             $this->headers = new Headers();
         }
     }
     return $this->headers;
 }
开发者ID:karnurik,项目名称:zf2-turtorial,代码行数:19,代码来源:Part.php

示例11: testGetEmbeddedContentId

 /**
  * @dataProvider getEmbeddedContentIdProvider
  * @param $rawHeaders
  * @param $expected
  */
 public function testGetEmbeddedContentId($rawHeaders, $expected)
 {
     $headers = Headers::fromString(implode(PHP_EOL, $rawHeaders), PHP_EOL);
     $contentIdHeader = null;
     $contentDispositionHeader = null;
     if (isset($rawHeaders['Content-ID'])) {
         $contentIdHeader = GenericHeader::fromString($rawHeaders['Content-ID']);
     }
     if (isset($rawHeaders['Content-Disposition'])) {
         $contentDispositionHeader = GenericHeader::fromString($rawHeaders['Content-Disposition']);
     }
     $this->part->expects($this->any())->method('getHeader')->willReturnMap([['Content-ID', null, $contentIdHeader], ['Content-Disposition', null, $contentDispositionHeader]]);
     $this->part->expects($this->any())->method('getHeaders')->willReturn($headers);
     $this->assertEquals($expected, $this->attachment->getEmbeddedContentId());
 }
开发者ID:ramunasd,项目名称:platform,代码行数:20,代码来源:AttachmentTest.php

示例12: __construct

 /**
  * Public constructor
  *
  * This handler supports the following params:
  * - file     filename or open file handler with message content (required)
  * - startPos start position of message or part in file (default: current position)
  * - endPos   end position of message or part in file (default: end of file)
  *
  * @param   array $params  full message with or without headers
  * @throws Exception\RuntimeException
  * @throws Exception\InvalidArgumentException
  */
 public function __construct(array $params)
 {
     if (empty($params['file'])) {
         throw new Exception\InvalidArgumentException('no file given in params');
     }
     if (!is_resource($params['file'])) {
         $this->_fh = fopen($params['file'], 'r');
     } else {
         $this->_fh = $params['file'];
     }
     if (!$this->_fh) {
         throw new Exception\RuntimeException('could not open file');
     }
     if (isset($params['startPos'])) {
         fseek($this->_fh, $params['startPos']);
     }
     $header = '';
     $endPos = isset($params['endPos']) ? $params['endPos'] : null;
     while (($endPos === null || ftell($this->_fh) < $endPos) && trim($line = fgets($this->_fh))) {
         $header .= $line;
     }
     $this->_headers = Headers::fromString($header);
     $this->_contentPos[0] = ftell($this->_fh);
     if ($endPos !== null) {
         $this->_contentPos[1] = $endPos;
     } else {
         fseek($this->_fh, 0, SEEK_END);
         $this->_contentPos[1] = ftell($this->_fh);
     }
     if (!$this->isMultipart()) {
         return;
     }
     $boundary = $this->getHeaderField('content-type', 'boundary');
     if (!$boundary) {
         throw new Exception\RuntimeException('no boundary found in content type to split message');
     }
     $part = array();
     $pos = $this->_contentPos[0];
     fseek($this->_fh, $pos);
     while (!feof($this->_fh) && ($endPos === null || $pos < $endPos)) {
         $line = fgets($this->_fh);
         if ($line === false) {
             if (feof($this->_fh)) {
                 break;
             }
             throw new Exception\RuntimeException('error reading file');
         }
         $lastPos = $pos;
         $pos = ftell($this->_fh);
         $line = trim($line);
         if ($line == '--' . $boundary) {
             if ($part) {
                 // not first part
                 $part[1] = $lastPos;
                 $this->_partPos[] = $part;
             }
             $part = array($pos);
         } else {
             if ($line == '--' . $boundary . '--') {
                 $part[1] = $lastPos;
                 $this->_partPos[] = $part;
                 break;
             }
         }
     }
     $this->_countParts = count($this->_partPos);
 }
开发者ID:navassouza,项目名称:zf2,代码行数:79,代码来源:File.php

示例13: prepareHeaders

 /**
  * Prepare header string from message
  * 
  * @param  Message $message 
  * @return string
  */
 protected function prepareHeaders(Message $message)
 {
     $headers = new Headers();
     foreach ($message->headers() as $header) {
         if ('Bcc' == $header->getFieldName()) {
             continue;
         }
         $headers->addHeader($header);
     }
     return $headers->toString();
 }
开发者ID:nevvermind,项目名称:zf2,代码行数:17,代码来源:Smtp.php

示例14: getImportance

 /**
  * Gets an email importance
  *
  * @param Headers $headers
  *
  * @return integer
  */
 protected function getImportance(Headers $headers)
 {
     $importance = $headers->get('Importance');
     if ($importance instanceof HeaderInterface) {
         switch (strtolower($importance->getFieldValue())) {
             case 'high':
                 return 1;
             case 'low':
                 return -1;
             default:
                 return 0;
         }
     }
     $labels = $headers->get('X-GM-LABELS');
     if ($labels instanceof HeaderInterface) {
         if ($labels->getFieldValue() === '\\\\Important') {
             return 1;
         }
     } elseif ($labels instanceof \ArrayIterator) {
         foreach ($labels as $label) {
             if ($label instanceof HeaderInterface && $label->getFieldValue() === '\\\\Important') {
                 return 1;
             }
         }
     }
     return 0;
 }
开发者ID:xamin123,项目名称:platform,代码行数:34,代码来源:ImapEmailManager.php

示例15: setHeaders

 /**
  * Compose headers
  *
  * @param   \Zend\Mail\Headers  $headers
  * @return  \Zork\Mail\Message
  */
 public function setHeaders(Headers $headers)
 {
     $headers->addHeaderLine('User-Agent', static::USER_AGENT)->addHeaderLine('X-Mailer', static::USER_AGENT);
     return parent::setHeaders($headers);
 }
开发者ID:gridguyz,项目名称:zork,代码行数:11,代码来源:Message.php


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