| 1 |
<?php |
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
|
|---|
| 20 |
class sfMail |
|---|
| 21 |
{ |
|---|
| 22 |
protected $mailer; |
|---|
| 23 |
|
|---|
| 24 |
public function __construct() |
|---|
| 25 |
{ |
|---|
| 26 |
require_once(sfConfig::get('sf_symfony_lib_dir').'/vendor/phpmailer/class.phpmailer.php'); |
|---|
| 27 |
require_once(sfConfig::get('sf_symfony_lib_dir').'/vendor/phpmailer/class.smtp.php'); |
|---|
| 28 |
|
|---|
| 29 |
$this->mailer = new PHPMailer(); |
|---|
| 30 |
} |
|---|
| 31 |
|
|---|
| 32 |
public function initialize() |
|---|
| 33 |
{ |
|---|
| 34 |
} |
|---|
| 35 |
|
|---|
| 36 |
public function setCharset($charset) |
|---|
| 37 |
{ |
|---|
| 38 |
$this->mailer->CharSet = $charset; |
|---|
| 39 |
} |
|---|
| 40 |
|
|---|
| 41 |
public function getCharset() |
|---|
| 42 |
{ |
|---|
| 43 |
return $this->mailer->CharSet; |
|---|
| 44 |
} |
|---|
| 45 |
|
|---|
| 46 |
public function setContentType($content_type) |
|---|
| 47 |
{ |
|---|
| 48 |
$this->mailer->ContentType = $content_type; |
|---|
| 49 |
} |
|---|
| 50 |
|
|---|
| 51 |
public function getContentType() |
|---|
| 52 |
{ |
|---|
| 53 |
return $this->mailer->ContentType; |
|---|
| 54 |
} |
|---|
| 55 |
|
|---|
| 56 |
public function setPriority($priority) |
|---|
| 57 |
{ |
|---|
| 58 |
$this->mailer->Priority = $priority; |
|---|
| 59 |
} |
|---|
| 60 |
|
|---|
| 61 |
public function getPriority() |
|---|
| 62 |
{ |
|---|
| 63 |
return $this->mailer->Priority; |
|---|
| 64 |
} |
|---|
| 65 |
|
|---|
| 66 |
public function setEncoding($encoding) |
|---|
| 67 |
{ |
|---|
| 68 |
$this->mailer->Encoding = $encoding; |
|---|
| 69 |
} |
|---|
| 70 |
|
|---|
| 71 |
public function getEncoding() |
|---|
| 72 |
{ |
|---|
| 73 |
return $this->mailer->Encoding; |
|---|
| 74 |
} |
|---|
| 75 |
|
|---|
| 76 |
public function setSubject($subject) |
|---|
| 77 |
{ |
|---|
| 78 |
$this->mailer->Subject = $subject; |
|---|
| 79 |
} |
|---|
| 80 |
|
|---|
| 81 |
public function getSubject() |
|---|
| 82 |
{ |
|---|
| 83 |
return $this->mailer->Subject; |
|---|
| 84 |
} |
|---|
| 85 |
|
|---|
| 86 |
public function setBody($body) |
|---|
| 87 |
{ |
|---|
| 88 |
$this->mailer->Body = $body; |
|---|
| 89 |
} |
|---|
| 90 |
|
|---|
| 91 |
public function getBody() |
|---|
| 92 |
{ |
|---|
| 93 |
return $this->mailer->Body; |
|---|
| 94 |
} |
|---|
| 95 |
|
|---|
| 96 |
public function setMailer($type = 'mail', $options = array()) |
|---|
| 97 |
{ |
|---|
| 98 |
switch ($type) |
|---|
| 99 |
{ |
|---|
| 100 |
case 'smtp': |
|---|
| 101 |
$this->mailer->IsSMTP(); |
|---|
| 102 |
if (isset($options['keep_alive'])) $this->mailer->SMTPKeepAlive = true; |
|---|
| 103 |
break; |
|---|
| 104 |
case 'sendmail': |
|---|
| 105 |
$this->mailer->IsSendmail(); |
|---|
| 106 |
break; |
|---|
| 107 |
default: |
|---|
| 108 |
$this->mailer->IsMail(); |
|---|
| 109 |
break; |
|---|
| 110 |
} |
|---|
| 111 |
} |
|---|
| 112 |
|
|---|
| 113 |
public function getMailer() |
|---|
| 114 |
{ |
|---|
| 115 |
return $this->mailer->Mailer; |
|---|
| 116 |
} |
|---|
| 117 |
|
|---|
| 118 |
public function setSender($address, $name = null) |
|---|
| 119 |
{ |
|---|
| 120 |
if (!$address) |
|---|
| 121 |
{ |
|---|
| 122 |
return; |
|---|
| 123 |
} |
|---|
| 124 |
|
|---|
| 125 |
if ($name == null) |
|---|
| 126 |
{ |
|---|
| 127 |
list($address, $name) = $this->splitAddress($address); |
|---|
| 128 |
} |
|---|
| 129 |
$this->mailer->Sender = $address; |
|---|
| 130 |
} |
|---|
| 131 |
|
|---|
| 132 |
public function getSender() |
|---|
| 133 |
{ |
|---|
| 134 |
return $this->mailer->Sender; |
|---|
| 135 |
} |
|---|
| 136 |
|
|---|
| 137 |
public function setFrom($address, $name = null) |
|---|
| 138 |
{ |
|---|
| 139 |
if (!$address) |
|---|
| 140 |
{ |
|---|
| 141 |
return; |
|---|
| 142 |
} |
|---|
| 143 |
|
|---|
| 144 |
if ($name == null) |
|---|
| 145 |
{ |
|---|
| 146 |
list($address, $name) = $this->splitAddress($address); |
|---|
| 147 |
} |
|---|
| 148 |
$this->mailer->From = $address; |
|---|
| 149 |
$this->mailer->FromName = $name; |
|---|
| 150 |
} |
|---|
| 151 |
|
|---|
| 152 |
public function getFrom() |
|---|
| 153 |
{ |
|---|
| 154 |
return $this->mailer->From; |
|---|
| 155 |
} |
|---|
| 156 |
|
|---|
| 157 |
|
|---|
| 158 |
* $recipents: |
|---|
| 159 |
* test@example.com |
|---|
| 160 |
* Example email <test@example.com> |
|---|
| 161 |
* array('test@example.com', 'test1@example.com') |
|---|
| 162 |
* array('Example email <test@example.com>', 'test1@example.com') |
|---|
| 163 |
*/ |
|---|
| 164 |
public function addAddresses($addresses) |
|---|
| 165 |
{ |
|---|
| 166 |
if (!$addresses) |
|---|
| 167 |
{ |
|---|
| 168 |
return; |
|---|
| 169 |
} |
|---|
| 170 |
|
|---|
| 171 |
if (is_array($addresses)) |
|---|
| 172 |
{ |
|---|
| 173 |
foreach ($addresses as $address) |
|---|
| 174 |
{ |
|---|
| 175 |
list($address, $name) = $this->splitAddress($address); |
|---|
| 176 |
$this->mailer->AddAddress($address, $name); |
|---|
| 177 |
} |
|---|
| 178 |
} |
|---|
| 179 |
else |
|---|
| 180 |
{ |
|---|
| 181 |
list($address, $name) = $this->splitAddress($addresses); |
|---|
| 182 |
$this->mailer->AddAddress($address, $name); |
|---|
| 183 |
} |
|---|
| 184 |
} |
|---|
| 185 |
|
|---|
| 186 |
private function splitAddress($address) |
|---|
| 187 |
{ |
|---|
| 188 |
if (preg_match('/^(.+)\s<(.+?)>$/', $address, $matches)) |
|---|
| 189 |
{ |
|---|
| 190 |
return array($matches[2], $matches[1]); |
|---|
| 191 |
} |
|---|
| 192 |
else |
|---|
| 193 |
{ |
|---|
| 194 |
return array($address, ''); |
|---|
| 195 |
} |
|---|
| 196 |
} |
|---|
| 197 |
|
|---|
| 198 |
public function addAddress($address, $name = null) |
|---|
| 199 |
{ |
|---|
| 200 |
if ($name == null) |
|---|
| 201 |
{ |
|---|
| 202 |
list($address, $name) = $this->splitAddress($address); |
|---|
| 203 |
} |
|---|
| 204 |
$this->mailer->AddAddress($address, $name); |
|---|
| 205 |
} |
|---|
| 206 |
|
|---|
| 207 |
public function addCc($address, $name = null) |
|---|
| 208 |
{ |
|---|
| 209 |
if ($name == null) |
|---|
| 210 |
{ |
|---|
| 211 |
list($address, $name) = $this->splitAddress($address); |
|---|
| 212 |
} |
|---|
| 213 |
$this->mailer->AddCc($address, $name); |
|---|
| 214 |
} |
|---|
| 215 |
|
|---|
| 216 |
public function addBcc($address, $name = null) |
|---|
| 217 |
{ |
|---|
| 218 |
if ($name == null) |
|---|
| 219 |
{ |
|---|
| 220 |
list($address, $name) = $this->splitAddress($address); |
|---|
| 221 |
} |
|---|
| 222 |
$this->mailer->AddBcc($address, $name); |
|---|
| 223 |
} |
|---|
| 224 |
|
|---|
| 225 |
public function addReplyTo($address, $name = null) |
|---|
| 226 |
{ |
|---|
| 227 |
if (!$address) |
|---|
| 228 |
{ |
|---|
| 229 |
return; |
|---|
| 230 |
} |
|---|
| 231 |
|
|---|
| 232 |
if ($name == null) |
|---|
| 233 |
{ |
|---|
| 234 |
list($address, $name) = $this->splitAddress($address); |
|---|
| 235 |
} |
|---|
| 236 |
$this->mailer->AddReplyTo($address, $name); |
|---|
| 237 |
} |
|---|
| 238 |
|
|---|
| 239 |
public function clearAddresses() |
|---|
| 240 |
{ |
|---|
| 241 |
$this->mailer->ClearAddresses(); |
|---|
| 242 |
} |
|---|
| 243 |
|
|---|
| 244 |
public function clearCcs() |
|---|
| 245 |
{ |
|---|
| 246 |
$this->mailer->ClearCcs(); |
|---|
| 247 |
} |
|---|
| 248 |
|
|---|
| 249 |
public function clearBccs() |
|---|
| 250 |
{ |
|---|
| 251 |
$this->mailer->ClearBccs(); |
|---|
| 252 |
} |
|---|
| 253 |
|
|---|
| 254 |
public function clearReplyTos() |
|---|
| 255 |
{ |
|---|
| 256 |
$this->mailer->ClearReplyTos(); |
|---|
| 257 |
} |
|---|
| 258 |
|
|---|
| 259 |
public function clearAllRecipients() |
|---|
| 260 |
{ |
|---|
| 261 |
$this->mailer->ClearAllRecipients(); |
|---|
| 262 |
} |
|---|
| 263 |
|
|---|
| 264 |
public function addAttachment($path, $name = '', $encoding = 'base64', $type = 'application/octet-stream') |
|---|
| 265 |
{ |
|---|
| 266 |
$this->mailer->AddAttachment($path, $name, $encoding, $type); |
|---|
| 267 |
} |
|---|
| 268 |
|
|---|
| 269 |
public function addStringAttachment($string, $filename, $encoding = 'base64', $type = 'application/octet-stream') |
|---|
| 270 |
{ |
|---|
| 271 |
$this->mailer->AddStringAttachment($string, $filename, $encoding, $type); |
|---|
| 272 |
} |
|---|
| 273 |
|
|---|
| 274 |
public function addEmbeddedImage($path, $cid, $name = '', $encoding = 'base64', $type = 'application/octet-stream') |
|---|
| 275 |
{ |
|---|
| 276 |
$this->mailer->AddEmbeddedImage($path, $cid, $name, $encoding, $type); |
|---|
| 277 |
} |
|---|
| 278 |
|
|---|
| 279 |
public function setAttachments($attachments) |
|---|
| 280 |
{ |
|---|
| 281 |
if ($attachments instanceof sfMailAttachments) |
|---|
| 282 |
{ |
|---|
| 283 |
$this->mailer->setAttachments($attachments->getAttachments()); |
|---|
| 284 |
} |
|---|
| 285 |
} |
|---|
| 286 |
|
|---|
| 287 |
public function clearAttachments() |
|---|
| 288 |
{ |
|---|
| 289 |
$this->mailer->ClearAttachments(); |
|---|
| 290 |
} |
|---|
| 291 |
|
|---|
| 292 |
function addCustomHeader($name, $value) |
|---|
| 293 |
{ |
|---|
| 294 |
$this->mailer->AddCustomHeader("$name: $value"); |
|---|
| 295 |
} |
|---|
| 296 |
|
|---|
| 297 |
function clearCustomHeaders() |
|---|
| 298 |
{ |
|---|
| 299 |
$this->mailer->ClearCustomHeaders(); |
|---|
| 300 |
} |
|---|
| 301 |
|
|---|
| 302 |
public function prepare() |
|---|
| 303 |
{ |
|---|
| 304 |
|
|---|
| 305 |
if (!empty($this->mailer->AltBody)) |
|---|
| 306 |
{ |
|---|
| 307 |
$this->mailer->ContentType = "multipart/alternative"; |
|---|
| 308 |
} |
|---|
| 309 |
|
|---|
| 310 |
$this->mailer->SetMessageType(); |
|---|
| 311 |
} |
|---|
| 312 |
|
|---|
| 313 |
public function send() |
|---|
| 314 |
{ |
|---|
| 315 |
if (!$this->mailer->Send()) |
|---|
| 316 |
{ |
|---|
| 317 |
throw new sfException($this->mailer->ErrorInfo); |
|---|
| 318 |
} |
|---|
| 319 |
} |
|---|
| 320 |
|
|---|
| 321 |
public function smtpClose() |
|---|
| 322 |
{ |
|---|
| 323 |
$this->mailer->SmtpClose(); |
|---|
| 324 |
} |
|---|
| 325 |
|
|---|
| 326 |
public function getRawHeader() |
|---|
| 327 |
{ |
|---|
| 328 |
return $this->mailer->CreateHeader(); |
|---|
| 329 |
} |
|---|
| 330 |
|
|---|
| 331 |
public function getRawBody() |
|---|
| 332 |
{ |
|---|
| 333 |
return $this->mailer->CreateBody(); |
|---|
| 334 |
} |
|---|
| 335 |
|
|---|
| 336 |
public function setDomain($hostname) |
|---|
| 337 |
{ |
|---|
| 338 |
$this->mailer->Hostname = $hostname; |
|---|
| 339 |
} |
|---|
| 340 |
|
|---|
| 341 |
public function getDomain() |
|---|
| 342 |
{ |
|---|
| 343 |
return $this->mailer->Hostname; |
|---|
| 344 |
} |
|---|
| 345 |
|
|---|
| 346 |
public function setHostname($hostname) |
|---|
| 347 |
{ |
|---|
| 348 |
$this->mailer->Host = $hostname; |
|---|
| 349 |
} |
|---|
| 350 |
|
|---|
| 351 |
public function getHostname() |
|---|
| 352 |
{ |
|---|
| 353 |
return $this->mailer->Host; |
|---|
| 354 |
} |
|---|
| 355 |
|
|---|
| 356 |
public function setPort($port) |
|---|
| 357 |
{ |
|---|
| 358 |
$this->mailer->Port = $port; |
|---|
| 359 |
} |
|---|
| 360 |
|
|---|
| 361 |
public function getPort() |
|---|
| 362 |
{ |
|---|
| 363 |
return $this->mailer->Port; |
|---|
| 364 |
} |
|---|
| 365 |
|
|---|
| 366 |
public function setUsername($username) |
|---|
| 367 |
{ |
|---|
| 368 |
$this->mailer->Username = $username; |
|---|
| 369 |
$this->mailer->SMTPAuth = $username ? true : false; |
|---|
| 370 |
} |
|---|
| 371 |
|
|---|
| 372 |
public function getUsername() |
|---|
| 373 |
{ |
|---|
| 374 |
return $this->mailer->Username; |
|---|
| 375 |
} |
|---|
| 376 |
|
|---|
| 377 |
public function setPassword($password) |
|---|
| 378 |
{ |
|---|
| 379 |
$this->mailer->Password = $password; |
|---|
| 380 |
} |
|---|
| 381 |
|
|---|
| 382 |
public function getPassword() |
|---|
| 383 |
{ |
|---|
| 384 |
return $this->mailer->Password; |
|---|
| 385 |
} |
|---|
| 386 |
|
|---|
| 387 |
public function setWordWrap($wordWrap) |
|---|
| 388 |
{ |
|---|
| 389 |
$this->mailer->WordWrap = $wordWrap; |
|---|
| 390 |
} |
|---|
| 391 |
|
|---|
| 392 |
public function getWordWrap() |
|---|
| 393 |
{ |
|---|
| 394 |
return $this->mailer->WordWrap; |
|---|
| 395 |
} |
|---|
| 396 |
|
|---|
| 397 |
public function setAltBody($text) |
|---|
| 398 |
{ |
|---|
| 399 |
$this->mailer->AltBody = $text; |
|---|
| 400 |
} |
|---|
| 401 |
|
|---|
| 402 |
public function getAltBody() |
|---|
| 403 |
{ |
|---|
| 404 |
return $this->mailer->AltBody; |
|---|
| 405 |
} |
|---|
| 406 |
} |
|---|
| 407 |
|
|---|