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


PHP Message::fromString方法代码示例

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


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

示例1: run

 public function run()
 {
     // Read the contents of the message in from the buffer
     $src = '';
     $stream = fopen($this->_emailSource, 'r');
     // The first line in the stream is a postfix message, so we discard it
     fgets($stream);
     while ($line = fgets($stream)) {
         $src .= $line;
     }
     fclose($stream);
     // Create a Zend\Mail\Message object with our message
     $email = \Zend\Mail\Message::fromString($src);
     $from = $email->getHeaders()->get('From')->getAddressList()->current()->getEmail();
     $email->setTo($from);
     // Create our transport
     $transport = new \Zend\Mail\Transport\Smtp();
     $options = new \Zend\Mail\Transport\SmtpOptions(array('host' => $this->_opts['smtp_server']));
     $transport->setOptions($options);
     $transport->send($email);
 }
开发者ID:BlueHornet,项目名称:Trampoline,代码行数:21,代码来源:Relay.php

示例2: testEvent

 public function testEvent()
 {
     $server = new Server('', 0);
     $server->setLog(new Logger('test_application'));
     $server->init();
     $testData = 21;
     $event1 = new Event(Event::TRIGGER_MAIL_NEW, null, function ($event, $from, $rcpt, $mail) use(&$testData) {
         #fwrite(STDOUT, 'my function: '.$event->getTrigger().', '.$testData."\n");
         $testData = 24;
         $this->assertEquals('from@example.com', $from);
         $this->assertEquals(array('to1@example.com', 'to2@example.com', 'cc@example.com', 'bcc@example.com'), $rcpt);
         $current = array();
         foreach ($mail->getTo() as $n => $address) {
             $current[] = $address->toString();
         }
         $this->assertEquals(array('Joe User <to1@example.com>', '<to2@example.com>'), $current);
         $this->assertEquals('Here is the subject', $mail->getSubject());
         return 42;
     });
     $server->eventAdd($event1);
     $mail = '';
     $mail .= 'Date: Thu, 31 Jul 2014 22:18:51 +0200' . Client::MSG_SEPARATOR;
     $mail .= 'To: Joe User <to1@example.com>, to2@example.com' . Client::MSG_SEPARATOR;
     $mail .= 'From: Mailer <from@example.com>' . Client::MSG_SEPARATOR;
     $mail .= 'Cc: cc@example.com' . Client::MSG_SEPARATOR;
     $mail .= 'Reply-To: Information <reply@example.com>' . Client::MSG_SEPARATOR;
     $mail .= 'Subject: Here is the subject' . Client::MSG_SEPARATOR;
     $mail .= 'MIME-Version: 1.0' . Client::MSG_SEPARATOR;
     $mail .= 'Content-Type: text/plain; charset=iso-8859-1' . Client::MSG_SEPARATOR;
     $mail .= 'Content-Transfer-Encoding: 8bit' . Client::MSG_SEPARATOR;
     $mail .= '' . Client::MSG_SEPARATOR;
     $mail .= 'This is the message body.' . Client::MSG_SEPARATOR;
     $mail .= 'END' . Client::MSG_SEPARATOR;
     $zmail = Message::fromString($mail);
     $rcpt = array('to1@example.com', 'to2@example.com', 'cc@example.com', 'bcc@example.com');
     $server->mailNew('from@example.com', $rcpt, $zmail);
     $this->assertEquals(24, $testData);
     $this->assertEquals(42, $event1->getReturnValue());
 }
开发者ID:mambaru,项目名称:smtpd,代码行数:39,代码来源:ServerTest.php

示例3: msgHandle


