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


PHP Message::setHeaders方法代码示例

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


在下文中一共展示了Message::setHeaders方法的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: 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

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

示例4: run

 public function run()
 {
     $config = Config::get('xmailer.imap');
     $mail = new StorageImap(array('host' => $config['host'], 'user' => $config['user'], 'password' => $config['password']));
     //$mail = new StorageImap(Config::get('xmailer.imap'));
     if ($mail->countMessages() > 0) {
         $message = $mail->getMessage(1);
         if ($message->getHeaders()->get("from") != null) {
             $from = $message->getHeaders()->get("from")->toString();
         } else {
             $from = "";
         }
         if ($message->getHeaders()->get("to") != null) {
             $to = $message->getHeaders()->get("to")->toString();
         } else {
             $to = "";
         }
         preg_match("/[\\w._%+-]+@[\\w.-]+.[\\w]{2,}/", $from, $fromEmails);
         preg_match("/[\\w._%+-]+@[\\w.-]+.[\\w]{2,}/", $to, $toEmails);
         $sendTo = $this->getEmailAdresses($toEmails);
         if ($this->isValidSender($fromEmails[0])) {
             foreach ($sendTo as $mailadress) {
                 $fwd = new Message();
                 $fwd->setBody($message->getContent());
                 $h = $message->getHeaders();
                 $h->removeHeader('From');
                 $h->removeHeader('To');
                 $h->removeHeader('Reply-To');
                 $fwd->setHeaders($h);
                 $fwd->addFrom($mailadress['from']);
                 $fwd->addTo($mailadress['to']);
                 if (Config::get('xmailer.replyto')) {
                     $fwd->addReplyTo($fromEmails[0]);
                 }
                 $transport = new SendmailTransport();
                 $transport->send($fwd);
             }
             $mail->moveMessage(1, "INBOX.Sent");
         } else {
             $mail->moveMessage(1, "INBOX.Spam");
         }
         return t("%d email sent to %d People.", 1, count($sendTo));
     }
     return t("No emails sent.");
 }
开发者ID:CVJM-Forchheim,项目名称:xmailer,代码行数:45,代码来源:process_xmailer.php

示例5: send

 public function send(ZendMessage $message = null)
 {
     $message = $message ? $message : $this->message;
     if (!$message) {
         throw new Exception\InvalidArgumentException(sprintf('Mail message not set'));
     }
     $transports = $this->transports;
     if (!$transports) {
         throw new Exception\InvalidArgumentException(sprintf('Mail transport not set'));
     }
     $conflictTransports = $this->conflictTransports;
     $transportTypes = array_keys($transports);
     if (count(array_intersect($conflictTransports, $transportTypes)) > 1) {
         throw new Exception\InvalidArgumentException(sprintf('Mail transports conflicted by %s', implode(",", array_intersect($conflictTransports, $transportTypes))));
     }
     $zendMessage = new ZendMessage();
     $zendMessage->setBody($message->getBody());
     $zendMessage->setHeaders($message->getHeaders());
     $zendMessage->setEncoding($message->getEncoding());
     $message = $zendMessage;
     foreach ($transports as $transportType => $transport) {
         $transport->send($message);
     }
 }
开发者ID:ahyswang,项目名称:eva-engine,代码行数:24,代码来源:Mail.php

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

示例7: mailAdd

 public function mailAdd($version, $id, $srcNodeId, $srcUserNickname, $dstNodeId, $subject, $text, $checksum, $relayCount, $encryptionMode, $status, $timeCreated, $timeReceived)
 {
     $this->log->info('mail add: ' . $id);
     $this->log->info('subject: ' . $subject);
     $this->log->info('from: ' . $srcNodeId);
     $this->log->info('nick: ' . $srcUserNickname);
     $headers = new ZendMailHeaders();
     $headers->addHeaderLine('Date', date('r', $timeReceived));
     $headers->addHeaderLine('X-Version', $version);
     $headers->addHeaderLine('X-Id', $id);
     $headers->addHeaderLine('X-Checksum', $checksum);
     $headers->addHeaderLine('X-RelayCount', $relayCount);
     $headers->addHeaderLine('X-EncrptionMode', $encryptionMode);
     $headers->addHeaderLine('X-Status', $status);
     $headers->addHeaderLine('X-TimeCreated', $timeCreated);
     $headers->addHeaderLine('X-TimeReceived', $timeReceived);
     $message = new ZendMailMessage();
     $message->setHeaders($headers);
     $message->addFrom($srcNodeId . '@phpchat.fox21.at', $srcUserNickname);
     $message->addTo($dstNodeId . '@phpchat.fox21.at');
     $message->setSubject($subject);
     $message->setBody($text);
     $this->server->addMail($message);
 }
开发者ID:thefox,项目名称:phpchat,代码行数:24,代码来源:ImapCommand.php

