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: * @package Swift
15: * @author Chris Corbyn
16: */
17: class Swift_Mailer
18: {
19: /** The Transport used to send messages */
20: private $_transport;
21:
22: /**
23: * Create a new Mailer using $transport for delivery.
24: *
25: * @param Swift_Transport $transport
26: */
27: public function __construct(Swift_Transport $transport)
28: {
29: $this->_transport = $transport;
30: }
31:
32: /**
33: * Create a new Mailer instance.
34: *
35: * @param Swift_Transport $transport
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: * For example 'mimepart' would create a 'message.mimepart' instance
46: *
47: * @param string $service
48: * @return object
49: */
50: public function createMessage($service = 'message')
51: {
52: return Swift_DependencyContainer::getInstance()
53: ->lookup('message.'.$service);
54: }
55:
56: /**
57: * Send the given Message like it would be sent in a mail client.
58: *
59: * All recipients (with the exception of Bcc) will be able to see the other
60: * recipients this message was sent to.
61: *
62: * Recipient/sender data will be retrieved from the Message object.
63: *
64: * The return value is the number of recipients who were accepted for
65: * delivery.
66: *
67: * @param Swift_Mime_Message $message
68: * @param array &$failedRecipients, optional
69: * @return int
70: */
71: public function send(Swift_Mime_Message $message, &$failedRecipients = null)
72: {
73: $failedRecipients = (array) $failedRecipients;
74:
75: if (!$this->_transport->isStarted()) {
76: $this->_transport->start();
77: }
78:
79: $sent = 0;
80:
81: try {
82: $sent = $this->_transport->send($message, $failedRecipients);
83: } catch (Swift_RfcComplianceException $e) {
84: foreach ($message->getTo() as $address => $name) {
85: $failedRecipients[] = $address;
86: }
87: }
88:
89: return $sent;
90: }
91:
92: /**
93: * Register a plugin using a known unique key (e.g. myPlugin).
94: *
95: * @param Swift_Events_EventListener $plugin
96: * @param string $key
97: */
98: public function registerPlugin(Swift_Events_EventListener $plugin)
99: {
100: $this->_transport->registerPlugin($plugin);
101: }
102:
103: /**
104: * The Transport used to send messages.
105: * @return Swift_Transport
106: */
107: public function getTransport()
108: {
109: return $this->_transport;
110: }
111: }
112: