本文整理汇总了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);
//发送消息
}
示例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;
}
示例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;
}
示例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);
}
示例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');
//.........这里部分代码省略.........
示例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();
}
示例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'));
}
示例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();
}
示例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);
}
示例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;
}