當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Headers::addHeader方法代碼示例

本文整理匯總了PHP中Zend\Mail\Headers::addHeader方法的典型用法代碼示例。如果您正苦於以下問題:PHP Headers::addHeader方法的具體用法?PHP Headers::addHeader怎麽用?PHP Headers::addHeader使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Zend\Mail\Headers的用法示例。


在下文中一共展示了Headers::addHeader方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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: 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

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

示例4: testCastingToStringReturnsAllMultiHeaderValues

 public function testCastingToStringReturnsAllMultiHeaderValues()
 {
     $headers = new Headers();
     $received1 = Header\Received::fromString("Received: from framework (localhost [127.0.0.1])\r\nby framework (Postfix) with ESMTP id BBBBBBBBBBB\r\nfor <zend@framework>; Mon, 21 Nov 2011 12:50:27 -0600 (CST)");
     $received2 = Header\Received::fromString("Received: from framework (localhost [127.0.0.1])\r\nby framework (Postfix) with ESMTP id AAAAAAAAAAA\r\nfor <zend@framework>; Mon, 21 Nov 2011 12:50:29 -0600 (CST)");
     $headers->addHeader($received1);
     $headers->addHeader($received2);
     $string = $headers->toString();
     $expected = array('Received: ' . $received1->getFieldValue(), 'Received: ' . $received2->getFieldValue());
     $expected = implode("\r\n", $expected) . "\r\n";
     $this->assertEquals($expected, $string);
 }
開發者ID:bradley-holt,項目名稱:zf2,代碼行數:12,代碼來源:HeadersTest.php

