|
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
|
11 |
|
public function __construct(Swift_Transport $transport) |
|
27
|
|
|
{ |
|
28
|
11 |
|
$this->_transport = $transport; |
|
29
|
11 |
|
} |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* Create a new Mailer instance. |
|
33
|
|
|
* |
|
34
|
|
|
* @param Swift_Transport $transport |
|
35
|
|
|
* |
|
36
|
|
|
* @return self |
|
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
|
|
|
* @throws Swift_DependencyException |
|
53
|
|
|
*/ |
|
54
|
|
|
public function createMessage($service = 'message') |
|
55
|
|
|
{ |
|
56
|
|
|
return Swift_DependencyContainer::getInstance()->lookup('message.' . $service); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* Send the given Message like it would be sent in a mail client. |
|
61
|
|
|
* |
|
62
|
|
|
* All recipients (with the exception of Bcc) will be able to see the other |
|
63
|
|
|
* recipients this message was sent to. |
|
64
|
|
|
* |
|
65
|
|
|
* Recipient/sender data will be retrieved from the Message object. |
|
66
|
|
|
* |
|
67
|
|
|
* The return value is the number of recipients who were accepted for |
|
68
|
|
|
* delivery. |
|
69
|
|
|
* |
|
70
|
|
|
* @param Swift_Mime_Message $message |
|
71
|
|
|
* @param array $failedRecipients An array of failures by-reference |
|
72
|
|
|
* |
|
73
|
|
|
* @return int The number of successful recipients. Can be 0 which indicates failure |
|
74
|
|
|
*/ |
|
75
|
10 |
|
public function send(Swift_Mime_Message $message, &$failedRecipients = null) |
|
76
|
|
|
{ |
|
77
|
10 |
|
$failedRecipients = (array) $failedRecipients; |
|
78
|
|
|
|
|
79
|
10 |
|
if (!$this->_transport->isStarted()) { |
|
80
|
10 |
|
$this->_transport->start(); |
|
81
|
10 |
|
} |
|
82
|
|
|
|
|
83
|
10 |
|
$sent = 0; |
|
84
|
|
|
|
|
85
|
|
|
try { |
|
86
|
10 |
|
$sent = $this->_transport->send($message, $failedRecipients); |
|
87
|
10 |
|
} catch (Swift_RfcComplianceException $e) { |
|
88
|
1 |
|
foreach ($message->getTo() as $address => $name) { |
|
89
|
1 |
|
$failedRecipients[] = $address; |
|
90
|
1 |
|
} |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
10 |
|
return $sent; |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
/** |
|
97
|
|
|
* Register a plugin using a known unique key (e.g. myPlugin). |
|
98
|
|
|
* |
|
99
|
|
|
* @param Swift_Events_EventListener $plugin |
|
100
|
|
|
*/ |
|
101
|
1 |
|
public function registerPlugin(Swift_Events_EventListener $plugin) |
|
102
|
|
|
{ |
|
103
|
1 |
|
$this->_transport->registerPlugin($plugin); |
|
104
|
1 |
|
} |
|
105
|
|
|
|
|
106
|
|
|
/** |
|
107
|
|
|
* The Transport used to send messages. |
|
108
|
|
|
* |
|
109
|
|
|
* @return Swift_Transport |
|
110
|
|
|
*/ |
|
111
|
|
|
public function getTransport() |
|
112
|
|
|
{ |
|
113
|
|
|
return $this->_transport; |
|
114
|
|
|
} |
|
115
|
|
|
} |
|
116
|
|
|
|
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.