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


PHP Swift_RecipientList::getIterator方法代码示例

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


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

示例1: send

 /**
  * Send a contact mail (text only) with the data provided by the given form.
  *
  * @uses Swift
  *
  * @throws InvalidArgumentException
  * @throws RuntimeException
  *
  * @param sfContactForm $form A valid contact form which contains the content.
  * @param sfContactFormDecorator $decorator Defaults to null. If given, the decorated subject and message will be used.
  *
  * @return bool True if all recipients got the mail.
  */
 public static function send(sfContactForm $form, sfContactFormDecorator $decorator = null)
 {
     if (!$form->isValid()) {
         throw new InvalidArgumentException('The given form is not valid.', 1);
     }
     if (!class_exists('Swift')) {
         throw new RuntimeException('Swift could not be found.');
     }
     // set up sender
     $from = sfConfig::get('sf_contactformplugin_from', false);
     if ($from === false) {
         throw new InvalidArgumentException('Configuration value of sf_contactformplugin_from is missing.', 2);
     }
     // where to send the contents of the contact form
     $mail = sfConfig::get('sf_contactformplugin_mail', false);
     if ($mail === false) {
         throw new InvalidArgumentException('Configuration value of sf_contactformplugin_mail is missing.', 3);
     }
     // set up mail content
     if (!is_null($decorator)) {
         $subject = $decorator->getSubject();
         $body = $decorator->getMessage();
     } else {
         $subject = $form->getValue('subject');
         $body = $form->getValue('message');
     }
     // set up recipients
     $recipients = new Swift_RecipientList();
     // check amount for given recipients
     $recipientCheck = 0;
     // use the sender as recipient to apply other recipients only as blind carbon copy
     $recipients->addTo($from);
     $recipientCheck++;
     // add a mail where to send the message
     $recipients->addBcc($mail);
     $recipientCheck++;
     // add sender to recipients, if chosen
     if ($form->getValue('sendcopy')) {
         $recipients->addBcc($form->getValue('email'));
         $recipientCheck++;
     }
     if (count($recipients->getIterator('bcc')) === 0) {
         throw new InvalidArgumentException('There are no recipients given.', 4);
     }
     // send the mail using swift
     try {
         $mailer = new Swift(new Swift_Connection_NativeMail());
         $message = new Swift_Message($subject, $body, 'text/plain');
         $countRecipients = $mailer->send($message, $recipients, $from);
         $mailer->disconnect();
         return $countRecipients == $recipientCheck;
     } catch (Exception $e) {
         $mailer->disconnect();
         throw $e;
     }
 }
开发者ID:havvg,项目名称:sfContactFormPlugin,代码行数:69,代码来源:sfContactFormMail.class.php