//.........这里部分代码省略.........
                 return $this->sendOk();
             } else {
                 return $this->sendSyntaxErrorInParameters();
             }
         } else {
             return $this->sendSyntaxErrorCommandUnrecognized();
         }
     } elseif ($commandcmp == 'data') {
         #$this->log('debug', 'client '.$this->id.' data');
         if ($this->getStatus('hasHello')) {
             $this->setStatus('hasData', true);
             return $this->sendDataResponse();
         } else {
             return $this->sendSyntaxErrorCommandUnrecognized();
         }
     } elseif ($commandcmp == 'noop') {
         return $this->sendOk();
     } elseif ($commandcmp == 'quit') {
         $rv .= $this->sendQuit();
         $this->shutdown();
     } elseif ($commandcmp == 'auth') {
         $this->setStatus('hasAuth', true);
         if (empty($args)) {
             return $this->sendSyntaxErrorInParameters();
         }
         $authentication = strtolower($args[0]);
         if ($authentication == 'plain') {
             $this->setStatus('hasAuthPlain', true);
             if (isset($args[1])) {
                 $this->setStatus('hasAuthPlainUser', true);
                 $this->setCredentials(array($args[1]));
                 if ($this->authenticate('plain')) {
                     return $this->sendAuthSuccessResponse();
                 }
                 return $this->sendAuthInvalid();
             }
             return $this->sendAuthPlainResponse();
         } elseif ($authentication == 'login') {
             $this->setStatus('hasAuthLogin', true);
             return $this->sendAskForUserResponse();
         } elseif ($authentication == 'cram-md5') {
             return $this->sendCommandNotImplemented();
         } else {
             return $this->sendSyntaxErrorInParameters();
         }
     } elseif ($commandcmp == 'starttls') {
         if (!empty($args)) {
             return $this->sendSyntaxErrorInParameters();
         }
         $this->sendReadyStartTls();
         try {
             return $this->getSocket()->enableEncryption();
         } catch (RuntimeException $e) {
             return $this->sendTemporaryErrorStartTls();
         }
     } elseif ($commandcmp == 'help') {
         return $this->sendOk('HELO, EHLO, MAIL FROM, RCPT TO, DATA, NOOP, QUIT');
     } else {
         if ($this->getStatus('hasAuth')) {
             if ($this->getStatus('hasAuthPlain')) {
                 $this->setStatus('hasAuthPlainUser', true);
                 $this->setCredentials(array($command));
                 if ($this->authenticate('plain')) {
                     return $this->sendAuthSuccessResponse();
                 }
                 return $this->sendAuthInvalid();
             } elseif ($this->getStatus('hasAuthLogin')) {
                 $credentials = $this->getCredentials();
                 if ($this->getStatus('hasAuthLoginUser')) {
                     $credentials['password'] = $command;
                     $this->setCredentials($credentials);
                     if ($this->authenticate('login')) {
                         return $this->sendAuthSuccessResponse();
                     }
                     return $this->sendAuthInvalid();
                 }
                 $this->setStatus('hasAuthLoginUser', true);
                 $credentials['user'] = $command;
                 $this->setCredentials($credentials);
                 return $this->sendAskForPasswordResponse();
             }
         } elseif ($this->getStatus('hasData')) {
             if ($msgRaw == '.') {
                 $this->mail = substr($this->mail, 0, -strlen(static::MSG_SEPARATOR));
                 $zmail = Message::fromString($this->mail);
                 $this->getServer()->mailNew($this->from, $this->rcpt, $zmail);
                 $this->from = '';
                 $this->rcpt = array();
                 $this->mail = '';
                 return $this->sendOk();
             } else {
                 $this->mail .= $msgRaw . static::MSG_SEPARATOR;
             }
         } else {
             $this->log('debug', 'client ' . $this->id . ' not implemented: /' . $command . '/ - /' . join('/ /', $args) . '/');
             return $this->sendSyntaxErrorCommandUnrecognized();
         }
     }
     return $rv;
 }
开发者ID:thefox,项目名称:smtpd,代码行数:101,代码来源:Client.php

示例4: emailFromFile

 /**
  * Email from file
  *
  * Given a filename, returns the email's object
  *
  * @return Zend\Mail\Message
  * @author Koen Punt
  **/
 protected function emailFromFile($email)
 {
     return Message::fromString(file_get_contents($email));
 }
开发者ID:fetch,项目名称:zend-mail-codeception-module,代码行数:12,代码来源:ZendMail.php

示例5: testRestoreFromSerializedString

 public function testRestoreFromSerializedString()
 {
     $this->message->addTo('zf-devteam@example.com', 'ZF DevTeam');
     $this->message->addFrom('matthew@example.com', "Matthew Weier O'Phinney");
     $this->message->addCc('zf-contributors@example.com', 'ZF Contributors List');
     $this->message->setSubject('This is a subject');
     $this->message->setBody('foo');
     $serialized = $this->message->toString();
     $restoredMessage = Message::fromString($serialized);
     $this->assertEquals($serialized, $restoredMessage->toString());
 }
开发者ID:pnaq57,项目名称:zf2demo,代码行数:11,代码来源:MessageTest.php

示例6: sendAppend

 private function sendAppend($data = '')
 {
     $appendMsgLen = strlen($this->getStatus('appendMsg'));
     #$this->log('debug', 'client '.$this->id.' append step: '.$this->getStatus('appendStep'));
     #$this->log('debug', 'client '.$this->id.' append len: '.$appendMsgLen);
     #$this->log('debug', 'client '.$this->id.' append lit: '.$this->getStatus('appendLiteral'));
     if ($this->getStatus('appendStep') == 1) {
         $this->status['appendStep']++;
         return $this->dataSend('+ Ready for literal data');
     } elseif ($this->getStatus('appendStep') == 2) {
         if ($appendMsgLen < $this->getStatus('appendLiteral')) {
             $this->status['appendMsg'] .= $data . Headers::EOL;
             $appendMsgLen = strlen($this->getStatus('appendMsg'));
         }
         if ($appendMsgLen >= $this->getStatus('appendLiteral')) {
             $this->status['appendStep']++;
             $this->log('debug', 'client ' . $this->id . ' append len reached: ' . $appendMsgLen);
             $message = Message::fromString($this->getStatus('appendMsg'));
             try {
                 $this->getServer()->addMail($message, $this->getStatus('appendFolder'), $this->getStatus('appendFlags'), false);
                 $this->log('debug', 'client ' . $this->id . ' append completed: ' . $this->getStatus('appendStep'));
                 return $this->sendOk('APPEND completed', $this->getStatus('appendTag'));
             } catch (Exception $e) {
                 $noMsg = 'Can not get folder: ' . $this->getStatus('appendFolder');
                 return $this->sendNo($noMsg, $this->getStatus('appendTag'), 'TRYCREATE');
             }
         } else {
             $diff = $this->getStatus('appendLiteral') - $appendMsgLen;
             $this->log('debug', 'client ' . $this->id . ' append left: ' . $diff . ' (' . $appendMsgLen . ')');
         }
     }
 }
开发者ID:thefox,项目名称:imapd,代码行数:32,代码来源:Client.php

示例7: getMailById

 public function getMailById($msgId)
 {
     $storage = $this->getDefaultStorage();
     $mailStr = $storage->getPlainMailById($msgId);
     $mail = ZendMailMessage::fromString($mailStr);
     return $mail;
 }
开发者ID:thefox,项目名称:imapd,代码行数:7,代码来源:Server.php


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