XOOPS RMCommon Utilities  2.1.8.91RC
 All Classes Namespaces Files Functions Variables
Mailer.php
Go to the documentation of this file.
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 //@require 'Swift/Transport.php';
12 //@require 'Swift/Mime/Message.php';
13 //@require 'Swift/Mailer/RecipientIterator.php';
14 //@require 'Swift/Events/EventListener.php';
15 
23 {
24 
26  private $_transport;
27 
33  public function __construct(Swift_Transport $transport)
34  {
35  $this->_transport = $transport;
36  }
37 
44  public static function newInstance(Swift_Transport $transport)
45  {
46  return new self($transport);
47  }
48 
68  public function send(Swift_Mime_Message $message, &$failedRecipients = null)
69  {
70  $failedRecipients = (array) $failedRecipients;
71 
72  if (!$this->_transport->isStarted())
73  {
74  $this->_transport->start();
75  }
76 
77  return $this->_transport->send($message, $failedRecipients);
78  }
79 
102  public function batchSend(Swift_Mime_Message $message,
103  &$failedRecipients = null,
105  {
106  $failedRecipients = (array) $failedRecipients;
107 
108  $sent = 0;
109  $to = $message->getTo();
110  $cc = $message->getCc();
111  $bcc = $message->getBcc();
112 
113  if (!empty($cc))
114  {
115  $message->setCc(array());
116  }
117  if (!empty($bcc))
118  {
119  $message->setBcc(array());
120  }
121 
122  //Use an iterator if set
123  if (isset($it))
124  {
125  while ($it->hasNext())
126  {
127  $message->setTo($it->nextRecipient());
128  $sent += $this->send($message, $failedRecipients);
129  }
130  }
131  else
132  {
133  foreach ($to as $address => $name)
134  {
135  $message->setTo(array($address => $name));
136  $sent += $this->send($message, $failedRecipients);
137  }
138  }
139 
140  $message->setTo($to);
141 
142  if (!empty($cc))
143  {
144  $message->setCc($cc);
145  }
146  if (!empty($bcc))
147  {
148  $message->setBcc($bcc);
149  }
150 
151  return $sent;
152  }
153 
161  {
162  $this->_transport->registerPlugin($plugin);
163  }
164 
169  public function getTransport()
170  {
171  return $this->_transport;
172  }
173 }