當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。