PageRenderTime 62ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/log_analyzer/class.phpmailer.php

https://github.com/michael-cannon/typo3-extensions
PHP | 1572 lines | 1108 code | 146 blank | 318 comment | 156 complexity | 229ea61f96854577b0aa0be7f0475e1d MD5 | raw file
Possible License(s): LGPL-2.1
  1. <?php
  2. /*~ class.phpmailer.php
  3. .---------------------------------------------------------------------------.
  4. | Software: PHPMailer - PHP email class |
  5. | Version: 2.0.0 rc1 |
  6. | Contact: via sourceforge.net support pages (also www.codeworxtech.com) |
  7. | Info: http://phpmailer.sourceforge.net |
  8. | Support: http://sourceforge.net/projects/phpmailer/ |
  9. | ------------------------------------------------------------------------- |
  10. | Author: Andy Prevost (project admininistrator) |
  11. | Author: Brent R. Matzelle (original founder) |
  12. | Copyright (c) 2004-2007, Andy Prevost. All Rights Reserved. |
  13. | Copyright (c) 2001-2003, Brent R. Matzelle |
  14. | ------------------------------------------------------------------------- |
  15. | License: Distributed under the Lesser General Public License (LGPL) |
  16. | http://www.gnu.org/copyleft/lesser.html |
  17. | This program is distributed in the hope that it will be useful - WITHOUT |
  18. | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
  19. | FITNESS FOR A PARTICULAR PURPOSE. |
  20. | ------------------------------------------------------------------------- |
  21. | We offer a number of paid services (www.codeworxtech.com): |
  22. | - Web Hosting on highly optimized fast and secure servers |
  23. | - Technology Consulting |
  24. | - Oursourcing (highly qualified programmers and graphic designers) |
  25. '---------------------------------------------------------------------------'
  26. /* Class for sending email using either sendmail, PHP mail(), or SMTP. */
  27. class PHPMailer {
  28. /* PUBLIC PROPERTIES */
  29. /* Email priority (1 = High, 3 = Normal, 5 = low).
  30. * @var int
  31. */
  32. var $Priority = 3;
  33. /* Sets the CharSet of the message.
  34. * @var string
  35. */
  36. var $CharSet = 'iso-8859-1';
  37. /* Sets the Content-type of the message.
  38. * @var string
  39. */
  40. var $ContentType = 'text/plain';
  41. /* Sets the Encoding of the message. Options for this are '8bit',
  42. * '7bit', 'binary', 'base64', and 'quoted-printable'.
  43. * @var string
  44. */
  45. var $Encoding = '8bit';
  46. /* Holds the most recent mailer error message.
  47. * @var string
  48. */
  49. var $ErrorInfo = '';
  50. /* Sets the From email address for the message.
  51. * @var string
  52. */
  53. var $From = 'root@localhost';
  54. /* Sets the From name of the message.
  55. * @var string
  56. */
  57. var $FromName = 'Root User';
  58. /* Sets the Sender email (Return-Path) of the message. If not empty,
  59. * will be sent via -f to sendmail or as 'MAIL FROM' in smtp mode.
  60. * @var string
  61. */
  62. var $Sender = '';
  63. /* Sets the Subject of the message.
  64. * @var string
  65. */
  66. var $Subject = '';
  67. /* Sets the Body of the message. This can be either an HTML or text body.
  68. * If HTML then run IsHTML(true).
  69. * @var string
  70. */
  71. var $Body = '';
  72. /* Sets the text-only body of the message. This automatically sets the
  73. * email to multipart/alternative. This body can be read by mail
  74. * clients that do not have HTML email capability such as mutt. Clients
  75. * that can read HTML will view the normal Body.
  76. * @var string
  77. */
  78. var $AltBody = '';
  79. /* Sets word wrapping on the body of the message to a given number of
  80. * characters.
  81. * @var int
  82. */
  83. var $WordWrap = 0;
  84. /* Method to send mail: ('mail', 'sendmail', or 'smtp').
  85. * @var string
  86. */
  87. var $Mailer = 'mail';
  88. /* Sets the path of the sendmail program.
  89. * @var string
  90. */
  91. var $Sendmail = '/usr/sbin/sendmail';
  92. /* Path to PHPMailer plugins. This is now only useful if the SMTP class
  93. * is in a different directory than the PHP include path.
  94. * @var string
  95. */
  96. var $PluginDir = '';
  97. /* Sets the email address that a reading confirmation will be sent.
  98. * @var string
  99. */
  100. var $ConfirmReadingTo = '';
  101. /* Sets the hostname to use in Message-Id and Received headers
  102. * and as default HELO string. If empty, the value returned
  103. * by SERVER_NAME is used or 'localhost.localdomain'.
  104. * @var string
  105. */
  106. var $Hostname = '';
  107. /* PROPERTIES FOR SMTP */
  108. /* Sets the SMTP hosts. All hosts must be separated by a
  109. * semicolon. You can also specify a different port
  110. * for each host by using this format: [hostname:port]
  111. * (e.g. 'smtp1.example.com:25;smtp2.example.com').
  112. * Hosts will be tried in order.
  113. * @var string
  114. */
  115. var $Host = 'localhost';
  116. /* Sets the default SMTP server port.
  117. * @var int
  118. */
  119. var $Port = 25;
  120. /* Sets the SMTP HELO of the message (Default is $Hostname).
  121. * @var string
  122. */
  123. var $Helo = '';
  124. /* Sets conection prefix
  125. * options are "", "ssl" or "tls"
  126. * @var string
  127. */
  128. var $SMTPSecure = "";
  129. /* Sets SMTP authentication. Utilizes the Username and Password variables.
  130. * @var bool
  131. */
  132. var $SMTPAuth = false;
  133. /* Sets SMTP username.
  134. * @var string
  135. */
  136. var $Username = '';
  137. /* Sets SMTP password.
  138. * @var string
  139. */
  140. var $Password = '';
  141. /* Sets the SMTP server timeout in seconds. This function will not
  142. * work with the win32 version.
  143. * @var int
  144. */
  145. var $Timeout = 10;
  146. /* Sets SMTP class debugging on or off.
  147. * @var bool
  148. */
  149. var $SMTPDebug = false;
  150. /* Prevents the SMTP connection from being closed after each mail
  151. * sending. If this is set to true then to close the connection
  152. * requires an explicit call to SmtpClose().
  153. * @var bool
  154. */
  155. var $SMTPKeepAlive = false;
  156. /* Provides the ability to have the TO field process individual
  157. * emails, instead of sending to entire TO addresses
  158. * @var bool
  159. */
  160. var $SingleTo = false;
  161. /* PRIVATE PROPERTIES */
  162. var $smtp = NULL;
  163. var $to = array();
  164. var $cc = array();
  165. var $bcc = array();
  166. var $ReplyTo = array();
  167. var $attachment = array();
  168. var $CustomHeader = array();
  169. var $message_type = '';
  170. var $boundary = array();
  171. var $language = array();
  172. var $error_count = 0;
  173. var $LE = "\n";
  174. var $Version = '2.0.0 rc1';
  175. /* CLASS METHODS, VARIABLES */
  176. /* Sets message type to HTML.
  177. * @param bool $bool
  178. * @return void
  179. */
  180. function IsHTML($bool) {
  181. if($bool == true) {
  182. $this->ContentType = 'text/html';
  183. } else {
  184. $this->ContentType = 'text/plain';
  185. }
  186. }
  187. /* Sets Mailer to send message using SMTP.
  188. * @return void
  189. */
  190. function IsSMTP() {
  191. $this->Mailer = 'smtp';
  192. }
  193. /* Sets Mailer to send message using PHP mail() function.
  194. * @return void
  195. */
  196. function IsMail() {
  197. $this->Mailer = 'mail';
  198. }
  199. /* Sets Mailer to send message using the $Sendmail program.
  200. * @return void
  201. */
  202. function IsSendmail() {
  203. $this->Mailer = 'sendmail';
  204. }
  205. /* Sets Mailer to send message using the qmail MTA.
  206. * @return void
  207. */
  208. function IsQmail() {
  209. $this->Sendmail = '/var/qmail/bin/sendmail';
  210. $this->Mailer = 'sendmail';
  211. }
  212. /* CLASS METHODS, RECIPIENTS */
  213. /* Adds a 'To' address.
  214. * @param string $address
  215. * @param string $name
  216. * @return void
  217. */
  218. function AddAddress($address, $name = '') {
  219. $cur = count($this->to);
  220. $this->to[$cur][0] = trim($address);
  221. $this->to[$cur][1] = $name;
  222. }
  223. /* Adds a 'Cc' address. Note: this function works
  224. * with the SMTP mailer on win32, not with the 'mail'
  225. * mailer.
  226. * @param string $address
  227. * @param string $name
  228. * @return void
  229. */
  230. function AddCC($address, $name = '') {
  231. $cur = count($this->cc);
  232. $this->cc[$cur][0] = trim($address);
  233. $this->cc[$cur][1] = $name;
  234. }
  235. /* Adds a 'Bcc' address. Note: this function works
  236. * with the SMTP mailer on win32, not with the 'mail'
  237. * mailer.
  238. * @param string $address
  239. * @param string $name
  240. * @return void
  241. */
  242. function AddBCC($address, $name = '') {
  243. $cur = count($this->bcc);
  244. $this->bcc[$cur][0] = trim($address);
  245. $this->bcc[$cur][1] = $name;
  246. }
  247. /* Adds a 'Reply-to' address.
  248. * @param string $address
  249. * @param string $name
  250. * @return void
  251. */
  252. function AddReplyTo($address, $name = '') {
  253. $cur = count($this->ReplyTo);
  254. $this->ReplyTo[$cur][0] = trim($address);
  255. $this->ReplyTo[$cur][1] = $name;
  256. }
  257. /* CLASS METHODS, MAIL SENDING */
  258. /* Creates message and assigns Mailer. If the message is
  259. * not sent successfully then it returns false. Use the ErrorInfo
  260. * variable to view description of the error.
  261. * @return bool
  262. */
  263. function Send() {
  264. $header = '';
  265. $body = '';
  266. $result = true;
  267. if((count($this->to) + count($this->cc) + count($this->bcc)) < 1) {
  268. $this->SetError($this->Lang('provide_address'));
  269. return false;
  270. }
  271. /* Set whether the message is multipart/alternative */
  272. if(!empty($this->AltBody)) {
  273. $this->ContentType = 'multipart/alternative';
  274. }
  275. $this->error_count = 0; // reset errors
  276. $this->SetMessageType();
  277. $header .= $this->CreateHeader();
  278. $body = $this->CreateBody();
  279. if($body == '') {
  280. return false;
  281. }
  282. /* Choose the mailer */
  283. switch($this->Mailer) {
  284. case 'sendmail':
  285. $result = $this->SendmailSend($header, $body);
  286. break;
  287. case 'smtp':
  288. $result = $this->SmtpSend($header, $body);
  289. break;
  290. case 'mail':
  291. $result = $this->MailSend($header, $body);
  292. break;
  293. default:
  294. $result = $this->MailSend($header, $body);
  295. break;
  296. //$this->SetError($this->Mailer . $this->Lang('mailer_not_supported'));
  297. //$result = false;
  298. //break;
  299. }
  300. return $result;
  301. }
  302. /* Sends mail using the $Sendmail program.
  303. * @access private
  304. * @return bool
  305. */
  306. function SendmailSend($header, $body) {
  307. if ($this->Sender != '') {
  308. $sendmail = sprintf("%s -oi -f %s -t", escapeshellcmd($this->Sendmail), escapeshellarg($this->Sender));
  309. } else {
  310. $sendmail = sprintf("%s -oi -t", escapeshellcmd($this->Sendmail));
  311. }
  312. if(!@$mail = popen($sendmail, 'w')) {
  313. $this->SetError($this->Lang('execute') . $this->Sendmail);
  314. return false;
  315. }
  316. fputs($mail, $header);
  317. fputs($mail, $body);
  318. $result = pclose($mail) >> 8 & 0xFF;
  319. if($result != 0) {
  320. $this->SetError($this->Lang('execute') . $this->Sendmail);
  321. return false;
  322. }
  323. return true;
  324. }
  325. /* Sends mail using the PHP mail() function.
  326. * @access private
  327. * @return bool
  328. */
  329. function MailSend($header, $body) {
  330. $to = '';
  331. for($i = 0; $i < count($this->to); $i++) {
  332. if($i != 0) { $to .= ', '; }
  333. $to .= $this->AddrFormat($this->to[$i]);
  334. }
  335. $toArr = split(',', $to);
  336. if ($this->Sender != '' && strlen(ini_get('safe_mode'))< 1) {
  337. $old_from = ini_get('sendmail_from');
  338. ini_set('sendmail_from', $this->Sender);
  339. $params = sprintf("-oi -f %s", $this->Sender);
  340. if ($this->SingleTo === true && count($toArr) > 1) {
  341. foreach ($toArr as $key => $val) {
  342. $rt = @mail($val, $this->EncodeHeader($this->SecureHeader($this->Subject)), $body, $header, $params);
  343. }
  344. } else {
  345. $rt = @mail($to, $this->EncodeHeader($this->SecureHeader($this->Subject)), $body, $header, $params);
  346. }
  347. } else {
  348. if ($this->SingleTo === true && count($toArr) > 1) {
  349. foreach ($toArr as $key => $val) {
  350. $rt = @mail($val, $this->EncodeHeader($this->SecureHeader($this->Subject)), $body, $header, $params);
  351. }
  352. } else {
  353. $rt = @mail($to, $this->EncodeHeader($this->SecureHeader($this->Subject)), $body, $header);
  354. }
  355. }
  356. if (isset($old_from)) {
  357. ini_set('sendmail_from', $old_from);
  358. }
  359. if(!$rt) {
  360. $this->SetError($this->Lang('instantiate'));
  361. return false;
  362. }
  363. return true;
  364. }
  365. /* Sends mail via SMTP using PhpSMTP (Author:
  366. * Chris Ryan). Returns bool. Returns false if there is a
  367. * bad MAIL FROM, RCPT, or DATA input.
  368. * @access private
  369. * @return bool
  370. */
  371. function SmtpSend($header, $body) {
  372. include_once($this->PluginDir . 'class.smtp.php');
  373. $error = '';
  374. $bad_rcpt = array();
  375. if(!$this->SmtpConnect()) {
  376. return false;
  377. }
  378. $smtp_from = ($this->Sender == '') ? $this->From : $this->Sender;
  379. if(!$this->smtp->Mail($smtp_from)) {
  380. $error = $this->Lang('from_failed') . $smtp_from;
  381. $this->SetError($error);
  382. $this->smtp->Reset();
  383. return false;
  384. }
  385. /* Attempt to send attach all recipients */
  386. for($i = 0; $i < count($this->to); $i++) {
  387. if(!$this->smtp->Recipient($this->to[$i][0])) {
  388. $bad_rcpt[] = $this->to[$i][0];
  389. }
  390. }
  391. for($i = 0; $i < count($this->cc); $i++) {
  392. if(!$this->smtp->Recipient($this->cc[$i][0])) {
  393. $bad_rcpt[] = $this->cc[$i][0];
  394. }
  395. }
  396. for($i = 0; $i < count($this->bcc); $i++) {
  397. if(!$this->smtp->Recipient($this->bcc[$i][0])) {
  398. $bad_rcpt[] = $this->bcc[$i][0];
  399. }
  400. }
  401. if(count($bad_rcpt) > 0) { // Create error message
  402. for($i = 0; $i < count($bad_rcpt); $i++) {
  403. if($i != 0) {
  404. $error .= ', ';
  405. }
  406. $error .= $bad_rcpt[$i];
  407. }
  408. $error = $this->Lang('recipients_failed') . $error;
  409. $this->SetError($error);
  410. $this->smtp->Reset();
  411. return false;
  412. }
  413. if(!$this->smtp->Data($header . $body)) {
  414. $this->SetError($this->Lang('data_not_accepted'));
  415. $this->smtp->Reset();
  416. return false;
  417. }
  418. if($this->SMTPKeepAlive == true) {
  419. $this->smtp->Reset();
  420. } else {
  421. $this->SmtpClose();
  422. }
  423. return true;
  424. }
  425. /* Initiates a connection to an SMTP server. Returns false if the
  426. * operation failed.
  427. * @access private
  428. * @return bool
  429. */
  430. function SmtpConnect() {
  431. if($this->smtp == NULL) {
  432. $this->smtp = new SMTP();
  433. }
  434. $this->smtp->do_debug = $this->SMTPDebug;
  435. $hosts = explode(';', $this->Host);
  436. $index = 0;
  437. $connection = ($this->smtp->Connected());
  438. /* Retry while there is no connection */
  439. while($index < count($hosts) && $connection == false) {
  440. $hostinfo = array();
  441. if(eregi('^(.+):([0-9]+)$', $hosts[$index], $hostinfo)) {
  442. $host = $hostinfo[1];
  443. $port = $hostinfo[2];
  444. } else {
  445. $host = $hosts[$index];
  446. $port = $this->Port;
  447. }
  448. if($this->smtp->Connect(((!empty($this->SMTPSecure))?$this->SMTPSecure.'://':'').$host, $port, $this->Timeout)) {
  449. if ($this->Helo != '') {
  450. $this->smtp->Hello($this->Helo);
  451. } else {
  452. $this->smtp->Hello($this->ServerHostname());
  453. }
  454. if($this->SMTPAuth) {
  455. if(!$this->smtp->Authenticate($this->Username, $this->Password)) {
  456. $this->SetError($this->Lang('authenticate'));
  457. $this->smtp->Reset();
  458. $connection = false;
  459. }
  460. }
  461. $connection = true;
  462. }
  463. $index++;
  464. }
  465. if(!$connection) {
  466. $this->SetError($this->Lang('connect_host'));
  467. }
  468. return $connection;
  469. }
  470. /* Closes the active SMTP session if one exists.
  471. * @return void
  472. */
  473. function SmtpClose() {
  474. if($this->smtp != NULL) {
  475. if($this->smtp->Connected()) {
  476. $this->smtp->Quit();
  477. $this->smtp->Close();
  478. }
  479. }
  480. }
  481. /* Sets the language for all class error messages. Returns false
  482. * if it cannot load the language file. The default language type
  483. * is English.
  484. * @param string $lang_type Type of language (e.g. Portuguese: 'br')
  485. * @param string $lang_path Path to the language file directory
  486. * @access public
  487. * @return bool
  488. */
  489. function SetLanguage($lang_type, $lang_path = 'language/') {
  490. if(file_exists($lang_path.'phpmailer.lang-'.$lang_type.'.php')) {
  491. include($lang_path.'phpmailer.lang-'.$lang_type.'.php');
  492. } elseif (file_exists($lang_path.'phpmailer.lang-en.php')) {
  493. include($lang_path.'phpmailer.lang-en.php');
  494. } else {
  495. $this->SetError('Could not load language file');
  496. return false;
  497. }
  498. $this->language = $PHPMAILER_LANG;
  499. return true;
  500. }
  501. /*CLASS METHODS, MESSAGE CREATION */
  502. /* Creates recipient headers.
  503. * @access private
  504. * @return string
  505. */
  506. function AddrAppend($type, $addr) {
  507. $addr_str = $type . ': ';
  508. $addr_str .= $this->AddrFormat($addr[0]);
  509. if(count($addr) > 1) {
  510. for($i = 1; $i < count($addr); $i++) {
  511. $addr_str .= ', ' . $this->AddrFormat($addr[$i]);
  512. }
  513. }
  514. $addr_str .= $this->LE;
  515. return $addr_str;
  516. }
  517. /* Formats an address correctly.
  518. * @access private
  519. * @return string
  520. */
  521. function AddrFormat($addr) {
  522. if(empty($addr[1])) {
  523. $formatted = $this->SecureHeader($addr[0]);
  524. } else {
  525. $formatted = $this->EncodeHeader($this->SecureHeader($addr[1]), 'phrase') . " <" . $this->SecureHeader($addr[0]) . ">";
  526. }
  527. return $formatted;
  528. }
  529. /* Wraps message for use with mailers that do not
  530. * automatically perform wrapping and for quoted-printable.
  531. * Original written by philippe.
  532. * @access private
  533. * @return string
  534. */
  535. function WrapText($message, $length, $qp_mode = false) {
  536. $soft_break = ($qp_mode) ? sprintf(" =%s", $this->LE) : $this->LE;
  537. $message = $this->FixEOL($message);
  538. if (substr($message, -1) == $this->LE) {
  539. $message = substr($message, 0, -1);
  540. }
  541. $line = explode($this->LE, $message);
  542. $message = '';
  543. for ($i=0 ;$i < count($line); $i++) {
  544. $line_part = explode(' ', $line[$i]);
  545. $buf = '';
  546. for ($e = 0; $e<count($line_part); $e++) {
  547. $word = $line_part[$e];
  548. if ($qp_mode and (strlen($word) > $length)) {
  549. $space_left = $length - strlen($buf) - 1;
  550. if ($e != 0) {
  551. if ($space_left > 20) {
  552. $len = $space_left;
  553. if (substr($word, $len - 1, 1) == '=') {
  554. $len--;
  555. } elseif (substr($word, $len - 2, 1) == '=') {
  556. $len -= 2;
  557. }
  558. $part = substr($word, 0, $len);
  559. $word = substr($word, $len);
  560. $buf .= ' ' . $part;
  561. $message .= $buf . sprintf("=%s", $this->LE);
  562. } else {
  563. $message .= $buf . $soft_break;
  564. }
  565. $buf = '';
  566. }
  567. while (strlen($word) > 0) {
  568. $len = $length;
  569. if (substr($word, $len - 1, 1) == '=') {
  570. $len--;
  571. } elseif (substr($word, $len - 2, 1) == '=') {
  572. $len -= 2;
  573. }
  574. $part = substr($word, 0, $len);
  575. $word = substr($word, $len);
  576. if (strlen($word) > 0) {
  577. $message .= $part . sprintf("=%s", $this->LE);
  578. } else {
  579. $buf = $part;
  580. }
  581. }
  582. } else {
  583. $buf_o = $buf;
  584. $buf .= ($e == 0) ? $word : (' ' . $word);
  585. if (strlen($buf) > $length and $buf_o != '') {
  586. $message .= $buf_o . $soft_break;
  587. $buf = $word;
  588. }
  589. }
  590. }
  591. $message .= $buf . $this->LE;
  592. }
  593. return $message;
  594. }
  595. /* Set the body wrapping.
  596. * @access private
  597. * @return void
  598. */
  599. function SetWordWrap() {
  600. if($this->WordWrap < 1) {
  601. return;
  602. }
  603. switch($this->message_type) {
  604. case 'alt':
  605. /* fall through */
  606. case 'alt_attachments':
  607. $this->AltBody = $this->WrapText($this->AltBody, $this->WordWrap);
  608. break;
  609. default:
  610. $this->Body = $this->WrapText($this->Body, $this->WordWrap);
  611. break;
  612. }
  613. }
  614. /* Assembles message header.
  615. * @access private
  616. * @return string
  617. */
  618. function CreateHeader() {
  619. $result = '';
  620. /* Set the boundaries */
  621. $uniq_id = md5(uniqid(time()));
  622. $this->boundary[1] = 'b1_' . $uniq_id;
  623. $this->boundary[2] = 'b2_' . $uniq_id;
  624. $result .= $this->HeaderLine('Date', $this->RFCDate());
  625. if($this->Sender == '') {
  626. $result .= $this->HeaderLine('Return-Path', trim($this->From));
  627. } else {
  628. $result .= $this->HeaderLine('Return-Path', trim($this->Sender));
  629. }
  630. /* To be created automatically by mail() */
  631. if($this->Mailer != 'mail') {
  632. if(count($this->to) > 0) {
  633. $result .= $this->AddrAppend('To', $this->to);
  634. } elseif (count($this->cc) == 0) {
  635. $result .= $this->HeaderLine('To', 'undisclosed-recipients:;');
  636. }
  637. if(count($this->cc) > 0) {
  638. $result .= $this->AddrAppend('Cc', $this->cc);
  639. }
  640. }
  641. $from = array();
  642. $from[0][0] = trim($this->From);
  643. $from[0][1] = $this->FromName;
  644. $result .= $this->AddrAppend('From', $from);
  645. /* sendmail and mail() extract Bcc from the header before sending */
  646. if((($this->Mailer == 'sendmail') || ($this->Mailer == 'mail')) && (count($this->bcc) > 0)) {
  647. $result .= $this->AddrAppend('Bcc', $this->bcc);
  648. }
  649. if(count($this->ReplyTo) > 0) {
  650. $result .= $this->AddrAppend('Reply-to', $this->ReplyTo);
  651. }
  652. /* mail() sets the subject itself */
  653. if($this->Mailer != 'mail') {
  654. $result .= $this->HeaderLine('Subject', $this->EncodeHeader($this->SecureHeader($this->Subject)));
  655. }
  656. $result .= sprintf("Message-ID: <%s@%s>%s", $uniq_id, $this->ServerHostname(), $this->LE);
  657. $result .= $this->HeaderLine('X-Priority', $this->Priority);
  658. $result .= $this->HeaderLine('X-Mailer', 'PHPMailer (phpmailer.sourceforge.net) [version ' . $this->Version . ']');
  659. if($this->ConfirmReadingTo != '') {
  660. $result .= $this->HeaderLine('Disposition-Notification-To', '<' . trim($this->ConfirmReadingTo) . '>');
  661. }
  662. // Add custom headers
  663. for($index = 0; $index < count($this->CustomHeader); $index++) {
  664. $result .= $this->HeaderLine(trim($this->CustomHeader[$index][0]), $this->EncodeHeader(trim($this->CustomHeader[$index][1])));
  665. }
  666. $result .= $this->HeaderLine('MIME-Version', '1.0');
  667. switch($this->message_type) {
  668. case 'plain':
  669. $result .= $this->HeaderLine('Content-Transfer-Encoding', $this->Encoding);
  670. $result .= sprintf("Content-Type: %s; charset=\"%s\"", $this->ContentType, $this->CharSet);
  671. break;
  672. case 'attachments':
  673. /* fall through */
  674. case 'alt_attachments':
  675. if($this->InlineImageExists()){
  676. $result .= sprintf("Content-Type: %s;%s\ttype=\"text/html\";%s\tboundary=\"%s\"%s", 'multipart/related', $this->LE, $this->LE, $this->boundary[1], $this->LE);
  677. } else {
  678. $result .= $this->HeaderLine('Content-Type', 'multipart/mixed;');
  679. $result .= $this->TextLine("\tboundary=\"" . $this->boundary[1] . '"');
  680. }
  681. break;
  682. case 'alt':
  683. $result .= $this->HeaderLine('Content-Type', 'multipart/alternative;');
  684. $result .= $this->TextLine("\tboundary=\"" . $this->boundary[1] . '"');
  685. break;
  686. }
  687. if($this->Mailer != 'mail') {
  688. $result .= $this->LE.$this->LE;
  689. }
  690. return $result;
  691. }
  692. /* Assembles the message body. Returns an empty string on failure.
  693. * @access private
  694. * @return string
  695. */
  696. function CreateBody() {
  697. $result = '';
  698. $this->SetWordWrap();
  699. switch($this->message_type) {
  700. case 'alt':
  701. $result .= $this->GetBoundary($this->boundary[1], '', 'text/plain', '');
  702. $result .= $this->EncodeString($this->AltBody, $this->Encoding);
  703. $result .= $this->LE.$this->LE;
  704. $result .= $this->GetBoundary($this->boundary[1], '', 'text/html', '');
  705. $result .= $this->EncodeString($this->Body, $this->Encoding);
  706. $result .= $this->LE.$this->LE;
  707. $result .= $this->EndBoundary($this->boundary[1]);
  708. break;
  709. case 'plain':
  710. $result .= $this->EncodeString($this->Body, $this->Encoding);
  711. break;
  712. case 'attachments':
  713. $result .= $this->GetBoundary($this->boundary[1], '', '', '');
  714. $result .= $this->EncodeString($this->Body, $this->Encoding);
  715. $result .= $this->LE;
  716. $result .= $this->AttachAll();
  717. break;
  718. case 'alt_attachments':
  719. $result .= sprintf("--%s%s", $this->boundary[1], $this->LE);
  720. $result .= sprintf("Content-Type: %s;%s" . "\tboundary=\"%s\"%s", 'multipart/alternative', $this->LE, $this->boundary[2], $this->LE.$this->LE);
  721. $result .= $this->GetBoundary($this->boundary[2], '', 'text/plain', '') . $this->LE; // Create text body
  722. $result .= $this->EncodeString($this->AltBody, $this->Encoding);
  723. $result .= $this->LE.$this->LE;
  724. $result .= $this->GetBoundary($this->boundary[2], '', 'text/html', '') . $this->LE; // Create the HTML body
  725. $result .= $this->EncodeString($this->Body, $this->Encoding);
  726. $result .= $this->LE.$this->LE;
  727. $result .= $this->EndBoundary($this->boundary[2]);
  728. $result .= $this->AttachAll();
  729. break;
  730. }
  731. if($this->IsError()) {
  732. $result = '';
  733. }
  734. return $result;
  735. }
  736. /* Returns the start of a message boundary.
  737. * @access private
  738. */
  739. function GetBoundary($boundary, $charSet, $contentType, $encoding) {
  740. $result = '';
  741. if($charSet == '') {
  742. $charSet = $this->CharSet;
  743. }
  744. if($contentType == '') {
  745. $contentType = $this->ContentType;
  746. }
  747. if($encoding == '') {
  748. $encoding = $this->Encoding;
  749. }
  750. $result .= $this->TextLine('--' . $boundary);
  751. $result .= sprintf("Content-Type: %s; charset = \"%s\"", $contentType, $charSet);
  752. $result .= $this->LE;
  753. $result .= $this->HeaderLine('Content-Transfer-Encoding', $encoding);
  754. $result .= $this->LE;
  755. return $result;
  756. }
  757. /* Returns the end of a message boundary.
  758. * @access private
  759. */
  760. function EndBoundary($boundary) {
  761. return $this->LE . '--' . $boundary . '--' . $this->LE;
  762. }
  763. /* Sets the message type.
  764. * @access private
  765. * @return void
  766. */
  767. function SetMessageType() {
  768. if(count($this->attachment) < 1 && strlen($this->AltBody) < 1) {
  769. $this->message_type = 'plain';
  770. } else {
  771. if(count($this->attachment) > 0) {
  772. $this->message_type = 'attachments';
  773. }
  774. if(strlen($this->AltBody) > 0 && count($this->attachment) < 1) {
  775. $this->message_type = 'alt';
  776. }
  777. if(strlen($this->AltBody) > 0 && count($this->attachment) > 0) {
  778. $this->message_type = 'alt_attachments';
  779. }
  780. }
  781. }
  782. /* Returns a formatted header line.
  783. * @access private
  784. * @return string
  785. */
  786. function HeaderLine($name, $value) {
  787. return $name . ': ' . $value . $this->LE;
  788. }
  789. /* Returns a formatted mail line.
  790. * @access private
  791. * @return string
  792. */
  793. function TextLine($value) {
  794. return $value . $this->LE;
  795. }
  796. /* CLASS METHODS, ATTACHMENTS */
  797. /* Adds an attachment from a path on the filesystem.
  798. * Returns false if the file could not be found
  799. * or accessed.
  800. * @param string $path Path to the attachment.
  801. * @param string $name Overrides the attachment name.
  802. * @param string $encoding File encoding (see $Encoding).
  803. * @param string $type File extension (MIME) type.
  804. * @return bool
  805. */
  806. function AddAttachment($path, $name = '', $encoding = 'base64', $type = 'application/octet-stream') {
  807. if(!@is_file($path)) {
  808. $this->SetError($this->Lang('file_access') . $path);
  809. return false;
  810. }
  811. $filename = basename($path);
  812. if($name == '') {
  813. $name = $filename;
  814. }
  815. $cur = count($this->attachment);
  816. $this->attachment[$cur][0] = $path;
  817. $this->attachment[$cur][1] = $filename;
  818. $this->attachment[$cur][2] = $name;
  819. $this->attachment[$cur][3] = $encoding;
  820. $this->attachment[$cur][4] = $type;
  821. $this->attachment[$cur][5] = false; // isStringAttachment
  822. $this->attachment[$cur][6] = 'attachment';
  823. $this->attachment[$cur][7] = 0;
  824. return true;
  825. }
  826. /* Attaches all fs, string, and binary attachments to the message.
  827. * Returns an empty string on failure.
  828. * @access private
  829. * @return string
  830. */
  831. function AttachAll() {
  832. /* Return text of body */
  833. $mime = array();
  834. /* Add all attachments */
  835. for($i = 0; $i < count($this->attachment); $i++) {
  836. /* Check for string attachment */
  837. $bString = $this->attachment[$i][5];
  838. if ($bString) {
  839. $string = $this->attachment[$i][0];
  840. } else {
  841. $path = $this->attachment[$i][0];
  842. }
  843. $filename = $this->attachment[$i][1];
  844. $name = $this->attachment[$i][2];
  845. $encoding = $this->attachment[$i][3];
  846. $type = $this->attachment[$i][4];
  847. $disposition = $this->attachment[$i][6];
  848. $cid = $this->attachment[$i][7];
  849. $mime[] = sprintf("--%s%s", $this->boundary[1], $this->LE);
  850. $mime[] = sprintf("Content-Type: %s; name=\"%s\"%s", $type, $name, $this->LE);
  851. $mime[] = sprintf("Content-Transfer-Encoding: %s%s", $encoding, $this->LE);
  852. if($disposition == 'inline') {
  853. $mime[] = sprintf("Content-ID: <%s>%s", $cid, $this->LE);
  854. }
  855. $mime[] = sprintf("Content-Disposition: %s; filename=\"%s\"%s", $disposition, $name, $this->LE.$this->LE);
  856. /* Encode as string attachment */
  857. if($bString) {
  858. $mime[] = $this->EncodeString($string, $encoding);
  859. if($this->IsError()) {
  860. return '';
  861. }
  862. $mime[] = $this->LE.$this->LE;
  863. } else {
  864. $mime[] = $this->EncodeFile($path, $encoding);
  865. if($this->IsError()) {
  866. return '';
  867. }
  868. $mime[] = $this->LE.$this->LE;
  869. }
  870. }
  871. $mime[] = sprintf("--%s--%s", $this->boundary[1], $this->LE);
  872. return join('', $mime);
  873. }
  874. /* Encodes attachment in requested format. Returns an
  875. * empty string on failure.
  876. * @access private
  877. * @return string
  878. */
  879. function EncodeFile ($path, $encoding = 'base64') {
  880. if(!@$fd = fopen($path, 'rb')) {
  881. $this->SetError($this->Lang('file_open') . $path);
  882. return '';
  883. }
  884. $magic_quotes = get_magic_quotes_runtime();
  885. set_magic_quotes_runtime(0);
  886. $file_buffer = fread($fd, filesize($path));
  887. $file_buffer = $this->EncodeString($file_buffer, $encoding);
  888. fclose($fd);
  889. set_magic_quotes_runtime($magic_quotes);
  890. return $file_buffer;
  891. }
  892. /* Encodes string to requested format. Returns an
  893. * empty string on failure.
  894. * @access private
  895. * @return string
  896. */
  897. function EncodeString ($str, $encoding = 'base64') {
  898. $encoded = '';
  899. switch(strtolower($encoding)) {
  900. case 'base64':
  901. /* chunk_split is found in PHP >= 3.0.6 */
  902. $encoded = chunk_split(base64_encode($str), 76, $this->LE);
  903. break;
  904. case '7bit':
  905. case '8bit':
  906. $encoded = $this->FixEOL($str);
  907. if (substr($encoded, -(strlen($this->LE))) != $this->LE)
  908. $encoded .= $this->LE;
  909. break;
  910. case 'binary':
  911. $encoded = $str;
  912. break;
  913. case 'quoted-printable':
  914. $encoded = $this->EncodeQP($str);
  915. break;
  916. default:
  917. $this->SetError($this->Lang('encoding') . $encoding);
  918. break;
  919. }
  920. return $encoded;
  921. }
  922. /* Encode a header string to best of Q, B, quoted or none.
  923. * @access private
  924. * @return string
  925. */
  926. function EncodeHeader ($str, $position = 'text') {
  927. $x = 0;
  928. switch (strtolower($position)) {
  929. case 'phrase':
  930. if (!preg_match('/[\200-\377]/', $str)) {
  931. /* Can't use addslashes as we don't know what value has magic_quotes_sybase. */
  932. $encoded = addcslashes($str, "\0..\37\177\\\"");
  933. if (($str == $encoded) && !preg_match('/[^A-Za-z0-9!#$%&\'*+\/=?^_`{|}~ -]/', $str)) {
  934. return ($encoded);
  935. } else {
  936. return ("\"$encoded\"");
  937. }
  938. }
  939. $x = preg_match_all('/[^\040\041\043-\133\135-\176]/', $str, $matches);
  940. break;
  941. case 'comment':
  942. $x = preg_match_all('/[()"]/', $str, $matches);
  943. /* Fall-through */
  944. case 'text':
  945. default:
  946. $x += preg_match_all('/[\000-\010\013\014\016-\037\177-\377]/', $str, $matches);
  947. break;
  948. }
  949. if ($x == 0) {
  950. return ($str);
  951. }
  952. $maxlen = 75 - 7 - strlen($this->CharSet);
  953. /* Try to select the encoding which should produce the shortest output */
  954. if (strlen($str)/3 < $x) {
  955. $encoding = 'B';
  956. $encoded = base64_encode($str);
  957. $maxlen -= $maxlen % 4;
  958. $encoded = trim(chunk_split($encoded, $maxlen, "\n"));
  959. } else {
  960. $encoding = 'Q';
  961. $encoded = $this->EncodeQ($str, $position);
  962. $encoded = $this->WrapText($encoded, $maxlen, true);
  963. $encoded = str_replace('='.$this->LE, "\n", trim($encoded));
  964. }
  965. $encoded = preg_replace('/^(.*)$/m', " =?".$this->CharSet."?$encoding?\\1?=", $encoded);
  966. $encoded = trim(str_replace("\n", $this->LE, $encoded));
  967. return $encoded;
  968. }
  969. /* Encode string to quoted-printable.
  970. * @access private
  971. * @return string
  972. */
  973. function EncodeQP ($str) {
  974. $encoded = $this->FixEOL($str);
  975. if (substr($encoded, -(strlen($this->LE))) != $this->LE) {
  976. $encoded .= $this->LE;
  977. }
  978. /* Replace every high ascii, control and = characters */
  979. $encoded = preg_replace('/([\000-\010\013\014\016-\037\075\177-\377])/e', "'='.sprintf('%02X', ord('\\1'))", $encoded);
  980. /* Replace every spaces and tabs when it's the last character on a line */
  981. $encoded = preg_replace("/([\011\040])".$this->LE."/e", "'='.sprintf('%02X', ord('\\1')).'".$this->LE."'", $encoded);
  982. /* Maximum line length of 76 characters before CRLF (74 + space + '=') */
  983. $encoded = $this->WrapText($encoded, 74, true);
  984. return $encoded;
  985. }
  986. /*Encode string to q encoding.
  987. * @access private
  988. * @return string
  989. */
  990. function EncodeQ ($str, $position = 'text') {
  991. /* There should not be any EOL in the string */
  992. $encoded = preg_replace("[\r\n]", '', $str);
  993. switch (strtolower($position)) {
  994. case 'phrase':
  995. $encoded = preg_replace("/([^A-Za-z0-9!*+\/ -])/e", "'='.sprintf('%02X', ord('\\1'))", $encoded);
  996. break;
  997. case 'comment':
  998. $encoded = preg_replace("/([\(\)\"])/e", "'='.sprintf('%02X', ord('\\1'))", $encoded);
  999. case 'text':
  1000. default:
  1001. /* Replace every high ascii, control =, ? and _ characters */
  1002. $encoded = preg_replace('/([\000-\011\013\014\016-\037\075\077\137\177-\377])/e',
  1003. "'='.sprintf('%02X', ord('\\1'))", $encoded);
  1004. break;
  1005. }
  1006. /* Replace every spaces to _ (more readable than =20) */
  1007. $encoded = str_replace(' ', '_', $encoded);
  1008. return $encoded;
  1009. }
  1010. /* Adds a string or binary attachment (non-filesystem) to the list.
  1011. * This method can be used to attach ascii or binary data,
  1012. * such as a BLOB record from a database.
  1013. * @param string $string String attachment data.
  1014. * @param string $filename Name of the attachment.
  1015. * @param string $encoding File encoding (see $Encoding).
  1016. * @param string $type File extension (MIME) type.
  1017. * @return void
  1018. */
  1019. function AddStringAttachment($string, $filename, $encoding = 'base64', $type = 'application/octet-stream') {
  1020. /* Append to $attachment array */
  1021. $cur = count($this->attachment);
  1022. $this->attachment[$cur][0] = $string;
  1023. $this->attachment[$cur][1] = $filename;
  1024. $this->attachment[$cur][2] = $filename;
  1025. $this->attachment[$cur][3] = $encoding;
  1026. $this->attachment[$cur][4] = $type;
  1027. $this->attachment[$cur][5] = true; // isString
  1028. $this->attachment[$cur][6] = 'attachment';
  1029. $this->attachment[$cur][7] = 0;
  1030. }
  1031. /* Adds an embedded attachment. This can include images, sounds, and
  1032. * just about any other document. Make sure to set the $type to an
  1033. * image type. For JPEG images use 'image/jpeg' and for GIF images
  1034. * use 'image/gif'.
  1035. * @param string $path Path to the attachment.
  1036. * @param string $cid Content ID of the attachment. Use this to identify
  1037. * the Id for accessing the image in an HTML form.
  1038. * @param string $name Overrides the attachment name.
  1039. * @param string $encoding File encoding (see $Encoding).
  1040. * @param string $type File extension (MIME) type.
  1041. * @return bool
  1042. */
  1043. function AddEmbeddedImage($path, $cid, $name = '', $encoding = 'base64', $type = 'application/octet-stream') {
  1044. if(!@is_file($path)) {
  1045. $this->SetError($this->Lang('file_access') . $path);
  1046. return false;
  1047. }
  1048. $filename = basename($path);
  1049. if($name == '') {
  1050. $name = $filename;
  1051. }
  1052. /* Append to $attachment array */
  1053. $cur = count($this->attachment);
  1054. $this->attachment[$cur][0] = $path;
  1055. $this->attachment[$cur][1] = $filename;
  1056. $this->attachment[$cur][2] = $name;
  1057. $this->attachment[$cur][3] = $encoding;
  1058. $this->attachment[$cur][4] = $type;
  1059. $this->attachment[$cur][5] = false;
  1060. $this->attachment[$cur][6] = 'inline';
  1061. $this->attachment[$cur][7] = $cid;
  1062. return true;
  1063. }
  1064. /* Returns true if an inline attachment is present.
  1065. * @access private
  1066. * @return bool
  1067. */
  1068. function InlineImageExists() {
  1069. $result = false;
  1070. for($i = 0; $i < count($this->attachment); $i++) {
  1071. if($this->attachment[$i][6] == 'inline') {
  1072. $result = true;
  1073. break;
  1074. }
  1075. }
  1076. return $result;
  1077. }
  1078. /* CLASS METHODS, MESSAGE RESET */
  1079. /* Clears all recipients assigned in the TO array. Returns void.
  1080. * @return void
  1081. */
  1082. function ClearAddresses() {
  1083. $this->to = array();
  1084. }
  1085. /* Clears all recipients assigned in the CC array. Returns void.
  1086. * @return void
  1087. */
  1088. function ClearCCs() {
  1089. $this->cc = array();
  1090. }
  1091. /* Clears all recipients assigned in the BCC array. Returns void.
  1092. * @return void
  1093. */
  1094. function ClearBCCs() {
  1095. $this->bcc = array();
  1096. }
  1097. /* Clears all recipients assigned in the ReplyTo array. Returns void.
  1098. * @return void
  1099. */
  1100. function ClearReplyTos() {
  1101. $this->ReplyTo = array();
  1102. }
  1103. /* Clears all recipients assigned in the TO, CC and BCC
  1104. * array. Returns void.
  1105. * @return void
  1106. */
  1107. function ClearAllRecipients() {
  1108. $this->to = array();
  1109. $this->cc = array();
  1110. $this->bcc = array();
  1111. }
  1112. /* Clears all previously set filesystem, string, and binary
  1113. * attachments. Returns void.
  1114. * @return void
  1115. */
  1116. function ClearAttachments() {
  1117. $this->attachment = array();
  1118. }
  1119. /* Clears all custom headers. Returns void.
  1120. * @return void
  1121. */
  1122. function ClearCustomHeaders() {
  1123. $this->CustomHeader = array();
  1124. }
  1125. /* CLASS METHODS, MISCELLANEOUS */
  1126. /* Adds the error message to the error container.
  1127. * Returns void.
  1128. * @access private
  1129. * @return void
  1130. */
  1131. function SetError($msg) {
  1132. $this->error_count++;
  1133. $this->ErrorInfo = $msg;
  1134. }
  1135. /* Returns the proper RFC 822 formatted date.
  1136. * @access private
  1137. * @return string
  1138. */
  1139. function RFCDate() {
  1140. $tz = date('Z');
  1141. $tzs = ($tz < 0) ? '-' : '+';
  1142. $tz = abs($tz);
  1143. $tz = (int)($tz/3600)*100 + ($tz%3600)/60;
  1144. $result = sprintf("%s %s%04d", date('D, j M Y H:i:s'), $tzs, $tz);
  1145. return $result;
  1146. }
  1147. /* Returns the appropriate server variable. Should work with both
  1148. * PHP 4.1.0+ as well as older versions. Returns an empty string
  1149. * if nothing is found.
  1150. * @access private
  1151. * @return mixed
  1152. */
  1153. function ServerVar($varName) {
  1154. global $HTTP_SERVER_VARS;
  1155. global $HTTP_ENV_VARS;
  1156. if(!isset($_SERVER)) {
  1157. $_SERVER = $HTTP_SERVER_VARS;
  1158. if(!isset($_SERVER['REMOTE_ADDR'])) {
  1159. $_SERVER = $HTTP_ENV_VARS; // must be Apache
  1160. }
  1161. }
  1162. if(isset($_SERVER[$varName])) {
  1163. return $_SERVER[$varName];
  1164. } else {
  1165. return '';
  1166. }
  1167. }
  1168. /* Returns the server hostname or 'localhost.localdomain' if unknown.
  1169. * @access private
  1170. * @return string
  1171. */
  1172. function ServerHostname() {
  1173. if ($this->Hostname != '') {
  1174. $result = $this->Hostname;
  1175. } elseif ($this->ServerVar('SERVER_NAME') != '') {
  1176. $result = $this->ServerVar('SERVER_NAME');
  1177. } else {
  1178. $result = 'localhost.localdomain';
  1179. }
  1180. return $result;
  1181. }
  1182. /* Returns a message in the appropriate language.
  1183. * @access private
  1184. * @return string
  1185. */
  1186. function Lang($key) {
  1187. if(count($this->language) < 1) {
  1188. $this->SetLanguage('en'); // set the default language
  1189. }
  1190. if(isset($this->language[$key])) {
  1191. return $this->language[$key];
  1192. } else {
  1193. return 'Language string failed to load: ' . $key;
  1194. }
  1195. }
  1196. /* Returns true if an error occurred.
  1197. * @return bool
  1198. */
  1199. function IsError() {
  1200. return ($this->error_count > 0);
  1201. }
  1202. /* Changes every end of line from CR or LF to CRLF.
  1203. * @access private
  1204. * @return string
  1205. */
  1206. function FixEOL($str) {
  1207. $str = str_replace("\r\n", "\n", $str);
  1208. $str = str_replace("\r", "\n", $str);
  1209. $str = str_replace("\n", $this->LE, $str);
  1210. return $str;
  1211. }
  1212. /* Adds a custom header.
  1213. * @return void
  1214. */
  1215. function AddCustomHeader($custom_header) {
  1216. $this->CustomHeader[] = explode(':', $custom_header, 2);
  1217. }
  1218. /**
  1219. * Evaluates the message and returns modifications for inline images and backgrounds
  1220. * @access public
  1221. * @return $message
  1222. */
  1223. function MsgHTML($message) {
  1224. preg_match_all("/(src|background)=\"(.*)\"/Ui", $message, $images);
  1225. if(isset($images[2])) {
  1226. foreach($images[2] as $i => $url) {
  1227. $filename = basename($url);
  1228. $directory = dirname($url);
  1229. $cid = 'cid:' . md5($filename);
  1230. $fileParts = split("\.", $filename);
  1231. $ext = $fileParts[1];
  1232. $mimeType = $this->_mime_types($ext);
  1233. $message = preg_replace("/".$images[1][$i]."=\"".preg_quote($url, '/')."\"/Ui", $images[1][$i]."=\"".$cid."\"", $message);
  1234. $this->AddEmbeddedImage($url, md5($filename), $filename, 'base64', $mimeType);
  1235. }
  1236. }
  1237. $this->IsHTML(true);
  1238. $this->Body = $message;
  1239. $textMsg = trim(strip_tags($message));
  1240. if ( !empty($textMsg) && empty($this->AltBody) ) {
  1241. $this->AltBody = $textMsg;
  1242. }
  1243. if ( empty($this->AltBody) ) {
  1244. $this->AltBody = 'To view this email message, open the email in with HTML compatibility!' . "\n\n";
  1245. }
  1246. }
  1247. /* Gets the mime type of the embedded or inline image
  1248. * @access private
  1249. * @return mime type of ext
  1250. */
  1251. function _mime_types($ext = '') {
  1252. $mimes = array(
  1253. 'hqx' => 'application/mac-binhex40',
  1254. 'cpt' => 'application/mac-compactpro',
  1255. 'doc' => 'application/msword',
  1256. 'bin' => 'application/macbinary',
  1257. 'dms' => 'application/octet-stream',
  1258. 'lha' => 'application/octet-stream',
  1259. 'lzh' => 'application/octet-stream',
  1260. 'exe' => 'application/octet-stream',
  1261. 'class' => 'application/octet-stream',
  1262. 'psd' => 'application/octet-stream',
  1263. 'so' => 'application/octet-stream',
  1264. 'sea' => 'application/octet-stream',
  1265. 'dll' => 'application/octet-stream',
  1266. 'oda' => 'application/oda',
  1267. 'pdf' => 'application/pdf',
  1268. 'ai' => 'application/postscript',
  1269. 'eps' => 'application/postscript',
  1270. 'ps' => 'application/postscript',
  1271. 'smi' => 'application/smil',
  1272. 'smil' => 'application/smil',
  1273. 'mif' => 'application/vnd.mif',
  1274. 'xls' => 'application/vnd.ms-excel',
  1275. 'ppt' => 'application/vnd.ms-powerpoint',
  1276. 'wbxml' => 'application/vnd.wap.wbxml',
  1277. 'wmlc' => 'application/vnd.wap.wmlc',
  1278. 'dcr' => 'application/x-director',
  1279. 'dir' => 'application/x-director',
  1280. 'dxr' => 'application/x-director',
  1281. 'dvi' => 'application/x-dvi',
  1282. 'gtar' => 'application/x-gtar',
  1283. 'php' => 'application/x-httpd-php',
  1284. 'php4' => 'application/x-httpd-php',
  1285. 'php3' => 'application/x-httpd-php',
  1286. 'phtml' => 'application/x-httpd-php',
  1287. 'phps' => 'application/x-httpd-php-source',
  1288. 'js' => 'application/x-javascript',
  1289. 'swf' => 'application/x-shockwave-flash',
  1290. 'sit' => 'application/x-stuffit',
  1291. 'tar' => 'application/x-tar',
  1292. 'tgz' => 'application/x-tar',
  1293. 'xhtml' => 'application/xhtml+xml',
  1294. 'xht' => 'application/xhtml+xml',
  1295. 'zip' => 'application/zip',
  1296. 'mid' => 'audio/midi',
  1297. 'midi' => 'audio/midi',
  1298. 'mpga' => 'audio/mpeg',
  1299. 'mp2' => 'audio/mpeg',
  1300. 'mp3' => 'audio/mpeg',
  1301. 'aif' => 'audio/x-aiff',
  1302. 'aiff' => 'audio/x-aiff',
  1303. 'aifc' => 'audio/x-aiff',
  1304. 'ram' => 'audio/x-pn-realaudio',
  1305. 'rm' => 'audio/x-pn-realaudio',
  1306. 'rpm' => 'audio/x-pn-realaudio-plugin',
  1307. 'ra' => 'audio/x-realaudio',
  1308. 'rv' => 'video/vnd.rn-realvideo',
  1309. 'wav' => 'audio/x-wav',
  1310. 'bmp' => 'image/bmp',
  1311. 'gif' => 'image/gif',
  1312. 'jpeg' => 'image/jpeg',
  1313. 'jpg' => 'image/jpeg',
  1314. 'jpe' => 'image/jpeg',
  1315. 'png' => 'image/png',
  1316. 'tiff' => 'image/tiff',
  1317. 'tif' => 'image/tiff',
  1318. 'css' => 'text/css',
  1319. 'html' => 'text/html',
  1320. 'htm' => 'text/html',
  1321. 'shtml' => 'text/html',
  1322. 'txt' => 'text/plain',
  1323. 'text' => 'text/plain',
  1324. 'log' => 'text/plain',
  1325. 'rtx' => 'text/richtext',
  1326. 'rtf' => 'text/rtf',
  1327. 'xml' => 'text/xml',
  1328. 'xsl' => 'text/xml',
  1329. 'mpeg' => 'video/mpeg',
  1330. 'mpg' => 'video/mpeg',
  1331. 'mpe' => 'video/mpeg',
  1332. 'qt' => 'video/quicktime',
  1333. 'mov' => 'video/quicktime',
  1334. 'avi' => 'video/x-msvideo',
  1335. 'movie' => 'video/x-sgi-movie',
  1336. 'doc' => 'application/msword',
  1337. 'word' => 'application/msword',
  1338. 'xl' => 'application/excel',
  1339. 'eml' => 'message/rfc822'
  1340. );
  1341. return ( ! isset($mimes[strtolower($ext)])) ? 'application/x-unknown-content-type' : $mimes[strtolower($ext)];
  1342. }
  1343. /* Set (or reset) Class Objects (variables)
  1344. *
  1345. * Usage Example:
  1346. * $page->set('reuse_code', true);
  1347. *
  1348. * @access public
  1349. * @param string $name Parameter Name
  1350. * @param mixed $value Parameter Value
  1351. * NOTE: will not work with arrays, there are no arrays to set/reset */
  1352. function set ( $name, $value = '' ) {
  1353. if ( isset($this->$name) ) {
  1354. $this->$name = $value;
  1355. } else {
  1356. $this->SetError('Cannot set or reset variable ' . $name);
  1357. return false;
  1358. }
  1359. }
  1360. /* This function will read a file from a supplied filename and return it. */
  1361. function getFile($filename) {
  1362. $return = '';
  1363. if ($fp = fopen($filename, 'rb')) {
  1364. while (!feof($fp)) {
  1365. $return .= fread($fp, 1024);
  1366. }
  1367. fclose($fp);
  1368. return $return;
  1369. } else {
  1370. return false;
  1371. }
  1372. }
  1373. /* Strips newlines to prevent header injection.
  1374. * @access private
  1375. * @param string $str String
  1376. * @return string
  1377. */
  1378. function SecureHeader($str) {
  1379. $str = trim($str);
  1380. $str = str_replace("\r", "", $str);
  1381. $str = str_replace("\n", "", $str);
  1382. return $str;
  1383. }
  1384. }
  1385. ?>