示例8: read

 public function read()
 {
     // Setup filter array
     $filter_arr = array();
     // TO
     if (!empty($this->to_filter)) {
         $filter_arr[] = "TO " . $this->to_filter;
     }
     // FROM
     if (!empty($this->from_filter)) {
         $filter_arr[] = "FROM " . $this->from_filter;
     }
     // CC
     if (!empty($this->cc_filter)) {
         $filter_arr[] = "CC " . $this->cc_filter;
     }
     // SUBJECT
     if (!empty($this->subject_filter)) {
         $filter_arr[] = "SUBJECT " . $this->subject_filter;
     }
     // BODY
     if (!empty($this->body_filter)) {
         $filter_arr[] = "BODY " . $this->body_filter;
     }
     // UNSEEN
     $filter_arr[] = "UNSEEN";
     // Connect and fetch emails
     $this->w->Log->info("Connecting to mail server");
     $mail = $this->connectToMail();
     if (!empty($mail)) {
         $this->w->Log->info("Getting messages with filter: " . json_encode($filter_arr));
         $results = $mail->protocol->search($filter_arr);
         if (count($results) > 0) {
             $this->w->Log->info("Found " . count($results) . " messages, looping through");
             foreach ($results as $messagenum) {
                 $rawmessage = "";
                 $message = $mail->getMessage($messagenum);
                 $zend_message = new Zend_Mail_Message();
                 $zend_message->setHeaders($message->getHeaders());
                 $zend_message->setBody($message->getContent());
                 $email = new EmailStructure();
                 $email->to = $message->to;
                 $email->from = $message->from;
                 if (isset($message->cc)) {
                     $email->cc = $message->cc;
                 }
                 $email->subject = $message->subject;
                 //$email->body["html"] = $message->getContent();
                 $rawmessage .= $zend_message->toString();
                 // Create messages
                 $channel_message = new ChannelMessage($this->w);
                 $channel_message->channel_id = $this->channel_id;
                 $channel_message->message_type = "email";
                 // $channel_message->attachment_id = $attachment_id;
                 $channel_message->is_processed = 0;
                 $channel_message->insert();
                 // Save raw email
                 $attachment_id = $this->w->File->saveFileContent($channel_message, $rawmessage, str_replace(".", "", microtime()) . ".txt", "channel_email_raw", "text/plain");
                 if ($message->isMultipart()) {
                     foreach (new RecursiveIteratorIterator($message) as $part) {
                         try {
                             $contentType = strtok($part->contentType, ';');
                             switch ($contentType) {
                                 case "text/plain":
                                     $email->body["plain"] = trim($part->__toString());
                                     break;
                                 case "text/html":
                                     $email->body["html"] = trim($part->__toString());
                                     break;
                                 default:
                                     // Is probably an attachment so just save it
                                     $transferEncoding = $part->getHeader("Content-Transfer-Encoding")->getFieldValue("transferEncoding");
                                     $content_type_header = $part->getHeader("Content-Type");
                                     // Name is stored under "parameters" in an array
                                     $nameArray = $content_type_header->getParameters();
                                     $this->w->File->saveFileContent($channel_message, $transferEncoding == "base64" ? base64_decode(trim($part->__toString())) : trim($part->__toString()), !empty($nameArray["name"]) ? $nameArray["name"] : "attachment" . time(), "channel_email_attachment", $contentType);
                             }
                         } catch (Zend_Mail_Exception $e) {
                             // Ignore
                         }
                     }
                 }
                 $attachment_id = $this->w->File->saveFileContent($channel_message, serialize($email), "email.txt", "channel_email_raw", "text/plain");
             }
         } else {
             $this->w->Log->info("No new messages found");
         }
     }
 }
开发者ID:itillawarra,项目名称:cmfive,代码行数:89,代码来源:EmailChannelOption.php

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

示例10: packData

 /**
  * pack tagged array of data to SendMessage format
  *
  *
  * @param Array $mailArray
  *
  * return array of data that will be converted to
  * send message
  *
  * @return Array
  */
 public function packData($mailArray)
 {
     $mimeMail = new Message();
     $textPart = $this->packText($mailArray['text'], $mailArray['header']['content-type']);
     unset($mailArray['header']['content-type']);
     $attachmentParts = $this->packAttachments($mailArray['link']);
     if (count($attachmentParts)) {
         $mimeMail->addPart($textPart);
         foreach ($attachmentParts as $part) {
             $mimeMail->addPart($part);
         }
     } else {
         $mimeMail->addPart($textPart);
     }
     $returnMail = new SendMessage();
     $returnMail->setBody($mimeMail);
     foreach ($mailArray['header'] as $header => $value) {
         switch ($header) {
             case 'references':
                 if (is_array($value)) {
                     $res = '';
                     foreach ($value as $reference) {
                         $res .= $reference . ' ';
                     }
                 } elseif (is_string($value)) {
                     $res = $value;
                 } else {
                     continue;
                 }
                 $headers = $returnMail->getHeaders();
                 $headers->addHeaderLine($header, $res);
                 $returnMail->setHeaders($headers);
                 break;
             case 'bcc':
                 $returnMail->addBcc($value);
                 break;
             case 'cc':
                 $returnMail->addCc($value);
                 break;
             case 'to':
                 $returnMail->addTo($value);
                 break;
             case 'from':
                 $returnMail->addFrom($value);
                 break;
             case 'reply-to':
                 $returnMail->addReplyTo($value);
                 break;
             case 'subject':
                 $returnMail->setSubject($value);
                 break;
             default:
                 $headers = $returnMail->getHeaders();
                 $headers->addHeaderLine($header, $value);
                 $returnMail->setHeaders($headers);
                 break;
         }
     }
     return $returnMail;
 }
开发者ID:modelframework,项目名称:mailservice,代码行数:71,代码来源:DefaultComposeStrategy.php


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