vendor/swiftmailer/lib/classes/Swift/Mailer.php
changeset 0 7f95f8617b0b
equal deleted inserted replaced
-1:000000000000 0:7f95f8617b0b
       
     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 /**
       
    13  * Swift Mailer class.
       
    14  * 
       
    15  * @package Swift
       
    16  * @author Chris Corbyn
       
    17  */
       
    18 class Swift_Mailer
       
    19 {
       
    20   
       
    21   /** The Transport used to send messages */
       
    22   private $_transport;
       
    23   
       
    24   /**
       
    25    * Create a new Mailer using $transport for delivery.
       
    26    * 
       
    27    * @param Swift_Transport $transport
       
    28    */
       
    29   public function __construct(Swift_Transport $transport)
       
    30   {
       
    31     $this->_transport = $transport;
       
    32   }
       
    33 
       
    34   /**
       
    35    * Create a new Mailer instance.
       
    36    * 
       
    37    * @param Swift_Transport $transport
       
    38    * @return Swift_Mailer
       
    39    */
       
    40   public static function newInstance(Swift_Transport $transport)
       
    41   {
       
    42     return new self($transport);
       
    43   }
       
    44 
       
    45   /**
       
    46    * Create a new class instance of one if the message services
       
    47    * For example 'mimepart' would create a 'message.mimepart' instance
       
    48    *
       
    49    * @param string $service
       
    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 retreived 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, optional
       
    71    * @return int
       
    72    */
       
    73   public function send(Swift_Mime_Message $message, &$failedRecipients = null)
       
    74   {
       
    75     $failedRecipients = (array) $failedRecipients;
       
    76     
       
    77     if (!$this->_transport->isStarted())
       
    78     {
       
    79       $this->_transport->start();
       
    80     }
       
    81     
       
    82     $sent = 0;
       
    83     
       
    84     try
       
    85     {
       
    86       $sent = $this->_transport->send($message, $failedRecipients);
       
    87     }
       
    88     catch (Swift_RfcComplianceException $e)
       
    89     {
       
    90       foreach ($message->getTo() as $address => $name)
       
    91       {
       
    92         $failedRecipients[] = $address;
       
    93       }
       
    94     }
       
    95     
       
    96     return $sent;
       
    97   }
       
    98   
       
    99   /**
       
   100    * Register a plugin using a known unique key (e.g. myPlugin).
       
   101    * 
       
   102    * @param Swift_Events_EventListener $plugin
       
   103    * @param string $key
       
   104    */
       
   105   public function registerPlugin(Swift_Events_EventListener $plugin)
       
   106   {
       
   107     $this->_transport->registerPlugin($plugin);
       
   108   }
       
   109   
       
   110   /**
       
   111    * The Transport used to send messages.
       
   112    * @return Swift_Transport
       
   113    */
       
   114   public function getTransport()
       
   115   {
       
   116     return $this->_transport;
       
   117   }
       
   118 }