示例5: testMsgHandleUidSearch

 /**
  * @group medium
  */
 public function testMsgHandleUidSearch()
 {
     $path1 = './test_data/test_mailbox_' . date('Ymd_His') . '_' . uniqid('', true);
     $log = new Logger('test_application');
     #$log->pushHandler(new StreamHandler('php://stdout', Logger::DEBUG));
     $server = new Server('', 0);
     $server->setLog($log);
     $server->init();
     $storage1 = new DirectoryStorage();
     $storage1->setPath($path1);
     $server->addStorage($storage1);
     $client = new Client();
     $client->setServer($server);
     $client->setId(1);
     $msg = $client->msgHandle('17 uid search');
     $this->assertEquals('17 NO uid failure' . Client::MSG_SEPARATOR, $msg);
     $client->setStatus('hasAuth', true);
     $msg = $client->msgHandle('17 uid search');
     $this->assertEquals('17 NO No mailbox selected.' . Client::MSG_SEPARATOR, $msg);
     $client->msgHandle('6 select INBOX');
     $message = new Message();
     $message->addFrom('dev1@fox21.at');
     $message->addTo('dev2@fox21.at');
     $message->setSubject('my_subject 1');
     $message->setBody('my_body');
     $server->addMail($message, null, null, false);
     $message = new Message();
     $message->addFrom('dev1@fox21.at');
     $message->addTo('dev2@fox21.at');
     $message->setSubject('my_subject 2');
     $message->setBody('my_body');
     $server->addMail($message, null, array(Storage::FLAG_ANSWERED), false);
     $message = new Message();
     $message->addFrom('dev1@fox21.at');
     $message->addTo('dev2@fox21.at');
     $message->addBcc('steve@apple.com');
     $message->setSubject('my_subject 3');
     $message->setBody('my_body');
     $server->addMail($message, null, null, false);
     $headers = new Headers();
     $headers->addHeader(Date::fromString('Date: ' . date('r', mktime(0, 0, 0, 2, 21, 1987))));
     $message = new Message();
     $message->setHeaders($headers);
     $message->addFrom('dev1@fox21.at');
     $message->addTo('dev2@fox21.at');
     $message->setSubject('my_subject 4');
     $message->setBody('my_body');
     $server->addMail($message, null, null, false);
     $message = new Message();
     $message->setHeaders($headers);
     $message->addFrom('dev1@fox21.at');
     $message->addTo('dev2@fox21.at');
     $message->setSubject('my_subject 5');
     $message->setBody('my_body');
     $server->addMail($message, null, null, false);
     $headers = new Headers();
     $headers->addHeader(Date::fromString('Date: ' . date('r', mktime(0, 0, 0, 11, 20, 1986))));
     $message = new Message();
     $message->setHeaders($headers);
     $message->addFrom('dev1@fox21.at');
     $message->addTo('dev2@fox21.at');
     $message->setSubject('my_subject 6');
     $message->setBody('hello world');
     $server->addMail($message, null, null, false);
     $message = new Message();
     $message->addFrom('dev1@fox21.at');
     $message->addTo('dev2@fox21.at');
     $message->setSubject('my_subject 7');
     $message->setBody('my_body');
     $server->addMail($message, null, array(Storage::FLAG_DELETED), false);
     $message = new Message();
     $message->addFrom('dev1@fox21.at');
     $message->addTo('dev2@fox21.at');
     $message->setSubject('my_subject 8');
     $message->setBody('my_body');
     $server->addMail($message, null, array(Storage::FLAG_DRAFT), false);
     $message = new Message();
     $message->addFrom('dev1@fox21.at');
     $message->addTo('dev2@fox21.at');
     $message->setSubject('my_subject 9');
     $message->setBody('my_body');
     $server->addMail($message, null, array(Storage::FLAG_FLAGGED), false);
     $message = new Message();
     $message->addFrom('test@fox21.at');
     $message->addTo('dev2@fox21.at');
     $message->setSubject('my_subject 10');
     $message->setBody('my_body');
     $server->addMail($message, null, null, false);
     $message = new Message();
     $message->addFrom('dev1@fox21.at');
     $message->addTo('dev2@fox21.at');
     $message->setSubject('my_subject 11');
     $message->setBody('my super fancy long body for testing the size');
     $server->addMail($message, null, null, false);
     $message = new Message();
     $message->addFrom('dev1@fox21.at');
     $message->addTo('dev2@fox21.at');
//.........這裏部分代碼省略.........
開發者ID:thefox,項目名稱:imapd,代碼行數:101,代碼來源:ClientTest.php

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

示例7: testClone

 public function testClone()
 {
     $headers = new Mail\Headers();
     $headers->addHeader(new Header\Bcc());
     $headers2 = clone $headers;
     $this->assertEquals($headers, $headers2);
     $headers2->removeHeader('Bcc');
     $this->assertTrue($headers->has('Bcc'));
     $this->assertFalse($headers2->has('Bcc'));
 }
開發者ID:razvansividra,項目名稱:pnlzf2-1,代碼行數:10,代碼來源:HeadersTest.php

示例8: prepareHeaders

 /**
  * Prepare the textual representation of headers
  * 
  * @param  Message $message
  * @return string
  */
 protected function prepareHeaders(Message $message)
 {
     $headers = $message->headers();
     // On Windows, simply return verbatim
     if ($this->isWindowsOs()) {
         return $headers->toString();
     }
     // On *nix platforms, strip the "to" header
     $headersToSend = new Headers();
     foreach ($headers as $header) {
         if ('To' == $header->getFieldName()) {
             continue;
         }
         $headersToSend->addHeader($header);
     }
     return $headersToSend->toString();
 }
開發者ID:nevvermind,項目名稱:zf2,代碼行數:23,代碼來源:Sendmail.php

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

示例10: headers

 private function headers()
 {
     $headers = new Headers();
     $messageId = new MessageId();
     $messageId->setId('testId');
     $headers->addHeader($messageId);
     $addressList = new AddressList();
     $addressList->add('test@gmail.com', 'Dummy Name');
     $from = new From();
     $from->setAddressList($addressList);
     $headers->addHeader($from);
     $to = new To();
     $to->setAddressList($addressList);
     $headers->addHeader($to);
     //@todo fix this;
     $contentTransferEncoding = new GenericHeader("Content-Transfer-Encoding", "7bit");
     $headers->addHeader($contentTransferEncoding);
     return $headers;
 }
開發者ID:gitter-badger,項目名稱:diamantedesk-application,代碼行數:19,代碼來源:ImapMessageProviderTest.php


注:本文中的Zend\Mail\Headers::addHeader方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。