Avail feature updated
[ninja.git] / application / vendor / swiftmailer / classes / Swift / Mailer.php
blobc92feb41b39842c191f40f9f0d18372a7e2852b5
1 <?php
3 /*
4 * This file is part of SwiftMailer.
5 * (c) 2004-2009 Chris Corbyn
7 * For the full copyright and license information, please view the LICENSE
8 * file that was distributed with this source code.
9 */
11 //@require 'Swift/Transport.php';
12 //@require 'Swift/Mime/Message.php';
13 //@require 'Swift/Mailer/RecipientIterator.php';
14 //@require 'Swift/Events/EventListener.php';
16 /**
17 * Swift Mailer class.
19 * @package Swift
20 * @author Chris Corbyn
22 class Swift_Mailer
25 /** The Transport used to send messages */
26 private $_transport;
28 /**
29 * Create a new Mailer using $transport for delivery.
31 * @param Swift_Transport $transport
33 public function __construct(Swift_Transport $transport)
35 $this->_transport = $transport;
38 /**
39 * Create a new Mailer instance.
41 * @param Swift_Transport $transport
42 * @return Swift_Mailer
44 public static function newInstance(Swift_Transport $transport)
46 return new self($transport);
49 /**
50 * Send the given Message like it would be sent in a mail client.
52 * All recipients (with the exception of Bcc) will be able to see the other
53 * recipients this message was sent to.
55 * If you need to send to each recipient without disclosing details about the
56 * other recipients see {@link batchSend()}.
58 * Recipient/sender data will be retreived from the Message object.
60 * The return value is the number of recipients who were accepted for
61 * delivery.
63 * @param Swift_Mime_Message $message
64 * @param array &$failedRecipients, optional
65 * @return int
66 * @see batchSend()
68 public function send(Swift_Mime_Message $message, &$failedRecipients = null)
70 $failedRecipients = (array) $failedRecipients;
72 if (!$this->_transport->isStarted())
74 $this->_transport->start();
77 return $this->_transport->send($message, $failedRecipients);
80 /**
81 * Send the given Message to all recipients individually.
83 * This differs from {@link send()} in the way headers are presented to the
84 * recipient. The only recipient in the "To:" field will be the individual
85 * recipient it was sent to.
87 * If an iterator is provided, recipients will be read from the iterator
88 * one-by-one, otherwise recipient data will be retreived from the Message
89 * object.
91 * Sender information is always read from the Message object.
93 * The return value is the number of recipients who were accepted for
94 * delivery.
96 * @param Swift_Mime_Message $message
97 * @param array &$failedRecipients, optional
98 * @param Swift_Mailer_RecipientIterator $it, optional
99 * @return int
100 * @see send()
102 public function batchSend(Swift_Mime_Message $message,
103 &$failedRecipients = null,
104 Swift_Mailer_RecipientIterator $it = null)
106 $failedRecipients = (array) $failedRecipients;
108 $sent = 0;
109 $to = $message->getTo();
110 $cc = $message->getCc();
111 $bcc = $message->getBcc();
113 if (!empty($cc))
115 $message->setCc(array());
117 if (!empty($bcc))
119 $message->setBcc(array());
122 //Use an iterator if set
123 if (isset($it))
125 while ($it->hasNext())
127 $message->setTo($it->nextRecipient());
128 $sent += $this->send($message, $failedRecipients);
131 else
133 foreach ($to as $address => $name)
135 $message->setTo(array($address => $name));
136 $sent += $this->send($message, $failedRecipients);
140 $message->setTo($to);
142 if (!empty($cc))
144 $message->setCc($cc);
146 if (!empty($bcc))
148 $message->setBcc($bcc);
151 return $sent;
155 * Register a plugin using a known unique key (e.g. myPlugin).
157 * @param Swift_Events_EventListener $plugin
158 * @param string $key
160 public function registerPlugin(Swift_Events_EventListener $plugin)
162 $this->_transport->registerPlugin($plugin);
166 * The Transport used to send messages.
167 * @return Swift_Transport
169 public function getTransport()
171 return $this->_transport;