Added
Link Here
|
1 |
--- lib/PHPMailer.class.php.orig 2007-06-14 19:00:15 UTC |
2 |
+++ lib/PHPMailer.class.php |
3 |
@@ -1,1541 +1,1541 @@ |
4 |
-<?php |
5 |
-//////////////////////////////////////////////////// |
6 |
-// PHPMailer - PHP email class |
7 |
-// |
8 |
-// Class for sending email using either |
9 |
-// sendmail, PHP mail(), or SMTP. Methods are |
10 |
-// based upon the standard AspEmail(tm) classes. |
11 |
-// |
12 |
-// Copyright (C) 2001 - 2003 Brent R. Matzelle |
13 |
-// |
14 |
-// License: LGPL, see LICENSE |
15 |
-//////////////////////////////////////////////////// |
16 |
- |
17 |
-/** |
18 |
- * PHPMailer - PHP email transport class |
19 |
- * @package PHPMailer |
20 |
- * @author Brent R. Matzelle |
21 |
- * @copyright 2001 - 2003 Brent R. Matzelle |
22 |
- */ |
23 |
-class PHPMailer |
24 |
-{ |
25 |
- ///////////////////////////////////////////////// |
26 |
- // PUBLIC VARIABLES |
27 |
- ///////////////////////////////////////////////// |
28 |
- |
29 |
- /** |
30 |
- * Email priority (1 = High, 3 = Normal, 5 = low). |
31 |
- * @var int |
32 |
- */ |
33 |
- var $Priority = 3; |
34 |
- |
35 |
- /** |
36 |
- * Sets the CharSet of the message. |
37 |
- * @var string |
38 |
- */ |
39 |
- var $CharSet = "iso-8859-1"; |
40 |
- |
41 |
- /** |
42 |
- * Sets the Content-type of the message. |
43 |
- * @var string |
44 |
- */ |
45 |
- var $ContentType = "text/plain"; |
46 |
- |
47 |
- /** |
48 |
- * Sets the Encoding of the message. Options for this are "8bit", |
49 |
- * "7bit", "binary", "base64", and "quoted-printable". |
50 |
- * @var string |
51 |
- */ |
52 |
- var $Encoding = "8bit"; |
53 |
- |
54 |
- /** |
55 |
- * Holds the most recent mailer error message. |
56 |
- * @var string |
57 |
- */ |
58 |
- var $ErrorInfo = ""; |
59 |
- |
60 |
- /** |
61 |
- * Sets the From email address for the message. |
62 |
- * @var string |
63 |
- */ |
64 |
- var $From = "root@localhost"; |
65 |
- |
66 |
- /** |
67 |
- * Sets the From name of the message. |
68 |
- * @var string |
69 |
- */ |
70 |
- var $FromName = "Root User"; |
71 |
- |
72 |
- /** |
73 |
- * Sets the Sender email (Return-Path) of the message. If not empty, |
74 |
- * will be sent via -f to sendmail or as 'MAIL FROM' in smtp mode. |
75 |
- * @var string |
76 |
- */ |
77 |
- var $Sender = ""; |
78 |
- |
79 |
- /** |
80 |
- * Sets the Subject of the message. |
81 |
- * @var string |
82 |
- */ |
83 |
- var $Subject = ""; |
84 |
- |
85 |
- /** |
86 |
- * Sets the Body of the message. This can be either an HTML or text body. |
87 |
- * If HTML then run IsHTML(true). |
88 |
- * @var string |
89 |
- */ |
90 |
- var $Body = ""; |
91 |
- |
92 |
- /** |
93 |
- * Sets the text-only body of the message. This automatically sets the |
94 |
- * email to multipart/alternative. This body can be read by mail |
95 |
- * clients that do not have HTML email capability such as mutt. Clients |
96 |
- * that can read HTML will view the normal Body. |
97 |
- * @var string |
98 |
- */ |
99 |
- var $AltBody = ""; |
100 |
- |
101 |
- /** |
102 |
- * Sets word wrapping on the body of the message to a given number of |
103 |
- * characters. |
104 |
- * @var int |
105 |
- */ |
106 |
- var $WordWrap = 0; |
107 |
- |
108 |
- /** |
109 |
- * Method to send mail: ("mail", "sendmail", or "smtp"). |
110 |
- * @var string |
111 |
- */ |
112 |
- var $Mailer = "mail"; |
113 |
- |
114 |
- /** |
115 |
- * Sets the path of the sendmail program. |
116 |
- * @var string |
117 |
- */ |
118 |
- var $Sendmail = "/usr/sbin/sendmail"; |
119 |
- |
120 |
- /** |
121 |
- * Path to PHPMailer plugins. This is now only useful if the SMTP class |
122 |
- * is in a different directory than the PHP include path. |
123 |
- * @var string |
124 |
- */ |
125 |
- var $PluginDir = ""; |
126 |
- |
127 |
- /** |
128 |
- * Holds PHPMailer version. |
129 |
- * @var string |
130 |
- */ |
131 |
- var $Version = "1.72"; |
132 |
- |
133 |
- /** |
134 |
- * Sets the email address that a reading confirmation will be sent. |
135 |
- * @var string |
136 |
- */ |
137 |
- var $ConfirmReadingTo = ""; |
138 |
- |
139 |
- /** |
140 |
- * Sets the hostname to use in Message-Id and Received headers |
141 |
- * and as default HELO string. If empty, the value returned |
142 |
- * by SERVER_NAME is used or 'localhost.localdomain'. |
143 |
- * @var string |
144 |
- */ |
145 |
- var $Hostname = ""; |
146 |
- |
147 |
- ///////////////////////////////////////////////// |
148 |
- // SMTP VARIABLES |
149 |
- ///////////////////////////////////////////////// |
150 |
- |
151 |
- /** |
152 |
- * Sets the SMTP hosts. All hosts must be separated by a |
153 |
- * semicolon. You can also specify a different port |
154 |
- * for each host by using this format: [hostname:port] |
155 |
- * (e.g. "smtp1.example.com:25;smtp2.example.com"). |
156 |
- * Hosts will be tried in order. |
157 |
- * @var string |
158 |
- */ |
159 |
- var $Host = "localhost"; |
160 |
- |
161 |
- /** |
162 |
- * Sets the default SMTP server port. |
163 |
- * @var int |
164 |
- */ |
165 |
- var $Port = 25; |
166 |
- |
167 |
- /** |
168 |
- * Sets the SMTP HELO of the message (Default is $Hostname). |
169 |
- * @var string |
170 |
- */ |
171 |
- var $Helo = ""; |
172 |
- |
173 |
- /** |
174 |
- * Sets SMTP authentication. Utilizes the Username and Password variables. |
175 |
- * @var bool |
176 |
- */ |
177 |
- var $SMTPAuth = false; |
178 |
- |
179 |
- /** |
180 |
- * Sets SMTP username. |
181 |
- * @var string |
182 |
- */ |
183 |
- var $Username = ""; |
184 |
- |
185 |
- /** |
186 |
- * Sets SMTP password. |
187 |
- * @var string |
188 |
- */ |
189 |
- var $Password = ""; |
190 |
- |
191 |
- /** |
192 |
- * Sets the SMTP server timeout in seconds. This function will not |
193 |
- * work with the win32 version. |
194 |
- * @var int |
195 |
- */ |
196 |
- var $Timeout = 10; |
197 |
- |
198 |
- /** |
199 |
- * Sets SMTP class debugging on or off. |
200 |
- * @var bool |
201 |
- */ |
202 |
- var $SMTPDebug = false; |
203 |
- |
204 |
- /** |
205 |
- * Prevents the SMTP connection from being closed after each mail |
206 |
- * sending. If this is set to true then to close the connection |
207 |
- * requires an explicit call to SmtpClose(). |
208 |
- * @var bool |
209 |
- */ |
210 |
- var $SMTPKeepAlive = false; |
211 |
- |
212 |
- /**#@+ |
213 |
- * @access private |
214 |
- */ |
215 |
- var $smtp = NULL; |
216 |
- var $to = array(); |
217 |
- var $cc = array(); |
218 |
- var $bcc = array(); |
219 |
- var $ReplyTo = array(); |
220 |
- var $attachment = array(); |
221 |
- var $CustomHeader = array(); |
222 |
- var $message_type = ""; |
223 |
- var $boundary = array(); |
224 |
- var $language = array(); |
225 |
- var $error_count = 0; |
226 |
- var $LE = "\n"; |
227 |
- /**#@-*/ |
228 |
- |
229 |
- ///////////////////////////////////////////////// |
230 |
- // CONSTRUCTOR |
231 |
- ///////////////////////////////////////////////// |
232 |
- /** |
233 |
- * Constructor, just set up language |
234 |
- * @param none |
235 |
- * @return void |
236 |
- */ |
237 |
- function PHPMailer() { |
238 |
- global $conf; |
239 |
- global $charset; |
240 |
- |
241 |
- $this->CharSet = $charset; |
242 |
- |
243 |
- $this->SetLanguage(); |
244 |
- |
245 |
- $this->Mailer = $conf['app']['emailType']; |
246 |
- |
247 |
- if ($this->Mailer == 'smtp') { // Set smtp variables |
248 |
- $this->Host = $conf['app']['smtpHost']; |
249 |
- $this->Port = $conf['app']['smtpPort']; |
250 |
- } |
251 |
- |
252 |
- if ($this->Mailer == 'sendmail') // Set sendmail variables |
253 |
- $this->Sendmail = $conf['app']['sendmailPath']; |
254 |
- |
255 |
- if ($this->Mailer == 'qmail') // Set qmail variables |
256 |
- $this->Sendmail = $conf['app']['qmailPath']; |
257 |
- } |
258 |
- |
259 |
- ///////////////////////////////////////////////// |
260 |
- // VARIABLE METHODS |
261 |
- ///////////////////////////////////////////////// |
262 |
- |
263 |
- /** |
264 |
- * Sets message type to HTML. |
265 |
- * @param bool $bool |
266 |
- * @return void |
267 |
- */ |
268 |
- function IsHTML($bool) { |
269 |
- if($bool == true) |
270 |
- $this->ContentType = "text/html"; |
271 |
- else |
272 |
- $this->ContentType = "text/plain"; |
273 |
- } |
274 |
- |
275 |
- /** |
276 |
- * Sets Mailer to send message using SMTP. |
277 |
- * @return void |
278 |
- */ |
279 |
- function IsSMTP() { |
280 |
- $this->Mailer = "smtp"; |
281 |
- } |
282 |
- |
283 |
- /** |
284 |
- * Sets Mailer to send message using PHP mail() function. |
285 |
- * @return void |
286 |
- */ |
287 |
- function IsMail() { |
288 |
- $this->Mailer = "mail"; |
289 |
- } |
290 |
- |
291 |
- /** |
292 |
- * Sets Mailer to send message using the $Sendmail program. |
293 |
- * @return void |
294 |
- */ |
295 |
- function IsSendmail() { |
296 |
- $this->Mailer = "sendmail"; |
297 |
- } |
298 |
- |
299 |
- /** |
300 |
- * Sets Mailer to send message using the qmail MTA. |
301 |
- * @return void |
302 |
- */ |
303 |
- function IsQmail() { |
304 |
- $this->Sendmail = "/var/qmail/bin/sendmail"; |
305 |
- $this->Mailer = "sendmail"; |
306 |
- } |
307 |
- |
308 |
- |
309 |
- ///////////////////////////////////////////////// |
310 |
- // RECIPIENT METHODS |
311 |
- ///////////////////////////////////////////////// |
312 |
- |
313 |
- /** |
314 |
- * Adds a "To" address. |
315 |
- * @param string $address |
316 |
- * @param string $name |
317 |
- * @return void |
318 |
- */ |
319 |
- function AddAddress($address, $name = "") { |
320 |
- $cur = count($this->to); |
321 |
- $this->to[$cur][0] = trim($address); |
322 |
- $this->to[$cur][1] = $name; |
323 |
- } |
324 |
- |
325 |
- /** |
326 |
- * Adds a "Cc" address. Note: this function works |
327 |
- * with the SMTP mailer on win32, not with the "mail" |
328 |
- * mailer. |
329 |
- * @param string $address |
330 |
- * @param string $name |
331 |
- * @return void |
332 |
- */ |
333 |
- function AddCC($address, $name = "") { |
334 |
- $cur = count($this->cc); |
335 |
- $this->cc[$cur][0] = trim($address); |
336 |
- $this->cc[$cur][1] = $name; |
337 |
- } |
338 |
- |
339 |
- /** |
340 |
- * Adds a "Bcc" address. Note: this function works |
341 |
- * with the SMTP mailer on win32, not with the "mail" |
342 |
- * mailer. |
343 |
- * @param string $address |
344 |
- * @param string $name |
345 |
- * @return void |
346 |
- */ |
347 |
- function AddBCC($address, $name = "") { |
348 |
- $cur = count($this->bcc); |
349 |
- $this->bcc[$cur][0] = trim($address); |
350 |
- $this->bcc[$cur][1] = $name; |
351 |
- } |
352 |
- |
353 |
- /** |
354 |
- * Adds a "Reply-to" address. |
355 |
- * @param string $address |
356 |
- * @param string $name |
357 |
- * @return void |
358 |
- */ |
359 |
- function AddReplyTo($address, $name = "") { |
360 |
- $cur = count($this->ReplyTo); |
361 |
- $this->ReplyTo[$cur][0] = trim($address); |
362 |
- $this->ReplyTo[$cur][1] = $name; |
363 |
- } |
364 |
- |
365 |
- |
366 |
- ///////////////////////////////////////////////// |
367 |
- // MAIL SENDING METHODS |
368 |
- ///////////////////////////////////////////////// |
369 |
- |
370 |
- /** |
371 |
- * Creates message and assigns Mailer. If the message is |
372 |
- * not sent successfully then it returns false. Use the ErrorInfo |
373 |
- * variable to view description of the error. |
374 |
- * @return bool |
375 |
- */ |
376 |
- function Send() { |
377 |
- $header = ""; |
378 |
- $body = ""; |
379 |
- $result = true; |
380 |
- |
381 |
- if((count($this->to) + count($this->cc) + count($this->bcc)) < 1) |
382 |
- { |
383 |
- $this->SetError($this->Lang("provide_address")); |
384 |
- return false; |
385 |
- } |
386 |
- |
387 |
- // Set whether the message is multipart/alternative |
388 |
- if(!empty($this->AltBody)) |
389 |
- $this->ContentType = "multipart/alternative"; |
390 |
- |
391 |
- $this->error_count = 0; // reset errors |
392 |
- $this->SetMessageType(); |
393 |
- $header .= $this->CreateHeader(); |
394 |
- $body = $this->CreateBody(); |
395 |
- |
396 |
- // Nick Korbel - 08-21-2005 |
397 |
- if (version_compare('4.3.0',phpversion(), '<=') == 1) { |
398 |
- $this->Subject = html_entity_decode($this->Subject, ENT_COMPAT, $this->CharSet); |
399 |
- if ($this->ContentType != "text/html") |
400 |
- $body = html_entity_decode($body, ENT_COMPAT, $this->CharSet); |
401 |
- } |
402 |
- |
403 |
- if($body == "") { return false; } |
404 |
- |
405 |
- // Choose the mailer |
406 |
- switch($this->Mailer) |
407 |
- { |
408 |
- case "sendmail": |
409 |
- $result = $this->SendmailSend($header, $body); |
410 |
- break; |
411 |
- case "mail": |
412 |
- $result = $this->MailSend($header, $body); |
413 |
- break; |
414 |
- case "smtp": |
415 |
- $result = $this->SmtpSend($header, $body); |
416 |
- break; |
417 |
- default: |
418 |
- $this->SetError($this->Mailer . $this->Lang("mailer_not_supported")); |
419 |
- $result = false; |
420 |
- break; |
421 |
- } |
422 |
- |
423 |
- return $result; |
424 |
- } |
425 |
- |
426 |
- /** |
427 |
- * Sends mail using the $Sendmail program. |
428 |
- * @access private |
429 |
- * @return bool |
430 |
- */ |
431 |
- function SendmailSend($header, $body) { |
432 |
- if ($this->Sender != "") |
433 |
- $sendmail = sprintf("%s -oi -f %s -t", $this->Sendmail, $this->Sender); |
434 |
- else |
435 |
- $sendmail = sprintf("%s -oi -t", $this->Sendmail); |
436 |
- |
437 |
- if(!@$mail = popen($sendmail, "w")) |
438 |
- { |
439 |
- $this->SetError($this->Lang("execute") . $this->Sendmail); |
440 |
- return false; |
441 |
- } |
442 |
- |
443 |
- fputs($mail, $header); |
444 |
- fputs($mail, $body); |
445 |
- |
446 |
- $result = pclose($mail) >> 8 & 0xFF; |
447 |
- if($result != 0) |
448 |
- { |
449 |
- $this->SetError($this->Lang("execute") . $this->Sendmail); |
450 |
- return false; |
451 |
- } |
452 |
- |
453 |
- return true; |
454 |
- } |
455 |
- |
456 |
- /** |
457 |
- * Sends mail using the PHP mail() function. |
458 |
- * @access private |
459 |
- * @return bool |
460 |
- */ |
461 |
- function MailSend($header, $body) { |
462 |
- $to = ""; |
463 |
- for($i = 0; $i < count($this->to); $i++) |
464 |
- { |
465 |
- if($i != 0) { $to .= ", "; } |
466 |
- $to .= $this->to[$i][0]; |
467 |
- } |
468 |
- |
469 |
- if ($this->Sender != "" && strlen(ini_get("safe_mode"))< 1) |
470 |
- { |
471 |
- $old_from = ini_get("sendmail_from"); |
472 |
- ini_set("sendmail_from", $this->Sender); |
473 |
- $params = sprintf("-oi -f %s", $this->Sender); |
474 |
- $rt = @mail($to, $this->EncodeHeader($this->Subject), $body, |
475 |
- $header, $params); |
476 |
- } |
477 |
- else |
478 |
- $rt = @mail($to, $this->EncodeHeader($this->Subject), $body, $header); |
479 |
- |
480 |
- if (isset($old_from)) |
481 |
- ini_set("sendmail_from", $old_from); |
482 |
- |
483 |
- if(!$rt) |
484 |
- { |
485 |
- $this->SetError($this->Lang("instantiate")); |
486 |
- return false; |
487 |
- } |
488 |
- |
489 |
- return true; |
490 |
- } |
491 |
- |
492 |
- /** |
493 |
- * Sends mail via SMTP using PhpSMTP (Author: |
494 |
- * Chris Ryan). Returns bool. Returns false if there is a |
495 |
- * bad MAIL FROM, RCPT, or DATA input. |
496 |
- * @access private |
497 |
- * @return bool |
498 |
- */ |
499 |
- function SmtpSend($header, $body) { |
500 |
- include_once($this->PluginDir . "Smtp.class.php"); |
501 |
- $error = ""; |
502 |
- $bad_rcpt = array(); |
503 |
- |
504 |
- if(!$this->SmtpConnect()) |
505 |
- return false; |
506 |
- |
507 |
- $smtp_from = ($this->Sender == "") ? $this->From : $this->Sender; |
508 |
- if(!$this->smtp->Mail($smtp_from)) |
509 |
- { |
510 |
- $error = $this->Lang("from_failed") . $smtp_from; |
511 |
- $this->SetError($error); |
512 |
- $this->smtp->Reset(); |
513 |
- return false; |
514 |
- } |
515 |
- |
516 |
- // Attempt to send attach all recipients |
517 |
- for($i = 0; $i < count($this->to); $i++) |
518 |
- { |
519 |
- if(!$this->smtp->Recipient($this->to[$i][0])) |
520 |
- $bad_rcpt[] = $this->to[$i][0]; |
521 |
- } |
522 |
- for($i = 0; $i < count($this->cc); $i++) |
523 |
- { |
524 |
- if(!$this->smtp->Recipient($this->cc[$i][0])) |
525 |
- $bad_rcpt[] = $this->cc[$i][0]; |
526 |
- } |
527 |
- for($i = 0; $i < count($this->bcc); $i++) |
528 |
- { |
529 |
- if(!$this->smtp->Recipient($this->bcc[$i][0])) |
530 |
- $bad_rcpt[] = $this->bcc[$i][0]; |
531 |
- } |
532 |
- |
533 |
- if(count($bad_rcpt) > 0) // Create error message |
534 |
- { |
535 |
- for($i = 0; $i < count($bad_rcpt); $i++) |
536 |
- { |
537 |
- if($i != 0) { $error .= ", "; } |
538 |
- $error .= $bad_rcpt[$i]; |
539 |
- } |
540 |
- $error = $this->Lang("recipients_failed") . $error; |
541 |
- $this->SetError($error); |
542 |
- $this->smtp->Reset(); |
543 |
- return false; |
544 |
- } |
545 |
- |
546 |
- if(!$this->smtp->Data($header . $body)) |
547 |
- { |
548 |
- $this->SetError($this->Lang("data_not_accepted")); |
549 |
- $this->smtp->Reset(); |
550 |
- return false; |
551 |
- } |
552 |
- if($this->SMTPKeepAlive == true) |
553 |
- $this->smtp->Reset(); |
554 |
- else |
555 |
- $this->SmtpClose(); |
556 |
- |
557 |
- return true; |
558 |
- } |
559 |
- |
560 |
- /** |
561 |
- * Initiates a connection to an SMTP server. Returns false if the |
562 |
- * operation failed. |
563 |
- * @access private |
564 |
- * @return bool |
565 |
- */ |
566 |
- function SmtpConnect() { |
567 |
- if($this->smtp == NULL) { $this->smtp = new SMTP(); } |
568 |
- |
569 |
- $this->smtp->do_debug = $this->SMTPDebug; |
570 |
- $hosts = explode(";", $this->Host); |
571 |
- $index = 0; |
572 |
- $connection = ($this->smtp->Connected()); |
573 |
- |
574 |
- // Retry while there is no connection |
575 |
- while($index < count($hosts) && $connection == false) |
576 |
- { |
577 |
- if(strstr($hosts[$index], ":")) |
578 |
- list($host, $port) = explode(":", $hosts[$index]); |
579 |
- else |
580 |
- { |
581 |
- $host = $hosts[$index]; |
582 |
- $port = $this->Port; |
583 |
- } |
584 |
- |
585 |
- if($this->smtp->Connect($host, $port, $this->Timeout)) |
586 |
- { |
587 |
- if ($this->Helo != '') |
588 |
- $this->smtp->Hello($this->Helo); |
589 |
- else |
590 |
- $this->smtp->Hello($this->ServerHostname()); |
591 |
- |
592 |
- if($this->SMTPAuth) |
593 |
- { |
594 |
- if(!$this->smtp->Authenticate($this->Username, |
595 |
- $this->Password)) |
596 |
- { |
597 |
- $this->SetError($this->Lang("authenticate")); |
598 |
- $this->smtp->Reset(); |
599 |
- $connection = false; |
600 |
- } |
601 |
- } |
602 |
- $connection = true; |
603 |
- } |
604 |
- $index++; |
605 |
- } |
606 |
- if(!$connection) |
607 |
- $this->SetError($this->Lang("connect_host")); |
608 |
- |
609 |
- return $connection; |
610 |
- } |
611 |
- |
612 |
- /** |
613 |
- * Closes the active SMTP session if one exists. |
614 |
- * @return void |
615 |
- */ |
616 |
- function SmtpClose() { |
617 |
- if($this->smtp != NULL) |
618 |
- { |
619 |
- if($this->smtp->Connected()) |
620 |
- { |
621 |
- $this->smtp->Quit(); |
622 |
- $this->smtp->Close(); |
623 |
- } |
624 |
- } |
625 |
- } |
626 |
- |
627 |
- /** |
628 |
- * Sets the language for all class error messages. Always in English. |
629 |
- * @param none |
630 |
- * @access public |
631 |
- * @return bool |
632 |
- */ |
633 |
- function SetLanguage() { |
634 |
- /** |
635 |
- * Only printing errors in english |
636 |
- */ |
637 |
- $PHPMAILER_LANG = array(); |
638 |
- |
639 |
- $PHPMAILER_LANG["provide_address"] = 'You must provide at least one ' . |
640 |
- 'recipient email address.'; |
641 |
- $PHPMAILER_LANG["mailer_not_supported"] = ' mailer is not supported.'; |
642 |
- $PHPMAILER_LANG["execute"] = 'Could not execute: '; |
643 |
- $PHPMAILER_LANG["instantiate"] = 'Could not instantiate mail function.'; |
644 |
- $PHPMAILER_LANG["authenticate"] = 'SMTP Error: Could not authenticate.'; |
645 |
- $PHPMAILER_LANG["from_failed"] = 'The following From address failed: '; |
646 |
- $PHPMAILER_LANG["recipients_failed"] = 'SMTP Error: The following ' . |
647 |
- 'recipients failed: '; |
648 |
- $PHPMAILER_LANG["data_not_accepted"] = 'SMTP Error: Data not accepted.'; |
649 |
- $PHPMAILER_LANG["connect_host"] = 'SMTP Error: Could not connect to SMTP host.'; |
650 |
- $PHPMAILER_LANG["file_access"] = 'Could not access file: '; |
651 |
- $PHPMAILER_LANG["file_open"] = 'File Error: Could not open file: '; |
652 |
- $PHPMAILER_LANG["encoding"] = 'Unknown encoding: '; |
653 |
- |
654 |
- $this->language = $PHPMAILER_LANG; |
655 |
- |
656 |
- return true; |
657 |
- } |
658 |
- |
659 |
- ///////////////////////////////////////////////// |
660 |
- // MESSAGE CREATION METHODS |
661 |
- ///////////////////////////////////////////////// |
662 |
- |
663 |
- /** |
664 |
- * Creates recipient headers. |
665 |
- * @access private |
666 |
- * @return string |
667 |
- */ |
668 |
- function AddrAppend($type, $addr) { |
669 |
- $addr_str = $type . ": "; |
670 |
- $addr_str .= $this->AddrFormat($addr[0]); |
671 |
- if(count($addr) > 1) |
672 |
- { |
673 |
- for($i = 1; $i < count($addr); $i++) |
674 |
- $addr_str .= ", " . $this->AddrFormat($addr[$i]); |
675 |
- } |
676 |
- $addr_str .= $this->LE; |
677 |
- |
678 |
- return $addr_str; |
679 |
- } |
680 |
- |
681 |
- /** |
682 |
- * Formats an address correctly. |
683 |
- * @access private |
684 |
- * @return string |
685 |
- */ |
686 |
- function AddrFormat($addr) { |
687 |
- if(empty($addr[1])) |
688 |
- $formatted = $addr[0]; |
689 |
- else |
690 |
- { |
691 |
- $formatted = $this->EncodeHeader($addr[1], 'phrase') . " <" . |
692 |
- $addr[0] . ">"; |
693 |
- } |
694 |
- |
695 |
- return $formatted; |
696 |
- } |
697 |
- |
698 |
- /** |
699 |
- * Wraps message for use with mailers that do not |
700 |
- * automatically perform wrapping and for quoted-printable. |
701 |
- * Original written by philippe. |
702 |
- * @access private |
703 |
- * @return string |
704 |
- */ |
705 |
- function WrapText($message, $length, $qp_mode = false) { |
706 |
- $soft_break = ($qp_mode) ? sprintf(" =%s", $this->LE) : $this->LE; |
707 |
- |
708 |
- $message = $this->FixEOL($message); |
709 |
- if (substr($message, -1) == $this->LE) |
710 |
- $message = substr($message, 0, -1); |
711 |
- |
712 |
- $line = explode($this->LE, $message); |
713 |
- $message = ""; |
714 |
- for ($i=0 ;$i < count($line); $i++) |
715 |
- { |
716 |
- $line_part = explode(" ", $line[$i]); |
717 |
- $buf = ""; |
718 |
- for ($e = 0; $e<count($line_part); $e++) |
719 |
- { |
720 |
- $word = $line_part[$e]; |
721 |
- if ($qp_mode and (strlen($word) > $length)) |
722 |
- { |
723 |
- $space_left = $length - strlen($buf) - 1; |
724 |
- if ($e != 0) |
725 |
- { |
726 |
- if ($space_left > 20) |
727 |
- { |
728 |
- $len = $space_left; |
729 |
- if (substr($word, $len - 1, 1) == "=") |
730 |
- $len--; |
731 |
- elseif (substr($word, $len - 2, 1) == "=") |
732 |
- $len -= 2; |
733 |
- $part = substr($word, 0, $len); |
734 |
- $word = substr($word, $len); |
735 |
- $buf .= " " . $part; |
736 |
- $message .= $buf . sprintf("=%s", $this->LE); |
737 |
- } |
738 |
- else |
739 |
- { |
740 |
- $message .= $buf . $soft_break; |
741 |
- } |
742 |
- $buf = ""; |
743 |
- } |
744 |
- while (strlen($word) > 0) |
745 |
- { |
746 |
- $len = $length; |
747 |
- if (substr($word, $len - 1, 1) == "=") |
748 |
- $len--; |
749 |
- elseif (substr($word, $len - 2, 1) == "=") |
750 |
- $len -= 2; |
751 |
- $part = substr($word, 0, $len); |
752 |
- $word = substr($word, $len); |
753 |
- |
754 |
- if (strlen($word) > 0) |
755 |
- $message .= $part . sprintf("=%s", $this->LE); |
756 |
- else |
757 |
- $buf = $part; |
758 |
- } |
759 |
- } |
760 |
- else |
761 |
- { |
762 |
- $buf_o = $buf; |
763 |
- $buf .= ($e == 0) ? $word : (" " . $word); |
764 |
- |
765 |
- if (strlen($buf) > $length and $buf_o != "") |
766 |
- { |
767 |
- $message .= $buf_o . $soft_break; |
768 |
- $buf = $word; |
769 |
- } |
770 |
- } |
771 |
- } |
772 |
- $message .= $buf . $this->LE; |
773 |
- } |
774 |
- |
775 |
- return $message; |
776 |
- } |
777 |
- |
778 |
- /** |
779 |
- * Set the body wrapping. |
780 |
- * @access private |
781 |
- * @return void |
782 |
- */ |
783 |
- function SetWordWrap() { |
784 |
- if($this->WordWrap < 1) |
785 |
- return; |
786 |
- |
787 |
- switch($this->message_type) |
788 |
- { |
789 |
- case "alt": |
790 |
- // fall through |
791 |
- case "alt_attachment": |
792 |
- $this->AltBody = $this->WrapText($this->AltBody, $this->WordWrap); |
793 |
- break; |
794 |
- default: |
795 |
- $this->Body = $this->WrapText($this->Body, $this->WordWrap); |
796 |
- break; |
797 |
- } |
798 |
- } |
799 |
- |
800 |
- /** |
801 |
- * Assembles message header. |
802 |
- * @access private |
803 |
- * @return string |
804 |
- */ |
805 |
- function CreateHeader() { |
806 |
- $result = ""; |
807 |
- |
808 |
- // Set the boundaries |
809 |
- $uniq_id = md5(uniqid(time())); |
810 |
- $this->boundary[1] = "b1_" . $uniq_id; |
811 |
- $this->boundary[2] = "b2_" . $uniq_id; |
812 |
- |
813 |
- $result .= $this->HeaderLine("Date", $this->RFCDate()); |
814 |
- if($this->Sender == "") |
815 |
- $result .= $this->HeaderLine("Return-Path", trim($this->From)); |
816 |
- else |
817 |
- $result .= $this->HeaderLine("Return-Path", trim($this->Sender)); |
818 |
- |
819 |
- // To be created automatically by mail() |
820 |
- if($this->Mailer != "mail") |
821 |
- { |
822 |
- if(count($this->to) > 0) |
823 |
- $result .= $this->AddrAppend("To", $this->to); |
824 |
- else if (count($this->cc) == 0) |
825 |
- $result .= $this->HeaderLine("To", "undisclosed-recipients:;"); |
826 |
- if(count($this->cc) > 0) |
827 |
- $result .= $this->AddrAppend("Cc", $this->cc); |
828 |
- } |
829 |
- |
830 |
- $from = array(); |
831 |
- $from[0][0] = trim($this->From); |
832 |
- $from[0][1] = $this->FromName; |
833 |
- $result .= $this->AddrAppend("From", $from); |
834 |
- |
835 |
- // sendmail and mail() extract Bcc from the header before sending |
836 |
- if((($this->Mailer == "sendmail") || ($this->Mailer == "mail")) && (count($this->bcc) > 0)) |
837 |
- $result .= $this->AddrAppend("Bcc", $this->bcc); |
838 |
- |
839 |
- if(count($this->ReplyTo) > 0) |
840 |
- $result .= $this->AddrAppend("Reply-to", $this->ReplyTo); |
841 |
- |
842 |
- // mail() sets the subject itself |
843 |
- if($this->Mailer != "mail") |
844 |
- $result .= $this->HeaderLine("Subject", $this->EncodeHeader(trim($this->Subject))); |
845 |
- |
846 |
- $result .= sprintf("Message-ID: <%s@%s>%s", $uniq_id, $this->ServerHostname(), $this->LE); |
847 |
- $result .= $this->HeaderLine("X-Priority", $this->Priority); |
848 |
- $result .= $this->HeaderLine("X-Mailer", "PHPMailer [version " . $this->Version . "]"); |
849 |
- |
850 |
- if($this->ConfirmReadingTo != "") |
851 |
- { |
852 |
- $result .= $this->HeaderLine("Disposition-Notification-To", |
853 |
- "<" . trim($this->ConfirmReadingTo) . ">"); |
854 |
- } |
855 |
- |
856 |
- // Add custom headers |
857 |
- for($index = 0; $index < count($this->CustomHeader); $index++) |
858 |
- { |
859 |
- $result .= $this->HeaderLine(trim($this->CustomHeader[$index][0]), |
860 |
- $this->EncodeHeader(trim($this->CustomHeader[$index][1]))); |
861 |
- } |
862 |
- $result .= $this->HeaderLine("MIME-Version", "1.0"); |
863 |
- |
864 |
- switch($this->message_type) |
865 |
- { |
866 |
- case "plain": |
867 |
- $result .= $this->HeaderLine("Content-Transfer-Encoding", $this->Encoding); |
868 |
- $result .= sprintf("Content-Type: %s; charset=\"%s\"", |
869 |
- $this->ContentType, $this->CharSet); |
870 |
- break; |
871 |
- case "attachments": |
872 |
- // fall through |
873 |
- case "alt_attachments": |
874 |
- if($this->InlineImageExists()) |
875 |
- { |
876 |
- $result .= sprintf("Content-Type: %s;%s\ttype=\"text/html\";%s\tboundary=\"%s\"%s", |
877 |
- "multipart/related", $this->LE, $this->LE, |
878 |
- $this->boundary[1], $this->LE); |
879 |
- } |
880 |
- else |
881 |
- { |
882 |
- $result .= $this->HeaderLine("Content-Type", "multipart/mixed;"); |
883 |
- $result .= $this->TextLine("\tboundary=\"" . $this->boundary[1] . '"'); |
884 |
- } |
885 |
- break; |
886 |
- case "alt": |
887 |
- $result .= $this->HeaderLine("Content-Type", "multipart/alternative;"); |
888 |
- $result .= $this->TextLine("\tboundary=\"" . $this->boundary[1] . '"'); |
889 |
- break; |
890 |
- } |
891 |
- |
892 |
- if($this->Mailer != "mail") |
893 |
- $result .= $this->LE.$this->LE; |
894 |
- |
895 |
- return $result; |
896 |
- } |
897 |
- |
898 |
- /** |
899 |
- * Assembles the message body. Returns an empty string on failure. |
900 |
- * @access private |
901 |
- * @return string |
902 |
- */ |
903 |
- function CreateBody() { |
904 |
- $result = ""; |
905 |
- |
906 |
- $this->SetWordWrap(); |
907 |
- |
908 |
- switch($this->message_type) |
909 |
- { |
910 |
- case "alt": |
911 |
- $result .= $this->GetBoundary($this->boundary[1], "", |
912 |
- "text/plain", ""); |
913 |
- $result .= $this->EncodeString($this->AltBody, $this->Encoding); |
914 |
- $result .= $this->LE.$this->LE; |
915 |
- $result .= $this->GetBoundary($this->boundary[1], "", |
916 |
- "text/html", ""); |
917 |
- |
918 |
- $result .= $this->EncodeString($this->Body, $this->Encoding); |
919 |
- $result .= $this->LE.$this->LE; |
920 |
- |
921 |
- $result .= $this->EndBoundary($this->boundary[1]); |
922 |
- break; |
923 |
- case "plain": |
924 |
- $result .= $this->EncodeString($this->Body, $this->Encoding); |
925 |
- break; |
926 |
- case "attachments": |
927 |
- $result .= $this->GetBoundary($this->boundary[1], "", "", ""); |
928 |
- $result .= $this->EncodeString($this->Body, $this->Encoding); |
929 |
- $result .= $this->LE; |
930 |
- |
931 |
- $result .= $this->AttachAll(); |
932 |
- break; |
933 |
- case "alt_attachments": |
934 |
- $result .= sprintf("--%s%s", $this->boundary[1], $this->LE); |
935 |
- $result .= sprintf("Content-Type: %s;%s" . |
936 |
- "\tboundary=\"%s\"%s", |
937 |
- "multipart/alternative", $this->LE, |
938 |
- $this->boundary[2], $this->LE.$this->LE); |
939 |
- |
940 |
- // Create text body |
941 |
- $result .= $this->GetBoundary($this->boundary[2], "", |
942 |
- "text/plain", "") . $this->LE; |
943 |
- |
944 |
- $result .= $this->EncodeString($this->AltBody, $this->Encoding); |
945 |
- $result .= $this->LE.$this->LE; |
946 |
- |
947 |
- // Create the HTML body |
948 |
- $result .= $this->GetBoundary($this->boundary[2], "", |
949 |
- "text/html", "") . $this->LE; |
950 |
- |
951 |
- $result .= $this->EncodeString($this->Body, $this->Encoding); |
952 |
- $result .= $this->LE.$this->LE; |
953 |
- |
954 |
- $result .= $this->EndBoundary($this->boundary[2]); |
955 |
- |
956 |
- $result .= $this->AttachAll(); |
957 |
- break; |
958 |
- } |
959 |
- if($this->IsError()) |
960 |
- $result = ""; |
961 |
- |
962 |
- return $result; |
963 |
- } |
964 |
- |
965 |
- /** |
966 |
- * Returns the start of a message boundary. |
967 |
- * @access private |
968 |
- */ |
969 |
- function GetBoundary($boundary, $charSet, $contentType, $encoding) { |
970 |
- $result = ""; |
971 |
- if($charSet == "") { $charSet = $this->CharSet; } |
972 |
- if($contentType == "") { $contentType = $this->ContentType; } |
973 |
- if($encoding == "") { $encoding = $this->Encoding; } |
974 |
- |
975 |
- $result .= $this->TextLine("--" . $boundary); |
976 |
- $result .= sprintf("Content-Type: %s; charset = \"%s\"", |
977 |
- $contentType, $charSet); |
978 |
- $result .= $this->LE; |
979 |
- $result .= $this->HeaderLine("Content-Transfer-Encoding", $encoding); |
980 |
- $result .= $this->LE; |
981 |
- |
982 |
- return $result; |
983 |
- } |
984 |
- |
985 |
- /** |
986 |
- * Returns the end of a message boundary. |
987 |
- * @access private |
988 |
- */ |
989 |
- function EndBoundary($boundary) { |
990 |
- return $this->LE . "--" . $boundary . "--" . $this->LE; |
991 |
- } |
992 |
- |
993 |
- /** |
994 |
- * Sets the message type. |
995 |
- * @access private |
996 |
- * @return void |
997 |
- */ |
998 |
- function SetMessageType() { |
999 |
- if(count($this->attachment) < 1 && strlen($this->AltBody) < 1) |
1000 |
- $this->message_type = "plain"; |
1001 |
- else |
1002 |
- { |
1003 |
- if(count($this->attachment) > 0) |
1004 |
- $this->message_type = "attachments"; |
1005 |
- if(strlen($this->AltBody) > 0 && count($this->attachment) < 1) |
1006 |
- $this->message_type = "alt"; |
1007 |
- if(strlen($this->AltBody) > 0 && count($this->attachment) > 0) |
1008 |
- $this->message_type = "alt_attachments"; |
1009 |
- } |
1010 |
- } |
1011 |
- |
1012 |
- /** |
1013 |
- * Returns a formatted header line. |
1014 |
- * @access private |
1015 |
- * @return string |
1016 |
- */ |
1017 |
- function HeaderLine($name, $value) { |
1018 |
- return $name . ": " . $value . $this->LE; |
1019 |
- } |
1020 |
- |
1021 |
- /** |
1022 |
- * Returns a formatted mail line. |
1023 |
- * @access private |
1024 |
- * @return string |
1025 |
- */ |
1026 |
- function TextLine($value) { |
1027 |
- return $value . $this->LE; |
1028 |
- } |
1029 |
- |
1030 |
- ///////////////////////////////////////////////// |
1031 |
- // ATTACHMENT METHODS |
1032 |
- ///////////////////////////////////////////////// |
1033 |
- |
1034 |
- /** |
1035 |
- * Adds an attachment from a path on the filesystem. |
1036 |
- * Returns false if the file could not be found |
1037 |
- * or accessed. |
1038 |
- * @param string $path Path to the attachment. |
1039 |
- * @param string $name Overrides the attachment name. |
1040 |
- * @param string $encoding File encoding (see $Encoding). |
1041 |
- * @param string $type File extension (MIME) type. |
1042 |
- * @return bool |
1043 |
- */ |
1044 |
- function AddAttachment($path, $name = "", $encoding = "base64", |
1045 |
- $type = "application/octet-stream") { |
1046 |
- if(!@is_file($path)) |
1047 |
- { |
1048 |
- $this->SetError($this->Lang("file_access") . $path); |
1049 |
- return false; |
1050 |
- } |
1051 |
- |
1052 |
- $filename = basename($path); |
1053 |
- if($name == "") |
1054 |
- $name = $filename; |
1055 |
- |
1056 |
- $cur = count($this->attachment); |
1057 |
- $this->attachment[$cur][0] = $path; |
1058 |
- $this->attachment[$cur][1] = $filename; |
1059 |
- $this->attachment[$cur][2] = $name; |
1060 |
- $this->attachment[$cur][3] = $encoding; |
1061 |
- $this->attachment[$cur][4] = $type; |
1062 |
- $this->attachment[$cur][5] = false; // isStringAttachment |
1063 |
- $this->attachment[$cur][6] = "attachment"; |
1064 |
- $this->attachment[$cur][7] = 0; |
1065 |
- |
1066 |
- return true; |
1067 |
- } |
1068 |
- |
1069 |
- /** |
1070 |
- * Attaches all fs, string, and binary attachments to the message. |
1071 |
- * Returns an empty string on failure. |
1072 |
- * @access private |
1073 |
- * @return string |
1074 |
- */ |
1075 |
- function AttachAll() { |
1076 |
- // Return text of body |
1077 |
- $mime = array(); |
1078 |
- |
1079 |
- // Add all attachments |
1080 |
- for($i = 0; $i < count($this->attachment); $i++) |
1081 |
- { |
1082 |
- // Check for string attachment |
1083 |
- $bString = $this->attachment[$i][5]; |
1084 |
- if ($bString) |
1085 |
- $string = $this->attachment[$i][0]; |
1086 |
- else |
1087 |
- $path = $this->attachment[$i][0]; |
1088 |
- |
1089 |
- $filename = $this->attachment[$i][1]; |
1090 |
- $name = $this->attachment[$i][2]; |
1091 |
- $encoding = $this->attachment[$i][3]; |
1092 |
- $type = $this->attachment[$i][4]; |
1093 |
- $disposition = $this->attachment[$i][6]; |
1094 |
- $cid = $this->attachment[$i][7]; |
1095 |
- |
1096 |
- $mime[] = sprintf("--%s%s", $this->boundary[1], $this->LE); |
1097 |
- $mime[] = sprintf("Content-Type: %s; name=\"%s\"%s", $type, $name, $this->LE); |
1098 |
- $mime[] = sprintf("Content-Transfer-Encoding: %s%s", $encoding, $this->LE); |
1099 |
- |
1100 |
- if($disposition == "inline") |
1101 |
- $mime[] = sprintf("Content-ID: <%s>%s", $cid, $this->LE); |
1102 |
- |
1103 |
- $mime[] = sprintf("Content-Disposition: %s; filename=\"%s\"%s", |
1104 |
- $disposition, $name, $this->LE.$this->LE); |
1105 |
- |
1106 |
- // Encode as string attachment |
1107 |
- if($bString) |
1108 |
- { |
1109 |
- $mime[] = $this->EncodeString($string, $encoding); |
1110 |
- if($this->IsError()) { return ""; } |
1111 |
- $mime[] = $this->LE.$this->LE; |
1112 |
- } |
1113 |
- else |
1114 |
- { |
1115 |
- $mime[] = $this->EncodeFile($path, $encoding); |
1116 |
- if($this->IsError()) { return ""; } |
1117 |
- $mime[] = $this->LE.$this->LE; |
1118 |
- } |
1119 |
- } |
1120 |
- |
1121 |
- $mime[] = sprintf("--%s--%s", $this->boundary[1], $this->LE); |
1122 |
- |
1123 |
- return join("", $mime); |
1124 |
- } |
1125 |
- |
1126 |
- /** |
1127 |
- * Encodes attachment in requested format. Returns an |
1128 |
- * empty string on failure. |
1129 |
- * @access private |
1130 |
- * @return string |
1131 |
- */ |
1132 |
- function EncodeFile ($path, $encoding = "base64") { |
1133 |
- if(!@$fd = fopen($path, "rb")) |
1134 |
- { |
1135 |
- $this->SetError($this->Lang("file_open") . $path); |
1136 |
- return ""; |
1137 |
- } |
1138 |
- $file_buffer = fread($fd, filesize($path)); |
1139 |
- $file_buffer = $this->EncodeString($file_buffer, $encoding); |
1140 |
- fclose($fd); |
1141 |
- |
1142 |
- return $file_buffer; |
1143 |
- } |
1144 |
- |
1145 |
- /** |
1146 |
- * Encodes string to requested format. Returns an |
1147 |
- * empty string on failure. |
1148 |
- * @access private |
1149 |
- * @return string |
1150 |
- */ |
1151 |
- function EncodeString ($str, $encoding = "base64") { |
1152 |
- $encoded = ""; |
1153 |
- switch(strtolower($encoding)) { |
1154 |
- case "base64": |
1155 |
- // chunk_split is found in PHP >= 3.0.6 |
1156 |
- $encoded = chunk_split(base64_encode($str), 76, $this->LE); |
1157 |
- break; |
1158 |
- case "7bit": |
1159 |
- case "8bit": |
1160 |
- $encoded = $this->FixEOL($str); |
1161 |
- if (substr($encoded, -(strlen($this->LE))) != $this->LE) |
1162 |
- $encoded .= $this->LE; |
1163 |
- break; |
1164 |
- case "binary": |
1165 |
- $encoded = $str; |
1166 |
- break; |
1167 |
- case "quoted-printable": |
1168 |
- $encoded = $this->EncodeQP($str); |
1169 |
- break; |
1170 |
- default: |
1171 |
- $this->SetError($this->Lang("encoding") . $encoding); |
1172 |
- break; |
1173 |
- } |
1174 |
- return $encoded; |
1175 |
- } |
1176 |
- |
1177 |
- /** |
1178 |
- * Encode a header string to best of Q, B, quoted or none. |
1179 |
- * @access private |
1180 |
- * @return string |
1181 |
- */ |
1182 |
- function EncodeHeader ($str, $position = 'text') { |
1183 |
- $x = 0; |
1184 |
- |
1185 |
- switch (strtolower($position)) { |
1186 |
- case 'phrase': |
1187 |
- if (!preg_match('/[\200-\377]/', $str)) { |
1188 |
- // Can't use addslashes as we don't know what value has magic_quotes_sybase. |
1189 |
- $encoded = addcslashes($str, "\0..\37\177\\\""); |
1190 |
- |
1191 |
- if (($str == $encoded) && !preg_match('/[^A-Za-z0-9!#$%&\'*+\/=?^_`{|}~ -]/', $str)) |
1192 |
- return ($encoded); |
1193 |
- else |
1194 |
- return ("\"$encoded\""); |
1195 |
- } |
1196 |
- $x = preg_match_all('/[^\040\041\043-\133\135-\176]/', $str, $matches); |
1197 |
- break; |
1198 |
- case 'comment': |
1199 |
- $x = preg_match_all('/[()"]/', $str, $matches); |
1200 |
- // Fall-through |
1201 |
- case 'text': |
1202 |
- default: |
1203 |
- $x += preg_match_all('/[\000-\010\013\014\016-\037\177-\377]/', $str, $matches); |
1204 |
- break; |
1205 |
- } |
1206 |
- |
1207 |
- if ($x == 0) |
1208 |
- return ($str); |
1209 |
- |
1210 |
- $maxlen = 75 - 7 - strlen($this->CharSet); |
1211 |
- // Try to select the encoding which should produce the shortest output |
1212 |
- if (strlen($str)/3 < $x) { |
1213 |
- $encoding = 'B'; |
1214 |
- $encoded = base64_encode($str); |
1215 |
- $maxlen -= $maxlen % 4; |
1216 |
- $encoded = trim(chunk_split($encoded, $maxlen, "\n")); |
1217 |
- } else { |
1218 |
- $encoding = 'Q'; |
1219 |
- $encoded = $this->EncodeQ($str, $position); |
1220 |
- $encoded = $this->WrapText($encoded, $maxlen, true); |
1221 |
- $encoded = str_replace("=".$this->LE, "\n", trim($encoded)); |
1222 |
- } |
1223 |
- |
1224 |
- $encoded = preg_replace('/^(.*)$/m', " =?".$this->CharSet."?$encoding?\\1?=", $encoded); |
1225 |
- $encoded = trim(str_replace("\n", $this->LE, $encoded)); |
1226 |
- |
1227 |
- return $encoded; |
1228 |
- } |
1229 |
- |
1230 |
- /** |
1231 |
- * Encode string to quoted-printable. |
1232 |
- * @access private |
1233 |
- * @return string |
1234 |
- */ |
1235 |
- function EncodeQP ($str) { |
1236 |
- $encoded = $this->FixEOL($str); |
1237 |
- if (substr($encoded, -(strlen($this->LE))) != $this->LE) |
1238 |
- $encoded .= $this->LE; |
1239 |
- |
1240 |
- // Replace every high ascii, control and = characters |
1241 |
- $encoded = preg_replace('/([\000-\010\013\014\016-\037\075\177-\377])/e', |
1242 |
- "'='.sprintf('%02X', ord('\\1'))", $encoded); |
1243 |
- // Replace every spaces and tabs when it's the last character on a line |
1244 |
- $encoded = preg_replace("/([\011\040])".$this->LE."/e", |
1245 |
- "'='.sprintf('%02X', ord('\\1')).'".$this->LE."'", $encoded); |
1246 |
- |
1247 |
- // Maximum line length of 76 characters before CRLF (74 + space + '=') |
1248 |
- $encoded = $this->WrapText($encoded, 74, true); |
1249 |
- |
1250 |
- return $encoded; |
1251 |
- } |
1252 |
- |
1253 |
- /** |
1254 |
- * Encode string to q encoding. |
1255 |
- * @access private |
1256 |
- * @return string |
1257 |
- */ |
1258 |
- function EncodeQ ($str, $position = "text") { |
1259 |
- // There should not be any EOL in the string |
1260 |
- $encoded = preg_replace("[\r\n]", "", $str); |
1261 |
- |
1262 |
- switch (strtolower($position)) { |
1263 |
- case "phrase": |
1264 |
- $encoded = preg_replace("/([^A-Za-z0-9!*+\/ -])/e", "'='.sprintf('%02X', ord('\\1'))", $encoded); |
1265 |
- break; |
1266 |
- case "comment": |
1267 |
- $encoded = preg_replace("/([\(\)\"])/e", "'='.sprintf('%02X', ord('\\1'))", $encoded); |
1268 |
- case "text": |
1269 |
- default: |
1270 |
- // Replace every high ascii, control =, ? and _ characters |
1271 |
- $encoded = preg_replace('/([\000-\011\013\014\016-\037\075\077\137\177-\377])/e', |
1272 |
- "'='.sprintf('%02X', ord('\\1'))", $encoded); |
1273 |
- break; |
1274 |
- } |
1275 |
- |
1276 |
- // Replace every spaces to _ (more readable than =20) |
1277 |
- $encoded = str_replace(" ", "_", $encoded); |
1278 |
- |
1279 |
- return $encoded; |
1280 |
- } |
1281 |
- |
1282 |
- /** |
1283 |
- * Adds a string or binary attachment (non-filesystem) to the list. |
1284 |
- * This method can be used to attach ascii or binary data, |
1285 |
- * such as a BLOB record from a database. |
1286 |
- * @param string $string String attachment data. |
1287 |
- * @param string $filename Name of the attachment. |
1288 |
- * @param string $encoding File encoding (see $Encoding). |
1289 |
- * @param string $type File extension (MIME) type. |
1290 |
- * @return void |
1291 |
- */ |
1292 |
- function AddStringAttachment($string, $filename, $encoding = "base64", |
1293 |
- $type = "application/octet-stream") { |
1294 |
- // Append to $attachment array |
1295 |
- $cur = count($this->attachment); |
1296 |
- $this->attachment[$cur][0] = $string; |
1297 |
- $this->attachment[$cur][1] = $filename; |
1298 |
- $this->attachment[$cur][2] = $filename; |
1299 |
- $this->attachment[$cur][3] = $encoding; |
1300 |
- $this->attachment[$cur][4] = $type; |
1301 |
- $this->attachment[$cur][5] = true; // isString |
1302 |
- $this->attachment[$cur][6] = "attachment"; |
1303 |
- $this->attachment[$cur][7] = 0; |
1304 |
- } |
1305 |
- |
1306 |
- /** |
1307 |
- * Adds an embedded attachment. This can include images, sounds, and |
1308 |
- * just about any other document. Make sure to set the $type to an |
1309 |
- * image type. For JPEG images use "image/jpeg" and for GIF images |
1310 |
- * use "image/gif". |
1311 |
- * @param string $path Path to the attachment. |
1312 |
- * @param string $cid Content ID of the attachment. Use this to identify |
1313 |
- * the Id for accessing the image in an HTML form. |
1314 |
- * @param string $name Overrides the attachment name. |
1315 |
- * @param string $encoding File encoding (see $Encoding). |
1316 |
- * @param string $type File extension (MIME) type. |
1317 |
- * @return bool |
1318 |
- */ |
1319 |
- function AddEmbeddedImage($path, $cid, $name = "", $encoding = "base64", |
1320 |
- $type = "application/octet-stream") { |
1321 |
- |
1322 |
- if(!@is_file($path)) |
1323 |
- { |
1324 |
- $this->SetError($this->Lang("file_access") . $path); |
1325 |
- return false; |
1326 |
- } |
1327 |
- |
1328 |
- $filename = basename($path); |
1329 |
- if($name == "") |
1330 |
- $name = $filename; |
1331 |
- |
1332 |
- // Append to $attachment array |
1333 |
- $cur = count($this->attachment); |
1334 |
- $this->attachment[$cur][0] = $path; |
1335 |
- $this->attachment[$cur][1] = $filename; |
1336 |
- $this->attachment[$cur][2] = $name; |
1337 |
- $this->attachment[$cur][3] = $encoding; |
1338 |
- $this->attachment[$cur][4] = $type; |
1339 |
- $this->attachment[$cur][5] = false; // isStringAttachment |
1340 |
- $this->attachment[$cur][6] = "inline"; |
1341 |
- $this->attachment[$cur][7] = $cid; |
1342 |
- |
1343 |
- return true; |
1344 |
- } |
1345 |
- |
1346 |
- /** |
1347 |
- * Returns true if an inline attachment is present. |
1348 |
- * @access private |
1349 |
- * @return bool |
1350 |
- */ |
1351 |
- function InlineImageExists() { |
1352 |
- $result = false; |
1353 |
- for($i = 0; $i < count($this->attachment); $i++) |
1354 |
- { |
1355 |
- if($this->attachment[$i][6] == "inline") |
1356 |
- { |
1357 |
- $result = true; |
1358 |
- break; |
1359 |
- } |
1360 |
- } |
1361 |
- |
1362 |
- return $result; |
1363 |
- } |
1364 |
- |
1365 |
- ///////////////////////////////////////////////// |
1366 |
- // MESSAGE RESET METHODS |
1367 |
- ///////////////////////////////////////////////// |
1368 |
- |
1369 |
- /** |
1370 |
- * Clears all recipients assigned in the TO array. Returns void. |
1371 |
- * @return void |
1372 |
- */ |
1373 |
- function ClearAddresses() { |
1374 |
- $this->to = array(); |
1375 |
- } |
1376 |
- |
1377 |
- /** |
1378 |
- * Clears all recipients assigned in the CC array. Returns void. |
1379 |
- * @return void |
1380 |
- */ |
1381 |
- function ClearCCs() { |
1382 |
- $this->cc = array(); |
1383 |
- } |
1384 |
- |
1385 |
- /** |
1386 |
- * Clears all recipients assigned in the BCC array. Returns void. |
1387 |
- * @return void |
1388 |
- */ |
1389 |
- function ClearBCCs() { |
1390 |
- $this->bcc = array(); |
1391 |
- } |
1392 |
- |
1393 |
- /** |
1394 |
- * Clears all recipients assigned in the ReplyTo array. Returns void. |
1395 |
- * @return void |
1396 |
- */ |
1397 |
- function ClearReplyTos() { |
1398 |
- $this->ReplyTo = array(); |
1399 |
- } |
1400 |
- |
1401 |
- /** |
1402 |
- * Clears all recipients assigned in the TO, CC and BCC |
1403 |
- * array. Returns void. |
1404 |
- * @return void |
1405 |
- */ |
1406 |
- function ClearAllRecipients() { |
1407 |
- $this->to = array(); |
1408 |
- $this->cc = array(); |
1409 |
- $this->bcc = array(); |
1410 |
- } |
1411 |
- |
1412 |
- /** |
1413 |
- * Clears all previously set filesystem, string, and binary |
1414 |
- * attachments. Returns void. |
1415 |
- * @return void |
1416 |
- */ |
1417 |
- function ClearAttachments() { |
1418 |
- $this->attachment = array(); |
1419 |
- } |
1420 |
- |
1421 |
- /** |
1422 |
- * Clears all custom headers. Returns void. |
1423 |
- * @return void |
1424 |
- */ |
1425 |
- function ClearCustomHeaders() { |
1426 |
- $this->CustomHeader = array(); |
1427 |
- } |
1428 |
- |
1429 |
- |
1430 |
- ///////////////////////////////////////////////// |
1431 |
- // MISCELLANEOUS METHODS |
1432 |
- ///////////////////////////////////////////////// |
1433 |
- |
1434 |
- /** |
1435 |
- * Adds the error message to the error container. |
1436 |
- * Returns void. |
1437 |
- * @access private |
1438 |
- * @return void |
1439 |
- */ |
1440 |
- function SetError($msg) { |
1441 |
- $this->error_count++; |
1442 |
- $this->ErrorInfo = $msg; |
1443 |
- } |
1444 |
- |
1445 |
- /** |
1446 |
- * Returns the proper RFC 822 formatted date. |
1447 |
- * @access private |
1448 |
- * @return string |
1449 |
- */ |
1450 |
- function RFCDate() { |
1451 |
- $tz = date("Z"); |
1452 |
- $tzs = ($tz < 0) ? "-" : "+"; |
1453 |
- $tz = abs($tz); |
1454 |
- $tz = ($tz/3600)*100 + ($tz%3600)/60; |
1455 |
- $result = sprintf("%s %s%04d", date("D, j M Y H:i:s"), $tzs, $tz); |
1456 |
- |
1457 |
- return $result; |
1458 |
- } |
1459 |
- |
1460 |
- /** |
1461 |
- * Returns the appropriate server variable. Should work with both |
1462 |
- * PHP 4.1.0+ as well as older versions. Returns an empty string |
1463 |
- * if nothing is found. |
1464 |
- * @access private |
1465 |
- * @return mixed |
1466 |
- */ |
1467 |
- function ServerVar($varName) { |
1468 |
- global $HTTP_SERVER_VARS; |
1469 |
- global $HTTP_ENV_VARS; |
1470 |
- |
1471 |
- if(!isset($_SERVER)) |
1472 |
- { |
1473 |
- $_SERVER = $HTTP_SERVER_VARS; |
1474 |
- if(!isset($_SERVER["REMOTE_ADDR"])) |
1475 |
- $_SERVER = $HTTP_ENV_VARS; // must be Apache |
1476 |
- } |
1477 |
- |
1478 |
- if(isset($_SERVER[$varName])) |
1479 |
- return $_SERVER[$varName]; |
1480 |
- else |
1481 |
- return ""; |
1482 |
- } |
1483 |
- |
1484 |
- /** |
1485 |
- * Returns the server hostname or 'localhost.localdomain' if unknown. |
1486 |
- * @access private |
1487 |
- * @return string |
1488 |
- */ |
1489 |
- function ServerHostname() { |
1490 |
- if ($this->Hostname != "") |
1491 |
- $result = $this->Hostname; |
1492 |
- elseif ($this->ServerVar('SERVER_NAME') != "") |
1493 |
- $result = $this->ServerVar('SERVER_NAME'); |
1494 |
- else |
1495 |
- $result = "localhost.localdomain"; |
1496 |
- |
1497 |
- return $result; |
1498 |
- } |
1499 |
- |
1500 |
- /** |
1501 |
- * Returns a message in the appropriate language. |
1502 |
- * @access private |
1503 |
- * @return string |
1504 |
- */ |
1505 |
- function Lang($key) { |
1506 |
- if(count($this->language) < 1) |
1507 |
- $this->SetLanguage("en"); // set the default language |
1508 |
- |
1509 |
- if(isset($this->language[$key])) |
1510 |
- return $this->language[$key]; |
1511 |
- else |
1512 |
- return "Language string failed to load: " . $key; |
1513 |
- } |
1514 |
- |
1515 |
- /** |
1516 |
- * Returns true if an error occurred. |
1517 |
- * @return bool |
1518 |
- */ |
1519 |
- function IsError() { |
1520 |
- return ($this->error_count > 0); |
1521 |
- } |
1522 |
- |
1523 |
- /** |
1524 |
- * Changes every end of line from CR or LF to CRLF. |
1525 |
- * @access private |
1526 |
- * @return string |
1527 |
- */ |
1528 |
- function FixEOL($str) { |
1529 |
- $str = str_replace("\r\n", "\n", $str); |
1530 |
- $str = str_replace("\r", "\n", $str); |
1531 |
- $str = str_replace("\n", $this->LE, $str); |
1532 |
- return $str; |
1533 |
- } |
1534 |
- |
1535 |
- /** |
1536 |
- * Adds a custom header. |
1537 |
- * @return void |
1538 |
- */ |
1539 |
- function AddCustomHeader($custom_header) { |
1540 |
- $this->CustomHeader[] = explode(":", $custom_header, 2); |
1541 |
- } |
1542 |
-} |
1543 |
- |
1544 |
-?> |
1545 |
+<?php |
1546 |
+//////////////////////////////////////////////////// |
1547 |
+// PHPMailer - PHP email class |
1548 |
+// |
1549 |
+// Class for sending email using either |
1550 |
+// sendmail, PHP mail(), or SMTP. Methods are |
1551 |
+// based upon the standard AspEmail(tm) classes. |
1552 |
+// |
1553 |
+// Copyright (C) 2001 - 2003 Brent R. Matzelle |
1554 |
+// |
1555 |
+// License: LGPL, see LICENSE |
1556 |
+//////////////////////////////////////////////////// |
1557 |
+ |
1558 |
+/** |
1559 |
+ * PHPMailer - PHP email transport class |
1560 |
+ * @package PHPMailer |
1561 |
+ * @author Brent R. Matzelle |
1562 |
+ * @copyright 2001 - 2003 Brent R. Matzelle |
1563 |
+ */ |
1564 |
+class PHPMailer |
1565 |
+{ |
1566 |
+ ///////////////////////////////////////////////// |
1567 |
+ // PUBLIC VARIABLES |
1568 |
+ ///////////////////////////////////////////////// |
1569 |
+ |
1570 |
+ /** |
1571 |
+ * Email priority (1 = High, 3 = Normal, 5 = low). |
1572 |
+ * @var int |
1573 |
+ */ |
1574 |
+ var $Priority = 3; |
1575 |
+ |
1576 |
+ /** |
1577 |
+ * Sets the CharSet of the message. |
1578 |
+ * @var string |
1579 |
+ */ |
1580 |
+ var $CharSet = "iso-8859-1"; |
1581 |
+ |
1582 |
+ /** |
1583 |
+ * Sets the Content-type of the message. |
1584 |
+ * @var string |
1585 |
+ */ |
1586 |
+ var $ContentType = "text/plain"; |
1587 |
+ |
1588 |
+ /** |
1589 |
+ * Sets the Encoding of the message. Options for this are "8bit", |
1590 |
+ * "7bit", "binary", "base64", and "quoted-printable". |
1591 |
+ * @var string |
1592 |
+ */ |
1593 |
+ var $Encoding = "8bit"; |
1594 |
+ |
1595 |
+ /** |
1596 |
+ * Holds the most recent mailer error message. |
1597 |
+ * @var string |
1598 |
+ */ |
1599 |
+ var $ErrorInfo = ""; |
1600 |
+ |
1601 |
+ /** |
1602 |
+ * Sets the From email address for the message. |
1603 |
+ * @var string |
1604 |
+ */ |
1605 |
+ var $From = "root@localhost"; |
1606 |
+ |
1607 |
+ /** |
1608 |
+ * Sets the From name of the message. |
1609 |
+ * @var string |
1610 |
+ */ |
1611 |
+ var $FromName = "Root User"; |
1612 |
+ |
1613 |
+ /** |
1614 |
+ * Sets the Sender email (Return-Path) of the message. If not empty, |
1615 |
+ * will be sent via -f to sendmail or as 'MAIL FROM' in smtp mode. |
1616 |
+ * @var string |
1617 |
+ */ |
1618 |
+ var $Sender = ""; |
1619 |
+ |
1620 |
+ /** |
1621 |
+ * Sets the Subject of the message. |
1622 |
+ * @var string |
1623 |
+ */ |
1624 |
+ var $Subject = ""; |
1625 |
+ |
1626 |
+ /** |
1627 |
+ * Sets the Body of the message. This can be either an HTML or text body. |
1628 |
+ * If HTML then run IsHTML(true). |
1629 |
+ * @var string |
1630 |
+ */ |
1631 |
+ var $Body = ""; |
1632 |
+ |
1633 |
+ /** |
1634 |
+ * Sets the text-only body of the message. This automatically sets the |
1635 |
+ * email to multipart/alternative. This body can be read by mail |
1636 |
+ * clients that do not have HTML email capability such as mutt. Clients |
1637 |
+ * that can read HTML will view the normal Body. |
1638 |
+ * @var string |
1639 |
+ */ |
1640 |
+ var $AltBody = ""; |
1641 |
+ |
1642 |
+ /** |
1643 |
+ * Sets word wrapping on the body of the message to a given number of |
1644 |
+ * characters. |
1645 |
+ * @var int |
1646 |
+ */ |
1647 |
+ var $WordWrap = 0; |
1648 |
+ |
1649 |
+ /** |
1650 |
+ * Method to send mail: ("mail", "sendmail", or "smtp"). |
1651 |
+ * @var string |
1652 |
+ */ |
1653 |
+ var $Mailer = "mail"; |
1654 |
+ |
1655 |
+ /** |
1656 |
+ * Sets the path of the sendmail program. |
1657 |
+ * @var string |
1658 |
+ */ |
1659 |
+ var $Sendmail = "/usr/sbin/sendmail"; |
1660 |
+ |
1661 |
+ /** |
1662 |
+ * Path to PHPMailer plugins. This is now only useful if the SMTP class |
1663 |
+ * is in a different directory than the PHP include path. |
1664 |
+ * @var string |
1665 |
+ */ |
1666 |
+ var $PluginDir = ""; |
1667 |
+ |
1668 |
+ /** |
1669 |
+ * Holds PHPMailer version. |
1670 |
+ * @var string |
1671 |
+ */ |
1672 |
+ var $Version = "1.72"; |
1673 |
+ |
1674 |
+ /** |
1675 |
+ * Sets the email address that a reading confirmation will be sent. |
1676 |
+ * @var string |
1677 |
+ */ |
1678 |
+ var $ConfirmReadingTo = ""; |
1679 |
+ |
1680 |
+ /** |
1681 |
+ * Sets the hostname to use in Message-Id and Received headers |
1682 |
+ * and as default HELO string. If empty, the value returned |
1683 |
+ * by SERVER_NAME is used or 'localhost.localdomain'. |
1684 |
+ * @var string |
1685 |
+ */ |
1686 |
+ var $Hostname = ""; |
1687 |
+ |
1688 |
+ ///////////////////////////////////////////////// |
1689 |
+ // SMTP VARIABLES |
1690 |
+ ///////////////////////////////////////////////// |
1691 |
+ |
1692 |
+ /** |
1693 |
+ * Sets the SMTP hosts. All hosts must be separated by a |
1694 |
+ * semicolon. You can also specify a different port |
1695 |
+ * for each host by using this format: [hostname:port] |
1696 |
+ * (e.g. "smtp1.example.com:25;smtp2.example.com"). |
1697 |
+ * Hosts will be tried in order. |
1698 |
+ * @var string |
1699 |
+ */ |
1700 |
+ var $Host = "localhost"; |
1701 |
+ |
1702 |
+ /** |
1703 |
+ * Sets the default SMTP server port. |
1704 |
+ * @var int |
1705 |
+ */ |
1706 |
+ var $Port = 25; |
1707 |
+ |
1708 |
+ /** |
1709 |
+ * Sets the SMTP HELO of the message (Default is $Hostname). |
1710 |
+ * @var string |
1711 |
+ */ |
1712 |
+ var $Helo = ""; |
1713 |
+ |
1714 |
+ /** |
1715 |
+ * Sets SMTP authentication. Utilizes the Username and Password variables. |
1716 |
+ * @var bool |
1717 |
+ */ |
1718 |
+ var $SMTPAuth = false; |
1719 |
+ |
1720 |
+ /** |
1721 |
+ * Sets SMTP username. |
1722 |
+ * @var string |
1723 |
+ */ |
1724 |
+ var $Username = ""; |
1725 |
+ |
1726 |
+ /** |
1727 |
+ * Sets SMTP password. |
1728 |
+ * @var string |
1729 |
+ */ |
1730 |
+ var $Password = ""; |
1731 |
+ |
1732 |
+ /** |
1733 |
+ * Sets the SMTP server timeout in seconds. This function will not |
1734 |
+ * work with the win32 version. |
1735 |
+ * @var int |
1736 |
+ */ |
1737 |
+ var $Timeout = 10; |
1738 |
+ |
1739 |
+ /** |
1740 |
+ * Sets SMTP class debugging on or off. |
1741 |
+ * @var bool |
1742 |
+ */ |
1743 |
+ var $SMTPDebug = false; |
1744 |
+ |
1745 |
+ /** |
1746 |
+ * Prevents the SMTP connection from being closed after each mail |
1747 |
+ * sending. If this is set to true then to close the connection |
1748 |
+ * requires an explicit call to SmtpClose(). |
1749 |
+ * @var bool |
1750 |
+ */ |
1751 |
+ var $SMTPKeepAlive = false; |
1752 |
+ |
1753 |
+ /**#@+ |
1754 |
+ * @access private |
1755 |
+ */ |
1756 |
+ var $smtp = NULL; |
1757 |
+ var $to = array(); |
1758 |
+ var $cc = array(); |
1759 |
+ var $bcc = array(); |
1760 |
+ var $ReplyTo = array(); |
1761 |
+ var $attachment = array(); |
1762 |
+ var $CustomHeader = array(); |
1763 |
+ var $message_type = ""; |
1764 |
+ var $boundary = array(); |
1765 |
+ var $language = array(); |
1766 |
+ var $error_count = 0; |
1767 |
+ var $LE = "\n"; |
1768 |
+ /**#@-*/ |
1769 |
+ |
1770 |
+ ///////////////////////////////////////////////// |
1771 |
+ // CONSTRUCTOR |
1772 |
+ ///////////////////////////////////////////////// |
1773 |
+ /** |
1774 |
+ * Constructor, just set up language |
1775 |
+ * @param none |
1776 |
+ * @return void |
1777 |
+ */ |
1778 |
+ function __construct() { |
1779 |
+ global $conf; |
1780 |
+ global $charset; |
1781 |
+ |
1782 |
+ $this->CharSet = $charset; |
1783 |
+ |
1784 |
+ $this->SetLanguage(); |
1785 |
+ |
1786 |
+ $this->Mailer = $conf['app']['emailType']; |
1787 |
+ |
1788 |
+ if ($this->Mailer == 'smtp') { // Set smtp variables |
1789 |
+ $this->Host = $conf['app']['smtpHost']; |
1790 |
+ $this->Port = $conf['app']['smtpPort']; |
1791 |
+ } |
1792 |
+ |
1793 |
+ if ($this->Mailer == 'sendmail') // Set sendmail variables |
1794 |
+ $this->Sendmail = $conf['app']['sendmailPath']; |
1795 |
+ |
1796 |
+ if ($this->Mailer == 'qmail') // Set qmail variables |
1797 |
+ $this->Sendmail = $conf['app']['qmailPath']; |
1798 |
+ } |
1799 |
+ |
1800 |
+ ///////////////////////////////////////////////// |
1801 |
+ // VARIABLE METHODS |
1802 |
+ ///////////////////////////////////////////////// |
1803 |
+ |
1804 |
+ /** |
1805 |
+ * Sets message type to HTML. |
1806 |
+ * @param bool $bool |
1807 |
+ * @return void |
1808 |
+ */ |
1809 |
+ function IsHTML($bool) { |
1810 |
+ if($bool == true) |
1811 |
+ $this->ContentType = "text/html"; |
1812 |
+ else |
1813 |
+ $this->ContentType = "text/plain"; |
1814 |
+ } |
1815 |
+ |
1816 |
+ /** |
1817 |
+ * Sets Mailer to send message using SMTP. |
1818 |
+ * @return void |
1819 |
+ */ |
1820 |
+ function IsSMTP() { |
1821 |
+ $this->Mailer = "smtp"; |
1822 |
+ } |
1823 |
+ |
1824 |
+ /** |
1825 |
+ * Sets Mailer to send message using PHP mail() function. |
1826 |
+ * @return void |
1827 |
+ */ |
1828 |
+ function IsMail() { |
1829 |
+ $this->Mailer = "mail"; |
1830 |
+ } |
1831 |
+ |
1832 |
+ /** |
1833 |
+ * Sets Mailer to send message using the $Sendmail program. |
1834 |
+ * @return void |
1835 |
+ */ |
1836 |
+ function IsSendmail() { |
1837 |
+ $this->Mailer = "sendmail"; |
1838 |
+ } |
1839 |
+ |
1840 |
+ /** |
1841 |
+ * Sets Mailer to send message using the qmail MTA. |
1842 |
+ * @return void |
1843 |
+ */ |
1844 |
+ function IsQmail() { |
1845 |
+ $this->Sendmail = "/var/qmail/bin/sendmail"; |
1846 |
+ $this->Mailer = "sendmail"; |
1847 |
+ } |
1848 |
+ |
1849 |
+ |
1850 |
+ ///////////////////////////////////////////////// |
1851 |
+ // RECIPIENT METHODS |
1852 |
+ ///////////////////////////////////////////////// |
1853 |
+ |
1854 |
+ /** |
1855 |
+ * Adds a "To" address. |
1856 |
+ * @param string $address |
1857 |
+ * @param string $name |
1858 |
+ * @return void |
1859 |
+ */ |
1860 |
+ function AddAddress($address, $name = "") { |
1861 |
+ $cur = count($this->to); |
1862 |
+ $this->to[$cur][0] = trim($address); |
1863 |
+ $this->to[$cur][1] = $name; |
1864 |
+ } |
1865 |
+ |
1866 |
+ /** |
1867 |
+ * Adds a "Cc" address. Note: this function works |
1868 |
+ * with the SMTP mailer on win32, not with the "mail" |
1869 |
+ * mailer. |
1870 |
+ * @param string $address |
1871 |
+ * @param string $name |
1872 |
+ * @return void |
1873 |
+ */ |
1874 |
+ function AddCC($address, $name = "") { |
1875 |
+ $cur = count($this->cc); |
1876 |
+ $this->cc[$cur][0] = trim($address); |
1877 |
+ $this->cc[$cur][1] = $name; |
1878 |
+ } |
1879 |
+ |
1880 |
+ /** |
1881 |
+ * Adds a "Bcc" address. Note: this function works |
1882 |
+ * with the SMTP mailer on win32, not with the "mail" |
1883 |
+ * mailer. |
1884 |
+ * @param string $address |
1885 |
+ * @param string $name |
1886 |
+ * @return void |
1887 |
+ */ |
1888 |
+ function AddBCC($address, $name = "") { |
1889 |
+ $cur = count($this->bcc); |
1890 |
+ $this->bcc[$cur][0] = trim($address); |
1891 |
+ $this->bcc[$cur][1] = $name; |
1892 |
+ } |
1893 |
+ |
1894 |
+ /** |
1895 |
+ * Adds a "Reply-to" address. |
1896 |
+ * @param string $address |
1897 |
+ * @param string $name |
1898 |
+ * @return void |
1899 |
+ */ |
1900 |
+ function AddReplyTo($address, $name = "") { |
1901 |
+ $cur = count($this->ReplyTo); |
1902 |
+ $this->ReplyTo[$cur][0] = trim($address); |
1903 |
+ $this->ReplyTo[$cur][1] = $name; |
1904 |
+ } |
1905 |
+ |
1906 |
+ |
1907 |
+ ///////////////////////////////////////////////// |
1908 |
+ // MAIL SENDING METHODS |
1909 |
+ ///////////////////////////////////////////////// |
1910 |
+ |
1911 |
+ /** |
1912 |
+ * Creates message and assigns Mailer. If the message is |
1913 |
+ * not sent successfully then it returns false. Use the ErrorInfo |
1914 |
+ * variable to view description of the error. |
1915 |
+ * @return bool |
1916 |
+ */ |
1917 |
+ function Send() { |
1918 |
+ $header = ""; |
1919 |
+ $body = ""; |
1920 |
+ $result = true; |
1921 |
+ |
1922 |
+ if((count($this->to) + count($this->cc) + count($this->bcc)) < 1) |
1923 |
+ { |
1924 |
+ $this->SetError($this->Lang("provide_address")); |
1925 |
+ return false; |
1926 |
+ } |
1927 |
+ |
1928 |
+ // Set whether the message is multipart/alternative |
1929 |
+ if(!empty($this->AltBody)) |
1930 |
+ $this->ContentType = "multipart/alternative"; |
1931 |
+ |
1932 |
+ $this->error_count = 0; // reset errors |
1933 |
+ $this->SetMessageType(); |
1934 |
+ $header .= $this->CreateHeader(); |
1935 |
+ $body = $this->CreateBody(); |
1936 |
+ |
1937 |
+ // Nick Korbel - 08-21-2005 |
1938 |
+ if (version_compare('4.3.0',phpversion(), '<=') == 1) { |
1939 |
+ $this->Subject = html_entity_decode($this->Subject, ENT_COMPAT, $this->CharSet); |
1940 |
+ if ($this->ContentType != "text/html") |
1941 |
+ $body = html_entity_decode($body, ENT_COMPAT, $this->CharSet); |
1942 |
+ } |
1943 |
+ |
1944 |
+ if($body == "") { return false; } |
1945 |
+ |
1946 |
+ // Choose the mailer |
1947 |
+ switch($this->Mailer) |
1948 |
+ { |
1949 |
+ case "sendmail": |
1950 |
+ $result = $this->SendmailSend($header, $body); |
1951 |
+ break; |
1952 |
+ case "mail": |
1953 |
+ $result = $this->MailSend($header, $body); |
1954 |
+ break; |
1955 |
+ case "smtp": |
1956 |
+ $result = $this->SmtpSend($header, $body); |
1957 |
+ break; |
1958 |
+ default: |
1959 |
+ $this->SetError($this->Mailer . $this->Lang("mailer_not_supported")); |
1960 |
+ $result = false; |
1961 |
+ break; |
1962 |
+ } |
1963 |
+ |
1964 |
+ return $result; |
1965 |
+ } |
1966 |
+ |
1967 |
+ /** |
1968 |
+ * Sends mail using the $Sendmail program. |
1969 |
+ * @access private |
1970 |
+ * @return bool |
1971 |
+ */ |
1972 |
+ function SendmailSend($header, $body) { |
1973 |
+ if ($this->Sender != "") |
1974 |
+ $sendmail = sprintf("%s -oi -f %s -t", $this->Sendmail, $this->Sender); |
1975 |
+ else |
1976 |
+ $sendmail = sprintf("%s -oi -t", $this->Sendmail); |
1977 |
+ |
1978 |
+ if(!@$mail = popen($sendmail, "w")) |
1979 |
+ { |
1980 |
+ $this->SetError($this->Lang("execute") . $this->Sendmail); |
1981 |
+ return false; |
1982 |
+ } |
1983 |
+ |
1984 |
+ fputs($mail, $header); |
1985 |
+ fputs($mail, $body); |
1986 |
+ |
1987 |
+ $result = pclose($mail) >> 8 & 0xFF; |
1988 |
+ if($result != 0) |
1989 |
+ { |
1990 |
+ $this->SetError($this->Lang("execute") . $this->Sendmail); |
1991 |
+ return false; |
1992 |
+ } |
1993 |
+ |
1994 |
+ return true; |
1995 |
+ } |
1996 |
+ |
1997 |
+ /** |
1998 |
+ * Sends mail using the PHP mail() function. |
1999 |
+ * @access private |
2000 |
+ * @return bool |
2001 |
+ */ |
2002 |
+ function MailSend($header, $body) { |
2003 |
+ $to = ""; |
2004 |
+ for($i = 0; $i < count($this->to); $i++) |
2005 |
+ { |
2006 |
+ if($i != 0) { $to .= ", "; } |
2007 |
+ $to .= $this->to[$i][0]; |
2008 |
+ } |
2009 |
+ |
2010 |
+ if ($this->Sender != "" && strlen(ini_get("safe_mode"))< 1) |
2011 |
+ { |
2012 |
+ $old_from = ini_get("sendmail_from"); |
2013 |
+ ini_set("sendmail_from", $this->Sender); |
2014 |
+ $params = sprintf("-oi -f %s", $this->Sender); |
2015 |
+ $rt = @mail($to, $this->EncodeHeader($this->Subject), $body, |
2016 |
+ $header, $params); |
2017 |
+ } |
2018 |
+ else |
2019 |
+ $rt = @mail($to, $this->EncodeHeader($this->Subject), $body, $header); |
2020 |
+ |
2021 |
+ if (isset($old_from)) |
2022 |
+ ini_set("sendmail_from", $old_from); |
2023 |
+ |
2024 |
+ if(!$rt) |
2025 |
+ { |
2026 |
+ $this->SetError($this->Lang("instantiate")); |
2027 |
+ return false; |
2028 |
+ } |
2029 |
+ |
2030 |
+ return true; |
2031 |
+ } |
2032 |
+ |
2033 |
+ /** |
2034 |
+ * Sends mail via SMTP using PhpSMTP (Author: |
2035 |
+ * Chris Ryan). Returns bool. Returns false if there is a |
2036 |
+ * bad MAIL FROM, RCPT, or DATA input. |
2037 |
+ * @access private |
2038 |
+ * @return bool |
2039 |
+ */ |
2040 |
+ function SmtpSend($header, $body) { |
2041 |
+ include_once($this->PluginDir . "Smtp.class.php"); |
2042 |
+ $error = ""; |
2043 |
+ $bad_rcpt = array(); |
2044 |
+ |
2045 |
+ if(!$this->SmtpConnect()) |
2046 |
+ return false; |
2047 |
+ |
2048 |
+ $smtp_from = ($this->Sender == "") ? $this->From : $this->Sender; |
2049 |
+ if(!$this->smtp->Mail($smtp_from)) |
2050 |
+ { |
2051 |
+ $error = $this->Lang("from_failed") . $smtp_from; |
2052 |
+ $this->SetError($error); |
2053 |
+ $this->smtp->Reset(); |
2054 |
+ return false; |
2055 |
+ } |
2056 |
+ |
2057 |
+ // Attempt to send attach all recipients |
2058 |
+ for($i = 0; $i < count($this->to); $i++) |
2059 |
+ { |
2060 |
+ if(!$this->smtp->Recipient($this->to[$i][0])) |
2061 |
+ $bad_rcpt[] = $this->to[$i][0]; |
2062 |
+ } |
2063 |
+ for($i = 0; $i < count($this->cc); $i++) |
2064 |
+ { |
2065 |
+ if(!$this->smtp->Recipient($this->cc[$i][0])) |
2066 |
+ $bad_rcpt[] = $this->cc[$i][0]; |
2067 |
+ } |
2068 |
+ for($i = 0; $i < count($this->bcc); $i++) |
2069 |
+ { |
2070 |
+ if(!$this->smtp->Recipient($this->bcc[$i][0])) |
2071 |
+ $bad_rcpt[] = $this->bcc[$i][0]; |
2072 |
+ } |
2073 |
+ |
2074 |
+ if(count($bad_rcpt) > 0) // Create error message |
2075 |
+ { |
2076 |
+ for($i = 0; $i < count($bad_rcpt); $i++) |
2077 |
+ { |
2078 |
+ if($i != 0) { $error .= ", "; } |
2079 |
+ $error .= $bad_rcpt[$i]; |
2080 |
+ } |
2081 |
+ $error = $this->Lang("recipients_failed") . $error; |
2082 |
+ $this->SetError($error); |
2083 |
+ $this->smtp->Reset(); |
2084 |
+ return false; |
2085 |
+ } |
2086 |
+ |
2087 |
+ if(!$this->smtp->Data($header . $body)) |
2088 |
+ { |
2089 |
+ $this->SetError($this->Lang("data_not_accepted")); |
2090 |
+ $this->smtp->Reset(); |
2091 |
+ return false; |
2092 |
+ } |
2093 |
+ if($this->SMTPKeepAlive == true) |
2094 |
+ $this->smtp->Reset(); |
2095 |
+ else |
2096 |
+ $this->SmtpClose(); |
2097 |
+ |
2098 |
+ return true; |
2099 |
+ } |
2100 |
+ |
2101 |
+ /** |
2102 |
+ * Initiates a connection to an SMTP server. Returns false if the |
2103 |
+ * operation failed. |
2104 |
+ * @access private |
2105 |
+ * @return bool |
2106 |
+ */ |
2107 |
+ function SmtpConnect() { |
2108 |
+ if($this->smtp == NULL) { $this->smtp = new SMTP(); } |
2109 |
+ |
2110 |
+ $this->smtp->do_debug = $this->SMTPDebug; |
2111 |
+ $hosts = explode(";", $this->Host); |
2112 |
+ $index = 0; |
2113 |
+ $connection = ($this->smtp->Connected()); |
2114 |
+ |
2115 |
+ // Retry while there is no connection |
2116 |
+ while($index < count($hosts) && $connection == false) |
2117 |
+ { |
2118 |
+ if(strstr($hosts[$index], ":")) |
2119 |
+ list($host, $port) = explode(":", $hosts[$index]); |
2120 |
+ else |
2121 |
+ { |
2122 |
+ $host = $hosts[$index]; |
2123 |
+ $port = $this->Port; |
2124 |
+ } |
2125 |
+ |
2126 |
+ if($this->smtp->Connect($host, $port, $this->Timeout)) |
2127 |
+ { |
2128 |
+ if ($this->Helo != '') |
2129 |
+ $this->smtp->Hello($this->Helo); |
2130 |
+ else |
2131 |
+ $this->smtp->Hello($this->ServerHostname()); |
2132 |
+ |
2133 |
+ if($this->SMTPAuth) |
2134 |
+ { |
2135 |
+ if(!$this->smtp->Authenticate($this->Username, |
2136 |
+ $this->Password)) |
2137 |
+ { |
2138 |
+ $this->SetError($this->Lang("authenticate")); |
2139 |
+ $this->smtp->Reset(); |
2140 |
+ $connection = false; |
2141 |
+ } |
2142 |
+ } |
2143 |
+ $connection = true; |
2144 |
+ } |
2145 |
+ $index++; |
2146 |
+ } |
2147 |
+ if(!$connection) |
2148 |
+ $this->SetError($this->Lang("connect_host")); |
2149 |
+ |
2150 |
+ return $connection; |
2151 |
+ } |
2152 |
+ |
2153 |
+ /** |
2154 |
+ * Closes the active SMTP session if one exists. |
2155 |
+ * @return void |
2156 |
+ */ |
2157 |
+ function SmtpClose() { |
2158 |
+ if($this->smtp != NULL) |
2159 |
+ { |
2160 |
+ if($this->smtp->Connected()) |
2161 |
+ { |
2162 |
+ $this->smtp->Quit(); |
2163 |
+ $this->smtp->Close(); |
2164 |
+ } |
2165 |
+ } |
2166 |
+ } |
2167 |
+ |
2168 |
+ /** |
2169 |
+ * Sets the language for all class error messages. Always in English. |
2170 |
+ * @param none |
2171 |
+ * @access public |
2172 |
+ * @return bool |
2173 |
+ */ |
2174 |
+ function SetLanguage() { |
2175 |
+ /** |
2176 |
+ * Only printing errors in english |
2177 |
+ */ |
2178 |
+ $PHPMAILER_LANG = array(); |
2179 |
+ |
2180 |
+ $PHPMAILER_LANG["provide_address"] = 'You must provide at least one ' . |
2181 |
+ 'recipient email address.'; |
2182 |
+ $PHPMAILER_LANG["mailer_not_supported"] = ' mailer is not supported.'; |
2183 |
+ $PHPMAILER_LANG["execute"] = 'Could not execute: '; |
2184 |
+ $PHPMAILER_LANG["instantiate"] = 'Could not instantiate mail function.'; |
2185 |
+ $PHPMAILER_LANG["authenticate"] = 'SMTP Error: Could not authenticate.'; |
2186 |
+ $PHPMAILER_LANG["from_failed"] = 'The following From address failed: '; |
2187 |
+ $PHPMAILER_LANG["recipients_failed"] = 'SMTP Error: The following ' . |
2188 |
+ 'recipients failed: '; |
2189 |
+ $PHPMAILER_LANG["data_not_accepted"] = 'SMTP Error: Data not accepted.'; |
2190 |
+ $PHPMAILER_LANG["connect_host"] = 'SMTP Error: Could not connect to SMTP host.'; |
2191 |
+ $PHPMAILER_LANG["file_access"] = 'Could not access file: '; |
2192 |
+ $PHPMAILER_LANG["file_open"] = 'File Error: Could not open file: '; |
2193 |
+ $PHPMAILER_LANG["encoding"] = 'Unknown encoding: '; |
2194 |
+ |
2195 |
+ $this->language = $PHPMAILER_LANG; |
2196 |
+ |
2197 |
+ return true; |
2198 |
+ } |
2199 |
+ |
2200 |
+ ///////////////////////////////////////////////// |
2201 |
+ // MESSAGE CREATION METHODS |
2202 |
+ ///////////////////////////////////////////////// |
2203 |
+ |
2204 |
+ /** |
2205 |
+ * Creates recipient headers. |
2206 |
+ * @access private |
2207 |
+ * @return string |
2208 |
+ */ |
2209 |
+ function AddrAppend($type, $addr) { |
2210 |
+ $addr_str = $type . ": "; |
2211 |
+ $addr_str .= $this->AddrFormat($addr[0]); |
2212 |
+ if(count($addr) > 1) |
2213 |
+ { |
2214 |
+ for($i = 1; $i < count($addr); $i++) |
2215 |
+ $addr_str .= ", " . $this->AddrFormat($addr[$i]); |
2216 |
+ } |
2217 |
+ $addr_str .= $this->LE; |
2218 |
+ |
2219 |
+ return $addr_str; |
2220 |
+ } |
2221 |
+ |
2222 |
+ /** |
2223 |
+ * Formats an address correctly. |
2224 |
+ * @access private |
2225 |
+ * @return string |
2226 |
+ */ |
2227 |
+ function AddrFormat($addr) { |
2228 |
+ if(empty($addr[1])) |
2229 |
+ $formatted = $addr[0]; |
2230 |
+ else |
2231 |
+ { |
2232 |
+ $formatted = $this->EncodeHeader($addr[1], 'phrase') . " <" . |
2233 |
+ $addr[0] . ">"; |
2234 |
+ } |
2235 |
+ |
2236 |
+ return $formatted; |
2237 |
+ } |
2238 |
+ |
2239 |
+ /** |
2240 |
+ * Wraps message for use with mailers that do not |
2241 |
+ * automatically perform wrapping and for quoted-printable. |
2242 |
+ * Original written by philippe. |
2243 |
+ * @access private |
2244 |
+ * @return string |
2245 |
+ */ |
2246 |
+ function WrapText($message, $length, $qp_mode = false) { |
2247 |
+ $soft_break = ($qp_mode) ? sprintf(" =%s", $this->LE) : $this->LE; |
2248 |
+ |
2249 |
+ $message = $this->FixEOL($message); |
2250 |
+ if (substr($message, -1) == $this->LE) |
2251 |
+ $message = substr($message, 0, -1); |
2252 |
+ |
2253 |
+ $line = explode($this->LE, $message); |
2254 |
+ $message = ""; |
2255 |
+ for ($i=0 ;$i < count($line); $i++) |
2256 |
+ { |
2257 |
+ $line_part = explode(" ", $line[$i]); |
2258 |
+ $buf = ""; |
2259 |
+ for ($e = 0; $e<count($line_part); $e++) |
2260 |
+ { |
2261 |
+ $word = $line_part[$e]; |
2262 |
+ if ($qp_mode and (strlen($word) > $length)) |
2263 |
+ { |
2264 |
+ $space_left = $length - strlen($buf) - 1; |
2265 |
+ if ($e != 0) |
2266 |
+ { |
2267 |
+ if ($space_left > 20) |
2268 |
+ { |
2269 |
+ $len = $space_left; |
2270 |
+ if (substr($word, $len - 1, 1) == "=") |
2271 |
+ $len--; |
2272 |
+ elseif (substr($word, $len - 2, 1) == "=") |
2273 |
+ $len -= 2; |
2274 |
+ $part = substr($word, 0, $len); |
2275 |
+ $word = substr($word, $len); |
2276 |
+ $buf .= " " . $part; |
2277 |
+ $message .= $buf . sprintf("=%s", $this->LE); |
2278 |
+ } |
2279 |
+ else |
2280 |
+ { |
2281 |
+ $message .= $buf . $soft_break; |
2282 |
+ } |
2283 |
+ $buf = ""; |
2284 |
+ } |
2285 |
+ while (strlen($word) > 0) |
2286 |
+ { |
2287 |
+ $len = $length; |
2288 |
+ if (substr($word, $len - 1, 1) == "=") |
2289 |
+ $len--; |
2290 |
+ elseif (substr($word, $len - 2, 1) == "=") |
2291 |
+ $len -= 2; |
2292 |
+ $part = substr($word, 0, $len); |
2293 |
+ $word = substr($word, $len); |
2294 |
+ |
2295 |
+ if (strlen($word) > 0) |
2296 |
+ $message .= $part . sprintf("=%s", $this->LE); |
2297 |
+ else |
2298 |
+ $buf = $part; |
2299 |
+ } |
2300 |
+ } |
2301 |
+ else |
2302 |
+ { |
2303 |
+ $buf_o = $buf; |
2304 |
+ $buf .= ($e == 0) ? $word : (" " . $word); |
2305 |
+ |
2306 |
+ if (strlen($buf) > $length and $buf_o != "") |
2307 |
+ { |
2308 |
+ $message .= $buf_o . $soft_break; |
2309 |
+ $buf = $word; |
2310 |
+ } |
2311 |
+ } |
2312 |
+ } |
2313 |
+ $message .= $buf . $this->LE; |
2314 |
+ } |
2315 |
+ |
2316 |
+ return $message; |
2317 |
+ } |
2318 |
+ |
2319 |
+ /** |
2320 |
+ * Set the body wrapping. |
2321 |
+ * @access private |
2322 |
+ * @return void |
2323 |
+ */ |
2324 |
+ function SetWordWrap() { |
2325 |
+ if($this->WordWrap < 1) |
2326 |
+ return; |
2327 |
+ |
2328 |
+ switch($this->message_type) |
2329 |
+ { |
2330 |
+ case "alt": |
2331 |
+ // fall through |
2332 |
+ case "alt_attachment": |
2333 |
+ $this->AltBody = $this->WrapText($this->AltBody, $this->WordWrap); |
2334 |
+ break; |
2335 |
+ default: |
2336 |
+ $this->Body = $this->WrapText($this->Body, $this->WordWrap); |
2337 |
+ break; |
2338 |
+ } |
2339 |
+ } |
2340 |
+ |
2341 |
+ /** |
2342 |
+ * Assembles message header. |
2343 |
+ * @access private |
2344 |
+ * @return string |
2345 |
+ */ |
2346 |
+ function CreateHeader() { |
2347 |
+ $result = ""; |
2348 |
+ |
2349 |
+ // Set the boundaries |
2350 |
+ $uniq_id = md5(uniqid(time())); |
2351 |
+ $this->boundary[1] = "b1_" . $uniq_id; |
2352 |
+ $this->boundary[2] = "b2_" . $uniq_id; |
2353 |
+ |
2354 |
+ $result .= $this->HeaderLine("Date", $this->RFCDate()); |
2355 |
+ if($this->Sender == "") |
2356 |
+ $result .= $this->HeaderLine("Return-Path", trim($this->From)); |
2357 |
+ else |
2358 |
+ $result .= $this->HeaderLine("Return-Path", trim($this->Sender)); |
2359 |
+ |
2360 |
+ // To be created automatically by mail() |
2361 |
+ if($this->Mailer != "mail") |
2362 |
+ { |
2363 |
+ if(count($this->to) > 0) |
2364 |
+ $result .= $this->AddrAppend("To", $this->to); |
2365 |
+ else if (count($this->cc) == 0) |
2366 |
+ $result .= $this->HeaderLine("To", "undisclosed-recipients:;"); |
2367 |
+ if(count($this->cc) > 0) |
2368 |
+ $result .= $this->AddrAppend("Cc", $this->cc); |
2369 |
+ } |
2370 |
+ |
2371 |
+ $from = array(); |
2372 |
+ $from[0][0] = trim($this->From); |
2373 |
+ $from[0][1] = $this->FromName; |
2374 |
+ $result .= $this->AddrAppend("From", $from); |
2375 |
+ |
2376 |
+ // sendmail and mail() extract Bcc from the header before sending |
2377 |
+ if((($this->Mailer == "sendmail") || ($this->Mailer == "mail")) && (count($this->bcc) > 0)) |
2378 |
+ $result .= $this->AddrAppend("Bcc", $this->bcc); |
2379 |
+ |
2380 |
+ if(count($this->ReplyTo) > 0) |
2381 |
+ $result .= $this->AddrAppend("Reply-to", $this->ReplyTo); |
2382 |
+ |
2383 |
+ // mail() sets the subject itself |
2384 |
+ if($this->Mailer != "mail") |
2385 |
+ $result .= $this->HeaderLine("Subject", $this->EncodeHeader(trim($this->Subject))); |
2386 |
+ |
2387 |
+ $result .= sprintf("Message-ID: <%s@%s>%s", $uniq_id, $this->ServerHostname(), $this->LE); |
2388 |
+ $result .= $this->HeaderLine("X-Priority", $this->Priority); |
2389 |
+ $result .= $this->HeaderLine("X-Mailer", "PHPMailer [version " . $this->Version . "]"); |
2390 |
+ |
2391 |
+ if($this->ConfirmReadingTo != "") |
2392 |
+ { |
2393 |
+ $result .= $this->HeaderLine("Disposition-Notification-To", |
2394 |
+ "<" . trim($this->ConfirmReadingTo) . ">"); |
2395 |
+ } |
2396 |
+ |
2397 |
+ // Add custom headers |
2398 |
+ for($index = 0; $index < count($this->CustomHeader); $index++) |
2399 |
+ { |
2400 |
+ $result .= $this->HeaderLine(trim($this->CustomHeader[$index][0]), |
2401 |
+ $this->EncodeHeader(trim($this->CustomHeader[$index][1]))); |
2402 |
+ } |
2403 |
+ $result .= $this->HeaderLine("MIME-Version", "1.0"); |
2404 |
+ |
2405 |
+ switch($this->message_type) |
2406 |
+ { |
2407 |
+ case "plain": |
2408 |
+ $result .= $this->HeaderLine("Content-Transfer-Encoding", $this->Encoding); |
2409 |
+ $result .= sprintf("Content-Type: %s; charset=\"%s\"", |
2410 |
+ $this->ContentType, $this->CharSet); |
2411 |
+ break; |
2412 |
+ case "attachments": |
2413 |
+ // fall through |
2414 |
+ case "alt_attachments": |
2415 |
+ if($this->InlineImageExists()) |
2416 |
+ { |
2417 |
+ $result .= sprintf("Content-Type: %s;%s\ttype=\"text/html\";%s\tboundary=\"%s\"%s", |
2418 |
+ "multipart/related", $this->LE, $this->LE, |
2419 |
+ $this->boundary[1], $this->LE); |
2420 |
+ } |
2421 |
+ else |
2422 |
+ { |
2423 |
+ $result .= $this->HeaderLine("Content-Type", "multipart/mixed;"); |
2424 |
+ $result .= $this->TextLine("\tboundary=\"" . $this->boundary[1] . '"'); |
2425 |
+ } |
2426 |
+ break; |
2427 |
+ case "alt": |
2428 |
+ $result .= $this->HeaderLine("Content-Type", "multipart/alternative;"); |
2429 |
+ $result .= $this->TextLine("\tboundary=\"" . $this->boundary[1] . '"'); |
2430 |
+ break; |
2431 |
+ } |
2432 |
+ |
2433 |
+ if($this->Mailer != "mail") |
2434 |
+ $result .= $this->LE.$this->LE; |
2435 |
+ |
2436 |
+ return $result; |
2437 |
+ } |
2438 |
+ |
2439 |
+ /** |
2440 |
+ * Assembles the message body. Returns an empty string on failure. |
2441 |
+ * @access private |
2442 |
+ * @return string |
2443 |
+ */ |
2444 |
+ function CreateBody() { |
2445 |
+ $result = ""; |
2446 |
+ |
2447 |
+ $this->SetWordWrap(); |
2448 |
+ |
2449 |
+ switch($this->message_type) |
2450 |
+ { |
2451 |
+ case "alt": |
2452 |
+ $result .= $this->GetBoundary($this->boundary[1], "", |
2453 |
+ "text/plain", ""); |
2454 |
+ $result .= $this->EncodeString($this->AltBody, $this->Encoding); |
2455 |
+ $result .= $this->LE.$this->LE; |
2456 |
+ $result .= $this->GetBoundary($this->boundary[1], "", |
2457 |
+ "text/html", ""); |
2458 |
+ |
2459 |
+ $result .= $this->EncodeString($this->Body, $this->Encoding); |
2460 |
+ $result .= $this->LE.$this->LE; |
2461 |
+ |
2462 |
+ $result .= $this->EndBoundary($this->boundary[1]); |
2463 |
+ break; |
2464 |
+ case "plain": |
2465 |
+ $result .= $this->EncodeString($this->Body, $this->Encoding); |
2466 |
+ break; |
2467 |
+ case "attachments": |
2468 |
+ $result .= $this->GetBoundary($this->boundary[1], "", "", ""); |
2469 |
+ $result .= $this->EncodeString($this->Body, $this->Encoding); |
2470 |
+ $result .= $this->LE; |
2471 |
+ |
2472 |
+ $result .= $this->AttachAll(); |
2473 |
+ break; |
2474 |
+ case "alt_attachments": |
2475 |
+ $result .= sprintf("--%s%s", $this->boundary[1], $this->LE); |
2476 |
+ $result .= sprintf("Content-Type: %s;%s" . |
2477 |
+ "\tboundary=\"%s\"%s", |
2478 |
+ "multipart/alternative", $this->LE, |
2479 |
+ $this->boundary[2], $this->LE.$this->LE); |
2480 |
+ |
2481 |
+ // Create text body |
2482 |
+ $result .= $this->GetBoundary($this->boundary[2], "", |
2483 |
+ "text/plain", "") . $this->LE; |
2484 |
+ |
2485 |
+ $result .= $this->EncodeString($this->AltBody, $this->Encoding); |
2486 |
+ $result .= $this->LE.$this->LE; |
2487 |
+ |
2488 |
+ // Create the HTML body |
2489 |
+ $result .= $this->GetBoundary($this->boundary[2], "", |
2490 |
+ "text/html", "") . $this->LE; |
2491 |
+ |
2492 |
+ $result .= $this->EncodeString($this->Body, $this->Encoding); |
2493 |
+ $result .= $this->LE.$this->LE; |
2494 |
+ |
2495 |
+ $result .= $this->EndBoundary($this->boundary[2]); |
2496 |
+ |
2497 |
+ $result .= $this->AttachAll(); |
2498 |
+ break; |
2499 |
+ } |
2500 |
+ if($this->IsError()) |
2501 |
+ $result = ""; |
2502 |
+ |
2503 |
+ return $result; |
2504 |
+ } |
2505 |
+ |
2506 |
+ /** |
2507 |
+ * Returns the start of a message boundary. |
2508 |
+ * @access private |
2509 |
+ */ |
2510 |
+ function GetBoundary($boundary, $charSet, $contentType, $encoding) { |
2511 |
+ $result = ""; |
2512 |
+ if($charSet == "") { $charSet = $this->CharSet; } |
2513 |
+ if($contentType == "") { $contentType = $this->ContentType; } |
2514 |
+ if($encoding == "") { $encoding = $this->Encoding; } |
2515 |
+ |
2516 |
+ $result .= $this->TextLine("--" . $boundary); |
2517 |
+ $result .= sprintf("Content-Type: %s; charset = \"%s\"", |
2518 |
+ $contentType, $charSet); |
2519 |
+ $result .= $this->LE; |
2520 |
+ $result .= $this->HeaderLine("Content-Transfer-Encoding", $encoding); |
2521 |
+ $result .= $this->LE; |
2522 |
+ |
2523 |
+ return $result; |
2524 |
+ } |
2525 |
+ |
2526 |
+ /** |
2527 |
+ * Returns the end of a message boundary. |
2528 |
+ * @access private |
2529 |
+ */ |
2530 |
+ function EndBoundary($boundary) { |
2531 |
+ return $this->LE . "--" . $boundary . "--" . $this->LE; |
2532 |
+ } |
2533 |
+ |
2534 |
+ /** |
2535 |
+ * Sets the message type. |
2536 |
+ * @access private |
2537 |
+ * @return void |
2538 |
+ */ |
2539 |
+ function SetMessageType() { |
2540 |
+ if(count($this->attachment) < 1 && strlen($this->AltBody) < 1) |
2541 |
+ $this->message_type = "plain"; |
2542 |
+ else |
2543 |
+ { |
2544 |
+ if(count($this->attachment) > 0) |
2545 |
+ $this->message_type = "attachments"; |
2546 |
+ if(strlen($this->AltBody) > 0 && count($this->attachment) < 1) |
2547 |
+ $this->message_type = "alt"; |
2548 |
+ if(strlen($this->AltBody) > 0 && count($this->attachment) > 0) |
2549 |
+ $this->message_type = "alt_attachments"; |
2550 |
+ } |
2551 |
+ } |
2552 |
+ |
2553 |
+ /** |
2554 |
+ * Returns a formatted header line. |
2555 |
+ * @access private |
2556 |
+ * @return string |
2557 |
+ */ |
2558 |
+ function HeaderLine($name, $value) { |
2559 |
+ return $name . ": " . $value . $this->LE; |
2560 |
+ } |
2561 |
+ |
2562 |
+ /** |
2563 |
+ * Returns a formatted mail line. |
2564 |
+ * @access private |
2565 |
+ * @return string |
2566 |
+ */ |
2567 |
+ function TextLine($value) { |
2568 |
+ return $value . $this->LE; |
2569 |
+ } |
2570 |
+ |
2571 |
+ ///////////////////////////////////////////////// |
2572 |
+ // ATTACHMENT METHODS |
2573 |
+ ///////////////////////////////////////////////// |
2574 |
+ |
2575 |
+ /** |
2576 |
+ * Adds an attachment from a path on the filesystem. |
2577 |
+ * Returns false if the file could not be found |
2578 |
+ * or accessed. |
2579 |
+ * @param string $path Path to the attachment. |
2580 |
+ * @param string $name Overrides the attachment name. |
2581 |
+ * @param string $encoding File encoding (see $Encoding). |
2582 |
+ * @param string $type File extension (MIME) type. |
2583 |
+ * @return bool |
2584 |
+ */ |
2585 |
+ function AddAttachment($path, $name = "", $encoding = "base64", |
2586 |
+ $type = "application/octet-stream") { |
2587 |
+ if(!@is_file($path)) |
2588 |
+ { |
2589 |
+ $this->SetError($this->Lang("file_access") . $path); |
2590 |
+ return false; |
2591 |
+ } |
2592 |
+ |
2593 |
+ $filename = basename($path); |
2594 |
+ if($name == "") |
2595 |
+ $name = $filename; |
2596 |
+ |
2597 |
+ $cur = count($this->attachment); |
2598 |
+ $this->attachment[$cur][0] = $path; |
2599 |
+ $this->attachment[$cur][1] = $filename; |
2600 |
+ $this->attachment[$cur][2] = $name; |
2601 |
+ $this->attachment[$cur][3] = $encoding; |
2602 |
+ $this->attachment[$cur][4] = $type; |
2603 |
+ $this->attachment[$cur][5] = false; // isStringAttachment |
2604 |
+ $this->attachment[$cur][6] = "attachment"; |
2605 |
+ $this->attachment[$cur][7] = 0; |
2606 |
+ |
2607 |
+ return true; |
2608 |
+ } |
2609 |
+ |
2610 |
+ /** |
2611 |
+ * Attaches all fs, string, and binary attachments to the message. |
2612 |
+ * Returns an empty string on failure. |
2613 |
+ * @access private |
2614 |
+ * @return string |
2615 |
+ */ |
2616 |
+ function AttachAll() { |
2617 |
+ // Return text of body |
2618 |
+ $mime = array(); |
2619 |
+ |
2620 |
+ // Add all attachments |
2621 |
+ for($i = 0; $i < count($this->attachment); $i++) |
2622 |
+ { |
2623 |
+ // Check for string attachment |
2624 |
+ $bString = $this->attachment[$i][5]; |
2625 |
+ if ($bString) |
2626 |
+ $string = $this->attachment[$i][0]; |
2627 |
+ else |
2628 |
+ $path = $this->attachment[$i][0]; |
2629 |
+ |
2630 |
+ $filename = $this->attachment[$i][1]; |
2631 |
+ $name = $this->attachment[$i][2]; |
2632 |
+ $encoding = $this->attachment[$i][3]; |
2633 |
+ $type = $this->attachment[$i][4]; |
2634 |
+ $disposition = $this->attachment[$i][6]; |
2635 |
+ $cid = $this->attachment[$i][7]; |
2636 |
+ |
2637 |
+ $mime[] = sprintf("--%s%s", $this->boundary[1], $this->LE); |
2638 |
+ $mime[] = sprintf("Content-Type: %s; name=\"%s\"%s", $type, $name, $this->LE); |
2639 |
+ $mime[] = sprintf("Content-Transfer-Encoding: %s%s", $encoding, $this->LE); |
2640 |
+ |
2641 |
+ if($disposition == "inline") |
2642 |
+ $mime[] = sprintf("Content-ID: <%s>%s", $cid, $this->LE); |
2643 |
+ |
2644 |
+ $mime[] = sprintf("Content-Disposition: %s; filename=\"%s\"%s", |
2645 |
+ $disposition, $name, $this->LE.$this->LE); |
2646 |
+ |
2647 |
+ // Encode as string attachment |
2648 |
+ if($bString) |
2649 |
+ { |
2650 |
+ $mime[] = $this->EncodeString($string, $encoding); |
2651 |
+ if($this->IsError()) { return ""; } |
2652 |
+ $mime[] = $this->LE.$this->LE; |
2653 |
+ } |
2654 |
+ else |
2655 |
+ { |
2656 |
+ $mime[] = $this->EncodeFile($path, $encoding); |
2657 |
+ if($this->IsError()) { return ""; } |
2658 |
+ $mime[] = $this->LE.$this->LE; |
2659 |
+ } |
2660 |
+ } |
2661 |
+ |
2662 |
+ $mime[] = sprintf("--%s--%s", $this->boundary[1], $this->LE); |
2663 |
+ |
2664 |
+ return join("", $mime); |
2665 |
+ } |
2666 |
+ |
2667 |
+ /** |
2668 |
+ * Encodes attachment in requested format. Returns an |
2669 |
+ * empty string on failure. |
2670 |
+ * @access private |
2671 |
+ * @return string |
2672 |
+ */ |
2673 |
+ function EncodeFile ($path, $encoding = "base64") { |
2674 |
+ if(!@$fd = fopen($path, "rb")) |
2675 |
+ { |
2676 |
+ $this->SetError($this->Lang("file_open") . $path); |
2677 |
+ return ""; |
2678 |
+ } |
2679 |
+ $file_buffer = fread($fd, filesize($path)); |
2680 |
+ $file_buffer = $this->EncodeString($file_buffer, $encoding); |
2681 |
+ fclose($fd); |
2682 |
+ |
2683 |
+ return $file_buffer; |
2684 |
+ } |
2685 |
+ |
2686 |
+ /** |
2687 |
+ * Encodes string to requested format. Returns an |
2688 |
+ * empty string on failure. |
2689 |
+ * @access private |
2690 |
+ * @return string |
2691 |
+ */ |
2692 |
+ function EncodeString ($str, $encoding = "base64") { |
2693 |
+ $encoded = ""; |
2694 |
+ switch(strtolower($encoding)) { |
2695 |
+ case "base64": |
2696 |
+ // chunk_split is found in PHP >= 3.0.6 |
2697 |
+ $encoded = chunk_split(base64_encode($str), 76, $this->LE); |
2698 |
+ break; |
2699 |
+ case "7bit": |
2700 |
+ case "8bit": |
2701 |
+ $encoded = $this->FixEOL($str); |
2702 |
+ if (substr($encoded, -(strlen($this->LE))) != $this->LE) |
2703 |
+ $encoded .= $this->LE; |
2704 |
+ break; |
2705 |
+ case "binary": |
2706 |
+ $encoded = $str; |
2707 |
+ break; |
2708 |
+ case "quoted-printable": |
2709 |
+ $encoded = $this->EncodeQP($str); |
2710 |
+ break; |
2711 |
+ default: |
2712 |
+ $this->SetError($this->Lang("encoding") . $encoding); |
2713 |
+ break; |
2714 |
+ } |
2715 |
+ return $encoded; |
2716 |
+ } |
2717 |
+ |
2718 |
+ /** |
2719 |
+ * Encode a header string to best of Q, B, quoted or none. |
2720 |
+ * @access private |
2721 |
+ * @return string |
2722 |
+ */ |
2723 |
+ function EncodeHeader ($str, $position = 'text') { |
2724 |
+ $x = 0; |
2725 |
+ |
2726 |
+ switch (strtolower($position)) { |
2727 |
+ case 'phrase': |
2728 |
+ if (!preg_match('/[\200-\377]/', $str)) { |
2729 |
+ // Can't use addslashes as we don't know what value has magic_quotes_sybase. |
2730 |
+ $encoded = addcslashes($str, "\0..\37\177\\\""); |
2731 |
+ |
2732 |
+ if (($str == $encoded) && !preg_match('/[^A-Za-z0-9!#$%&\'*+\/=?^_`{|}~ -]/', $str)) |
2733 |
+ return ($encoded); |
2734 |
+ else |
2735 |
+ return ("\"$encoded\""); |
2736 |
+ } |
2737 |
+ $x = preg_match_all('/[^\040\041\043-\133\135-\176]/', $str, $matches); |
2738 |
+ break; |
2739 |
+ case 'comment': |
2740 |
+ $x = preg_match_all('/[()"]/', $str, $matches); |
2741 |
+ // Fall-through |
2742 |
+ case 'text': |
2743 |
+ default: |
2744 |
+ $x += preg_match_all('/[\000-\010\013\014\016-\037\177-\377]/', $str, $matches); |
2745 |
+ break; |
2746 |
+ } |
2747 |
+ |
2748 |
+ if ($x == 0) |
2749 |
+ return ($str); |
2750 |
+ |
2751 |
+ $maxlen = 75 - 7 - strlen($this->CharSet); |
2752 |
+ // Try to select the encoding which should produce the shortest output |
2753 |
+ if (strlen($str)/3 < $x) { |
2754 |
+ $encoding = 'B'; |
2755 |
+ $encoded = base64_encode($str); |
2756 |
+ $maxlen -= $maxlen % 4; |
2757 |
+ $encoded = trim(chunk_split($encoded, $maxlen, "\n")); |
2758 |
+ } else { |
2759 |
+ $encoding = 'Q'; |
2760 |
+ $encoded = $this->EncodeQ($str, $position); |
2761 |
+ $encoded = $this->WrapText($encoded, $maxlen, true); |
2762 |
+ $encoded = str_replace("=".$this->LE, "\n", trim($encoded)); |
2763 |
+ } |
2764 |
+ |
2765 |
+ $encoded = preg_replace('/^(.*)$/m', " =?".$this->CharSet."?$encoding?\\1?=", $encoded); |
2766 |
+ $encoded = trim(str_replace("\n", $this->LE, $encoded)); |
2767 |
+ |
2768 |
+ return $encoded; |
2769 |
+ } |
2770 |
+ |
2771 |
+ /** |
2772 |
+ * Encode string to quoted-printable. |
2773 |
+ * @access private |
2774 |
+ * @return string |
2775 |
+ */ |
2776 |
+ function EncodeQP ($str) { |
2777 |
+ $encoded = $this->FixEOL($str); |
2778 |
+ if (substr($encoded, -(strlen($this->LE))) != $this->LE) |
2779 |
+ $encoded .= $this->LE; |
2780 |
+ |
2781 |
+ // Replace every high ascii, control and = characters |
2782 |
+ $encoded = preg_replace('/([\000-\010\013\014\016-\037\075\177-\377])/e', |
2783 |
+ "'='.sprintf('%02X', ord('\\1'))", $encoded); |
2784 |
+ // Replace every spaces and tabs when it's the last character on a line |
2785 |
+ $encoded = preg_replace("/([\011\040])".$this->LE."/e", |
2786 |
+ "'='.sprintf('%02X', ord('\\1')).'".$this->LE."'", $encoded); |
2787 |
+ |
2788 |
+ // Maximum line length of 76 characters before CRLF (74 + space + '=') |
2789 |
+ $encoded = $this->WrapText($encoded, 74, true); |
2790 |
+ |
2791 |
+ return $encoded; |
2792 |
+ } |
2793 |
+ |
2794 |
+ /** |
2795 |
+ * Encode string to q encoding. |
2796 |
+ * @access private |
2797 |
+ * @return string |
2798 |
+ */ |
2799 |
+ function EncodeQ ($str, $position = "text") { |
2800 |
+ // There should not be any EOL in the string |
2801 |
+ $encoded = preg_replace("[\r\n]", "", $str); |
2802 |
+ |
2803 |
+ switch (strtolower($position)) { |
2804 |
+ case "phrase": |
2805 |
+ $encoded = preg_replace("/([^A-Za-z0-9!*+\/ -])/e", "'='.sprintf('%02X', ord('\\1'))", $encoded); |
2806 |
+ break; |
2807 |
+ case "comment": |
2808 |
+ $encoded = preg_replace("/([\(\)\"])/e", "'='.sprintf('%02X', ord('\\1'))", $encoded); |
2809 |
+ case "text": |
2810 |
+ default: |
2811 |
+ // Replace every high ascii, control =, ? and _ characters |
2812 |
+ $encoded = preg_replace('/([\000-\011\013\014\016-\037\075\077\137\177-\377])/e', |
2813 |
+ "'='.sprintf('%02X', ord('\\1'))", $encoded); |
2814 |
+ break; |
2815 |
+ } |
2816 |
+ |
2817 |
+ // Replace every spaces to _ (more readable than =20) |
2818 |
+ $encoded = str_replace(" ", "_", $encoded); |
2819 |
+ |
2820 |
+ return $encoded; |
2821 |
+ } |
2822 |
+ |
2823 |
+ /** |
2824 |
+ * Adds a string or binary attachment (non-filesystem) to the list. |
2825 |
+ * This method can be used to attach ascii or binary data, |
2826 |
+ * such as a BLOB record from a database. |
2827 |
+ * @param string $string String attachment data. |
2828 |
+ * @param string $filename Name of the attachment. |
2829 |
+ * @param string $encoding File encoding (see $Encoding). |
2830 |
+ * @param string $type File extension (MIME) type. |
2831 |
+ * @return void |
2832 |
+ */ |
2833 |
+ function AddStringAttachment($string, $filename, $encoding = "base64", |
2834 |
+ $type = "application/octet-stream") { |
2835 |
+ // Append to $attachment array |
2836 |
+ $cur = count($this->attachment); |
2837 |
+ $this->attachment[$cur][0] = $string; |
2838 |
+ $this->attachment[$cur][1] = $filename; |
2839 |
+ $this->attachment[$cur][2] = $filename; |
2840 |
+ $this->attachment[$cur][3] = $encoding; |
2841 |
+ $this->attachment[$cur][4] = $type; |
2842 |
+ $this->attachment[$cur][5] = true; // isString |
2843 |
+ $this->attachment[$cur][6] = "attachment"; |
2844 |
+ $this->attachment[$cur][7] = 0; |
2845 |
+ } |
2846 |
+ |
2847 |
+ /** |
2848 |
+ * Adds an embedded attachment. This can include images, sounds, and |
2849 |
+ * just about any other document. Make sure to set the $type to an |
2850 |
+ * image type. For JPEG images use "image/jpeg" and for GIF images |
2851 |
+ * use "image/gif". |
2852 |
+ * @param string $path Path to the attachment. |
2853 |
+ * @param string $cid Content ID of the attachment. Use this to identify |
2854 |
+ * the Id for accessing the image in an HTML form. |
2855 |
+ * @param string $name Overrides the attachment name. |
2856 |
+ * @param string $encoding File encoding (see $Encoding). |
2857 |
+ * @param string $type File extension (MIME) type. |
2858 |
+ * @return bool |
2859 |
+ */ |
2860 |
+ function AddEmbeddedImage($path, $cid, $name = "", $encoding = "base64", |
2861 |
+ $type = "application/octet-stream") { |
2862 |
+ |
2863 |
+ if(!@is_file($path)) |
2864 |
+ { |
2865 |
+ $this->SetError($this->Lang("file_access") . $path); |
2866 |
+ return false; |
2867 |
+ } |
2868 |
+ |
2869 |
+ $filename = basename($path); |
2870 |
+ if($name == "") |
2871 |
+ $name = $filename; |
2872 |
+ |
2873 |
+ // Append to $attachment array |
2874 |
+ $cur = count($this->attachment); |
2875 |
+ $this->attachment[$cur][0] = $path; |
2876 |
+ $this->attachment[$cur][1] = $filename; |
2877 |
+ $this->attachment[$cur][2] = $name; |
2878 |
+ $this->attachment[$cur][3] = $encoding; |
2879 |
+ $this->attachment[$cur][4] = $type; |
2880 |
+ $this->attachment[$cur][5] = false; // isStringAttachment |
2881 |
+ $this->attachment[$cur][6] = "inline"; |
2882 |
+ $this->attachment[$cur][7] = $cid; |
2883 |
+ |
2884 |
+ return true; |
2885 |
+ } |
2886 |
+ |
2887 |
+ /** |
2888 |
+ * Returns true if an inline attachment is present. |
2889 |
+ * @access private |
2890 |
+ * @return bool |
2891 |
+ */ |
2892 |
+ function InlineImageExists() { |
2893 |
+ $result = false; |
2894 |
+ for($i = 0; $i < count($this->attachment); $i++) |
2895 |
+ { |
2896 |
+ if($this->attachment[$i][6] == "inline") |
2897 |
+ { |
2898 |
+ $result = true; |
2899 |
+ break; |
2900 |
+ } |
2901 |
+ } |
2902 |
+ |
2903 |
+ return $result; |
2904 |
+ } |
2905 |
+ |
2906 |
+ ///////////////////////////////////////////////// |
2907 |
+ // MESSAGE RESET METHODS |
2908 |
+ ///////////////////////////////////////////////// |
2909 |
+ |
2910 |
+ /** |
2911 |
+ * Clears all recipients assigned in the TO array. Returns void. |
2912 |
+ * @return void |
2913 |
+ */ |
2914 |
+ function ClearAddresses() { |
2915 |
+ $this->to = array(); |
2916 |
+ } |
2917 |
+ |
2918 |
+ /** |
2919 |
+ * Clears all recipients assigned in the CC array. Returns void. |
2920 |
+ * @return void |
2921 |
+ */ |
2922 |
+ function ClearCCs() { |
2923 |
+ $this->cc = array(); |
2924 |
+ } |
2925 |
+ |
2926 |
+ /** |
2927 |
+ * Clears all recipients assigned in the BCC array. Returns void. |
2928 |
+ * @return void |
2929 |
+ */ |
2930 |
+ function ClearBCCs() { |
2931 |
+ $this->bcc = array(); |
2932 |
+ } |
2933 |
+ |
2934 |
+ /** |
2935 |
+ * Clears all recipients assigned in the ReplyTo array. Returns void. |
2936 |
+ * @return void |
2937 |
+ */ |
2938 |
+ function ClearReplyTos() { |
2939 |
+ $this->ReplyTo = array(); |
2940 |
+ } |
2941 |
+ |
2942 |
+ /** |
2943 |
+ * Clears all recipients assigned in the TO, CC and BCC |
2944 |
+ * array. Returns void. |
2945 |
+ * @return void |
2946 |
+ */ |
2947 |
+ function ClearAllRecipients() { |
2948 |
+ $this->to = array(); |
2949 |
+ $this->cc = array(); |
2950 |
+ $this->bcc = array(); |
2951 |
+ } |
2952 |
+ |
2953 |
+ /** |
2954 |
+ * Clears all previously set filesystem, string, and binary |
2955 |
+ * attachments. Returns void. |
2956 |
+ * @return void |
2957 |
+ */ |
2958 |
+ function ClearAttachments() { |
2959 |
+ $this->attachment = array(); |
2960 |
+ } |
2961 |
+ |
2962 |
+ /** |
2963 |
+ * Clears all custom headers. Returns void. |
2964 |
+ * @return void |
2965 |
+ */ |
2966 |
+ function ClearCustomHeaders() { |
2967 |
+ $this->CustomHeader = array(); |
2968 |
+ } |
2969 |
+ |
2970 |
+ |
2971 |
+ ///////////////////////////////////////////////// |
2972 |
+ // MISCELLANEOUS METHODS |
2973 |
+ ///////////////////////////////////////////////// |
2974 |
+ |
2975 |
+ /** |
2976 |
+ * Adds the error message to the error container. |
2977 |
+ * Returns void. |
2978 |
+ * @access private |
2979 |
+ * @return void |
2980 |
+ */ |
2981 |
+ function SetError($msg) { |
2982 |
+ $this->error_count++; |
2983 |
+ $this->ErrorInfo = $msg; |
2984 |
+ } |
2985 |
+ |
2986 |
+ /** |
2987 |
+ * Returns the proper RFC 822 formatted date. |
2988 |
+ * @access private |
2989 |
+ * @return string |
2990 |
+ */ |
2991 |
+ function RFCDate() { |
2992 |
+ $tz = date("Z"); |
2993 |
+ $tzs = ($tz < 0) ? "-" : "+"; |
2994 |
+ $tz = abs($tz); |
2995 |
+ $tz = ($tz/3600)*100 + ($tz%3600)/60; |
2996 |
+ $result = sprintf("%s %s%04d", date("D, j M Y H:i:s"), $tzs, $tz); |
2997 |
+ |
2998 |
+ return $result; |
2999 |
+ } |
3000 |
+ |
3001 |
+ /** |
3002 |
+ * Returns the appropriate server variable. Should work with both |
3003 |
+ * PHP 4.1.0+ as well as older versions. Returns an empty string |
3004 |
+ * if nothing is found. |
3005 |
+ * @access private |
3006 |
+ * @return mixed |
3007 |
+ */ |
3008 |
+ function ServerVar($varName) { |
3009 |
+ global $HTTP_SERVER_VARS; |
3010 |
+ global $HTTP_ENV_VARS; |
3011 |
+ |
3012 |
+ if(!isset($_SERVER)) |
3013 |
+ { |
3014 |
+ $_SERVER = $HTTP_SERVER_VARS; |
3015 |
+ if(!isset($_SERVER["REMOTE_ADDR"])) |
3016 |
+ $_SERVER = $HTTP_ENV_VARS; // must be Apache |
3017 |
+ } |
3018 |
+ |
3019 |
+ if(isset($_SERVER[$varName])) |
3020 |
+ return $_SERVER[$varName]; |
3021 |
+ else |
3022 |
+ return ""; |
3023 |
+ } |
3024 |
+ |
3025 |
+ /** |
3026 |
+ * Returns the server hostname or 'localhost.localdomain' if unknown. |
3027 |
+ * @access private |
3028 |
+ * @return string |
3029 |
+ */ |
3030 |
+ function ServerHostname() { |
3031 |
+ if ($this->Hostname != "") |
3032 |
+ $result = $this->Hostname; |
3033 |
+ elseif ($this->ServerVar('SERVER_NAME') != "") |
3034 |
+ $result = $this->ServerVar('SERVER_NAME'); |
3035 |
+ else |
3036 |
+ $result = "localhost.localdomain"; |
3037 |
+ |
3038 |
+ return $result; |
3039 |
+ } |
3040 |
+ |
3041 |
+ /** |
3042 |
+ * Returns a message in the appropriate language. |
3043 |
+ * @access private |
3044 |
+ * @return string |
3045 |
+ */ |
3046 |
+ function Lang($key) { |
3047 |
+ if(count($this->language) < 1) |
3048 |
+ $this->SetLanguage("en"); // set the default language |
3049 |
+ |
3050 |
+ if(isset($this->language[$key])) |
3051 |
+ return $this->language[$key]; |
3052 |
+ else |
3053 |
+ return "Language string failed to load: " . $key; |
3054 |
+ } |
3055 |
+ |
3056 |
+ /** |
3057 |
+ * Returns true if an error occurred. |
3058 |
+ * @return bool |
3059 |
+ */ |
3060 |
+ function IsError() { |
3061 |
+ return ($this->error_count > 0); |
3062 |
+ } |
3063 |
+ |
3064 |
+ /** |
3065 |
+ * Changes every end of line from CR or LF to CRLF. |
3066 |
+ * @access private |
3067 |
+ * @return string |
3068 |
+ */ |
3069 |
+ function FixEOL($str) { |
3070 |
+ $str = str_replace("\r\n", "\n", $str); |
3071 |
+ $str = str_replace("\r", "\n", $str); |
3072 |
+ $str = str_replace("\n", $this->LE, $str); |
3073 |
+ return $str; |
3074 |
+ } |
3075 |
+ |
3076 |
+ /** |
3077 |
+ * Adds a custom header. |
3078 |
+ * @return void |
3079 |
+ */ |
3080 |
+ function AddCustomHeader($custom_header) { |
3081 |
+ $this->CustomHeader[] = explode(":", $custom_header, 2); |
3082 |
+ } |
3083 |
+} |
3084 |
+ |
3085 |
+?> |