[ Index ]

MailPress 544

[ Index ]     [ Classes ]     [ Functions ]     [ Variables ]     [ Constants ]     [ Statistics ]    

title

Body

[close]

/mp-includes/Swiftmailer/classes/Swift/ -> Mailer.php (source)

   1  <?php
   2  
   3  /*
   4   * This file is part of SwiftMailer.
   5   * (c) 2004-2009 Chris Corbyn
   6   *
   7   * For the full copyright and license information, please view the LICENSE
   8   * file that was distributed with this source code.
   9   */
  10  
  11  /**
  12   * Swift Mailer class.
  13   *
  14   * @author Chris Corbyn
  15   */
  16  class Swift_Mailer
  17  {
  18      /** The Transport used to send messages */
  19      private $_transport;
  20  
  21      /**
  22       * Create a new Mailer using $transport for delivery.
  23       *
  24       * @param Swift_Transport $transport
  25       */
  26      public function __construct(Swift_Transport $transport)
  27      {
  28          $this->_transport = $transport;
  29      }
  30  
  31      /**
  32       * Create a new Mailer instance.
  33       *
  34       * @param Swift_Transport $transport
  35       *
  36       * @return Swift_Mailer
  37       */
  38      public static function newInstance(Swift_Transport $transport)
  39      {
  40          return new self($transport);
  41      }
  42  
  43      /**
  44       * Create a new class instance of one of the message services.
  45       *
  46       * For example 'mimepart' would create a 'message.mimepart' instance
  47       *
  48       * @param string $service
  49       *
  50       * @return object
  51       */
  52      public function createMessage($service = 'message')
  53      {
  54          return Swift_DependencyContainer::getInstance()
  55              ->lookup('message.'.$service);
  56      }
  57  
  58      /**
  59       * Send the given Message like it would be sent in a mail client.
  60       *
  61       * All recipients (with the exception of Bcc) will be able to see the other
  62       * recipients this message was sent to.
  63       *
  64       * Recipient/sender data will be retrieved from the Message object.
  65       *
  66       * The return value is the number of recipients who were accepted for
  67       * delivery.
  68       *
  69       * @param Swift_Mime_Message $message
  70       * @param array              $failedRecipients An array of failures by-reference
  71       *
  72       * @return int
  73       */
  74      public function send(Swift_Mime_Message $message, &$failedRecipients = null)
  75      {
  76          $failedRecipients = (array) $failedRecipients;
  77  
  78          if (!$this->_transport->isStarted()) {
  79              $this->_transport->start();
  80          }
  81  
  82          $sent = 0;
  83  
  84          try {
  85              $sent = $this->_transport->send($message, $failedRecipients);
  86          } catch (Swift_RfcComplianceException $e) {
  87              foreach ($message->getTo() as $address => $name) {
  88                  $failedRecipients[] = $address;
  89              }
  90          }
  91  
  92          return $sent;
  93      }
  94  
  95      /**
  96       * Register a plugin using a known unique key (e.g. myPlugin).
  97       *
  98       * @param Swift_Events_EventListener $plugin
  99       */
 100      public function registerPlugin(Swift_Events_EventListener $plugin)
 101      {
 102          $this->_transport->registerPlugin($plugin);
 103      }
 104  
 105      /**
 106       * The Transport used to send messages.
 107       *
 108       * @return Swift_Transport
 109       */
 110      public function getTransport()
 111      {
 112          return $this->_transport;
 113      }
 114  }


Generated: Thu Apr 28 18:38:52 2016 Cross-referenced by PHPXref 0.7.1