示例2: send

 /**
  * Send a message to any number of recipients
  * @param Swift_Message The message to send.  This does not need to (and shouldn't really) have any of the recipient headers set.
  * @param mixed The recipients to send to.  Can be a string, Swift_Address or Swift_RecipientList. Note that all addresses apart from Bcc recipients will appear in the message headers
  * @param mixed The address to send the message from.  Can either be a string or an instance of Swift_Address.
  * @return int The number of successful recipients
  * @throws Swift_ConnectionException If sending fails for any reason.
  */
 public function send(Swift_Message $message, $recipients, $from)
 {
     Swift_ClassLoader::load("Swift_Message_Encoder");
     if (is_string($recipients) && preg_match("/^" . Swift_Message_Encoder::CHEAP_ADDRESS_RE . "\$/", $recipients)) {
         $recipients = new Swift_Address($recipients);
     } elseif (!$recipients instanceof Swift_AddressContainer) {
         throw new Exception("The recipients parameter must either be a valid string email address, " . "an instance of Swift_RecipientList or an instance of Swift_Address.");
     }
     if (is_string($from) && preg_match("/^" . Swift_Message_Encoder::CHEAP_ADDRESS_RE . "\$/", $from)) {
         $from = new Swift_Address($from);
     } elseif (!$from instanceof Swift_Address) {
         throw new Exception("The sender parameter must either be a valid string email address or " . "an instance of Swift_Address.");
     }
     $log = Swift_LogContainer::getLog();
     if (!$message->getEncoding() && !$this->connection->hasExtension("8BITMIME")) {
         $message->setEncoding("QP", true, true);
     }
     $list = $recipients;
     if ($recipients instanceof Swift_Address) {
         $list = new Swift_RecipientList();
         $list->addTo($recipients);
     }
     Swift_ClassLoader::load("Swift_Events_SendEvent");
     $send_event = new Swift_Events_SendEvent($message, $list, $from, 0);
     $this->notifyListeners($send_event, "BeforeSendListener");
     $to = $cc = array();
     if (!($has_from = $message->getFrom())) {
         $message->setFrom($from);
     }
     if (!($has_return_path = $message->getReturnPath())) {
         $message->setReturnPath($from->build(true));
     }
     if (!($has_reply_to = $message->getReplyTo())) {
         $message->setReplyTo($from);
     }
     if (!$has_reply_to[0]) {
         $message->setReplyTo($from->getAddress());
     }
     if (!($has_message_id = $message->getId())) {
         $message->generateId();
     }
     $this->command("MAIL FROM: " . $message->getReturnPath(true), 250);
     $failed = 0;
     $sent = 0;
     $tmp_sent = 0;
     $it = $list->getIterator("to");
     while ($it->hasNext()) {
         $it->next();
         $address = $it->getValue();
         $to[] = $address->build();
         try {
             $this->command("RCPT TO: " . $address->build(true), 250);
             $tmp_sent++;
         } catch (Swift_BadResponseException $e) {
             $failed++;
             $send_event->addFailedRecipient($address->getAddress());
             if ($log->hasLevel(Swift_Log::LOG_FAILURES)) {
                 $log->addfailedRecipient($address->getAddress());
             }
         }
     }
     $it = $list->getIterator("cc");
     while ($it->hasNext()) {
         $it->next();
         $address = $it->getValue();
         $cc[] = $address->build();
         try {
             $this->command("RCPT TO: " . $address->build(true), 250);
             $tmp_sent++;
         } catch (Swift_BadResponseException $e) {
             $failed++;
             $send_event->addFailedRecipient($address->getAddress());
             if ($log->hasLevel(Swift_Log::LOG_FAILURES)) {
                 $log->addfailedRecipient($address->getAddress());
             }
         }
     }
     if ($failed == count($to) + count($cc)) {
         $this->reset();
         $this->notifyListeners($send_event, "SendListener");
         return 0;
     }
     if (!($has_to = $message->getTo()) && !empty($to)) {
         $message->setTo($to);
     }
     if (!($has_cc = $message->getCc()) && !empty($cc)) {
         $message->setCc($cc);
     }
     $this->command("DATA", 354);
     $data = $message->build();
     while (false !== ($bytes = $data->read())) {
         $this->command($bytes, -1);
//.........这里部分代码省略.........
开发者ID:jenia0jenia,项目名称:otk,代码行数:101,代码来源:Swift.php

示例3: send

 /**
  * Run a batch send in a fail-safe manner.
  * This operates as Swift::batchSend() except it deals with errors itself.
  * @param Swift_Message To send
  * @param Swift_RecipientList Recipients (To: only)
  * @param Swift_Address The sender's address
  * @return int The number sent to
  */
 public function send(Swift_Message $message, Swift_RecipientList $recipients, $sender)
 {
     $sent = 0;
     $successive_fails = 0;
     $it = $recipients->getIterator("to");
     while ($it->hasNext()) {
         $it->next();
         $recipient = $it->getValue();
         $tried = 0;
         $loop = true;
         while ($loop && $tried < $this->getMaxTries()) {
             try {
                 $tried++;
                 $loop = false;
                 $this->copyMessageHeaders($message);
                 $sent += $n = $this->swift->send($message, $recipient, $sender);
                 if (!$n) {
                     $this->addFailedRecipient($recipient->getAddress());
                 }
                 $successive_fails = 0;
             } catch (Exception $e) {
                 $successive_fails++;
                 $this->restoreMessageHeaders($message);
                 if (($max = $this->getMaxSuccessiveFailures()) && $successive_fails > $max) {
                     throw new Exception("Too many successive failures. BatchMailer is configured to allow no more than " . $max . " successive failures.");
                 }
                 //If an exception was thrown, give it one more go
                 if ($t = $this->getSleepTime()) {
                     sleep($t);
                 }
                 $this->forceRestartSwift();
                 $loop = true;
             }
         }
     }
     return $sent;
 }
开发者ID:AlexanderS,项目名称:Part-DB,代码行数:45,代码来源:BatchMailer.php


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