PageRenderTime 86ms CodeModel.GetById 26ms RepoModel.GetById 0ms app.codeStats 1ms

/ festos/core/class.phpmailer.php

http://festos.googlecode.com/
PHP | 1718 lines | 1170 code | 145 blank | 403 comment | 176 complexity | 88e223e27e1c605ac2c4a58aa36817fc MD5 | raw file
Possible License(s): LGPL-2.1, BSD-3-Clause

Large files files are truncated, but you can click here to view the full file

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

Large files files are truncated, but you can click here to view the full file