Advertisement
Guest User

php mailer by R #LulzSec #AntiSec #PuzzSec

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