Source for file class.phpmailer.php

Documentation is available at class.phpmailer.php

  1. <?php
  2. /*~ class.phpmailer.php
  3. .---------------------------------------------------------------------------.
  4. | Software: PHPMailer - PHP email class |
  5. | Version: 5.0.0 |
  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. | Admin: Andy Prevost (project admininistrator) |
  11. | Authors: Andy Prevost (codeworxtech) codeworxtech@users.sourceforge.net |
  12. | : Marcus Bointon (coolbru) coolbru@users.sourceforge.net |
  13. | Founder: Brent R. Matzelle (original founder) |
  14. | Copyright (c) 2004-2009, Andy Prevost. All Rights Reserved. |
  15. | Copyright (c) 2001-2003, Brent R. Matzelle |
  16. | ------------------------------------------------------------------------- |
  17. | License: Distributed under the Lesser General Public License (LGPL) |
  18. | http://www.gnu.org/copyleft/lesser.html |
  19. | This program is distributed in the hope that it will be useful - WITHOUT |
  20. | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
  21. | FITNESS FOR A PARTICULAR PURPOSE. |
  22. | ------------------------------------------------------------------------- |
  23. | We offer a number of paid services (www.codeworxtech.com): |
  24. | - Web Hosting on highly optimized fast and secure servers |
  25. | - Technology Consulting |
  26. | - Oursourcing (highly qualified programmers and graphic designers) |
  27. '---------------------------------------------------------------------------'
  28. */
  29.  
  30. /**
  31. * PHPMailer - PHP email transport class
  32. * NOTE: Requires PHP version 5 or later
  33. * @package PHPMailer
  34. * @author Andy Prevost
  35. * @author Marcus Bointon
  36. * @copyright 2004 - 2009 Andy Prevost
  37. * @version $Id: class.phpmailer.php 254 2009-04-02 18:52:18Z codeworxtech $
  38. * @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
  39. */
  40.  
  41. if (version_compare(PHP_VERSION, '5.0.0', '<') ) exit("Sorry, this version of PHPMailer will only run on PHP version 5 or greater!\n");
  42.  
  43. class PHPMailer {
  44.  
  45. /////////////////////////////////////////////////
  46. // PROPERTIES, PUBLIC
  47. /////////////////////////////////////////////////
  48.  
  49.  
  50. /**
  51. * Email priority (1 = High, 3 = Normal, 5 = low).
  52. * @var int
  53. */
  54. public $Priority = 3;
  55.  
  56. /**
  57. * Sets the CharSet of the message.
  58. * @var string
  59. */
  60. public $CharSet = 'iso-8859-1';
  61.  
  62. /**
  63. * Sets the Content-type of the message.
  64. * @var string
  65. */
  66. public $ContentType = 'text/plain';
  67.  
  68. /**
  69. * Sets the Encoding of the message. Options for this are
  70. * "8bit", "7bit", "binary", "base64", and "quoted-printable".
  71. * @var string
  72. */
  73. public $Encoding = '8bit';
  74.  
  75. /**
  76. * Holds the most recent mailer error message.
  77. * @var string
  78. */
  79. public $ErrorInfo = '';
  80.  
  81. /**
  82. * Sets the From email address for the message.
  83. * @var string
  84. */
  85. public $From = 'root@localhost';
  86.  
  87. /**
  88. * Sets the From name of the message.
  89. * @var string
  90. */
  91. public $FromName = 'Root User';
  92.  
  93. /**
  94. * Sets the Sender email (Return-Path) of the message. If not empty,
  95. * will be sent via -f to sendmail or as 'MAIL FROM' in smtp mode.
  96. * @var string
  97. */
  98. public $Sender = '';
  99.  
  100. /**
  101. * Sets the Subject of the message.
  102. * @var string
  103. */
  104. public $Subject = '';
  105.  
  106. /**
  107. * Sets the Body of the message. This can be either an HTML or text body.
  108. * If HTML then run IsHTML(true).
  109. * @var string
  110. */
  111. public $Body = '';
  112.  
  113. /**
  114. * Sets the text-only body of the message. This automatically sets the
  115. * email to multipart/alternative. This body can be read by mail
  116. * clients that do not have HTML email capability such as mutt. Clients
  117. * that can read HTML will view the normal Body.
  118. * @var string
  119. */
  120. public $AltBody = '';
  121.  
  122. /**
  123. * Sets word wrapping on the body of the message to a given number of
  124. * characters.
  125. * @var int
  126. */
  127. public $WordWrap = 0;
  128.  
  129. /**
  130. * Method to send mail: ("mail", "sendmail", or "smtp").
  131. * @var string
  132. */
  133. public $Mailer = 'mail';
  134.  
  135. /**
  136. * Sets the path of the sendmail program.
  137. * @var string
  138. */
  139. public $Sendmail = '/usr/sbin/sendmail';
  140.  
  141. /**
  142. * Path to PHPMailer plugins. Useful if the SMTP class
  143. * is in a different directory than the PHP include path.
  144. * @var string
  145. */
  146. public $PluginDir = '';
  147.  
  148. /**
  149. * Sets the email address that a reading confirmation will be sent.
  150. * @var string
  151. */
  152. public $ConfirmReadingTo = '';
  153.  
  154. /**
  155. * Sets the hostname to use in Message-Id and Received headers
  156. * and as default HELO string. If empty, the value returned
  157. * by SERVER_NAME is used or 'localhost.localdomain'.
  158. * @var string
  159. */
  160. public $Hostname = '';
  161.  
  162. /**
  163. * Sets the message ID to be used in the Message-Id header.
  164. * If empty, a unique id will be generated.
  165. * @var string
  166. */
  167. public $MessageID = '';
  168.  
  169. /////////////////////////////////////////////////
  170. // PROPERTIES FOR SMTP
  171. /////////////////////////////////////////////////
  172.  
  173.  
  174. /**
  175. * Sets the SMTP hosts. All hosts must be separated by a
  176. * semicolon. You can also specify a different port
  177. * for each host by using this format: [hostname:port]
  178. * (e.g. "smtp1.example.com:25;smtp2.example.com").
  179. * Hosts will be tried in order.
  180. * @var string
  181. */
  182. public $Host = 'localhost';
  183.  
  184. /**
  185. * Sets the default SMTP server port.
  186. * @var int
  187. */
  188. public $Port = 25;
  189.  
  190. /**
  191. * Sets the SMTP HELO of the message (Default is $Hostname).
  192. * @var string
  193. */
  194. public $Helo = '';
  195.  
  196. /**
  197. * Sets connection prefix.
  198. * Options are "", "ssl" or "tls"
  199. * @var string
  200. */
  201. public $SMTPSecure = '';
  202.  
  203. /**
  204. * Sets SMTP authentication. Utilizes the Username and Password variables.
  205. * @var bool
  206. */
  207. public $SMTPAuth = false;
  208.  
  209. /**
  210. * Sets SMTP username.
  211. * @var string
  212. */
  213. public $Username = '';
  214.  
  215. /**
  216. * Sets SMTP password.
  217. * @var string
  218. */
  219. public $Password = '';
  220.  
  221. /**
  222. * Sets the SMTP server timeout in seconds.
  223. * This function will not work with the win32 version.
  224. * @var int
  225. */
  226. public $Timeout = 10;
  227.  
  228. /**
  229. * Sets SMTP class debugging on or off.
  230. * @var bool
  231. */
  232. public $SMTPDebug = false;
  233.  
  234. /**
  235. * Prevents the SMTP connection from being closed after each mail
  236. * sending. If this is set to true then to close the connection
  237. * requires an explicit call to SmtpClose().
  238. * @var bool
  239. */
  240. public $SMTPKeepAlive = false;
  241.  
  242. /**
  243. * Provides the ability to have the TO field process individual
  244. * emails, instead of sending to entire TO addresses
  245. * @var bool
  246. */
  247. public $SingleTo = false;
  248.  
  249. /**
  250. * Provides the ability to change the line ending
  251. * @var string
  252. */
  253. public $LE = "\n";
  254.  
  255. /////////////////////////////////////////////////
  256. // PROPERTIES, PRIVATE AND PROTECTED
  257. /////////////////////////////////////////////////
  258.  
  259.  
  260. private $smtp = NULL;
  261. private $to = array();
  262. private $cc = array();
  263. private $bcc = array();
  264. private $ReplyTo = array();
  265. private $all_recipients = array();
  266. private $attachment = array();
  267. private $CustomHeader = array();
  268. private $message_type = '';
  269. private $boundary = array();
  270. protected $language = array();
  271. private $error_count = 0;
  272. private $sign_cert_file = "";
  273. private $sign_key_file = "";
  274. private $sign_key_pass = "";
  275. private $exceptions = false;
  276.  
  277. /////////////////////////////////////////////////
  278. // CONSTANTS
  279. /////////////////////////////////////////////////
  280.  
  281.  
  282. const VERSION = '5.0.0';
  283. const STOP_MESSAGE = 0; // message only, continue processing
  284. const STOP_CONTINUE = 1; // message?, likely ok to continue processing
  285. const STOP_CRITICAL = 2; // message, plus full stop, critical error reached
  286.  
  287. /////////////////////////////////////////////////
  288. // METHODS, VARIABLES
  289. /////////////////////////////////////////////////
  290.  
  291.  
  292. /**
  293. * Constructor
  294. * @param boolean $exceptions Should we throw external exceptions?
  295. */
  296. public function __construct($exceptions = false) {
  297. $this->exceptions = ($exceptions == true);
  298. }
  299.  
  300. /**
  301. * Sets message type to HTML.
  302. * @param bool $ishtml
  303. * @return void
  304. */
  305. public function IsHTML($ishtml = true) {
  306. if ($ishtml) {
  307. $this->ContentType = 'text/html';
  308. } else {
  309. $this->ContentType = 'text/plain';
  310. }
  311. }
  312.  
  313. /**
  314. * Sets Mailer to send message using SMTP.
  315. * @return void
  316. */
  317. public function IsSMTP() {
  318. $this->Mailer = 'smtp';
  319. }
  320.  
  321. /**
  322. * Sets Mailer to send message using PHP mail() function.
  323. * @return void
  324. */
  325. public function IsMail() {
  326. $this->Mailer = 'mail';
  327. }
  328.  
  329. /**
  330. * Sets Mailer to send message using the $Sendmail program.
  331. * @return void
  332. */
  333. public function IsSendmail() {
  334. if (!stristr(ini_get('sendmail_path'), 'sendmail')) {
  335. $this->Sendmail = '/var/qmail/bin/sendmail';
  336. }
  337. $this->Mailer = 'sendmail';
  338. }
  339.  
  340. /**
  341. * Sets Mailer to send message using the qmail MTA.
  342. * @return void
  343. */
  344. public function IsQmail() {
  345. if (stristr(ini_get('sendmail_path'), 'qmail')) {
  346. $this->Sendmail = '/var/qmail/bin/sendmail';
  347. }
  348. $this->Mailer = 'sendmail';
  349. }
  350.  
  351. /////////////////////////////////////////////////
  352. // METHODS, RECIPIENTS
  353. /////////////////////////////////////////////////
  354.  
  355.  
  356. /**
  357. * Adds a "To" address.
  358. * @param string $address
  359. * @param string $name
  360. * @return boolean true on success, false if address already used
  361. */
  362. public function AddAddress($address, $name = '') {
  363. return $this->AddAnAddress('to', $address, $name);
  364. }
  365.  
  366. /**
  367. * Adds a "Cc" address.
  368. * Note: this function works with the SMTP mailer on win32, not with the "mail" mailer.
  369. * @param string $address
  370. * @param string $name
  371. * @return boolean true on success, false if address already used
  372. */
  373. public function AddCC($address, $name = '') {
  374. return $this->AddAnAddress('cc', $address, $name);
  375. }
  376.  
  377. /**
  378. * Adds a "Bcc" address.
  379. * Note: this function works with the SMTP mailer on win32, not with the "mail" mailer.
  380. * @param string $address
  381. * @param string $name
  382. * @return boolean true on success, false if address already used
  383. */
  384. public function AddBCC($address, $name = '') {
  385. return $this->AddAnAddress('bcc', $address, $name);
  386. }
  387.  
  388. /**
  389. * Adds a "Reply-to" address.
  390. * @param string $address
  391. * @param string $name
  392. * @return boolean
  393. */
  394. public function AddReplyTo($address, $name = '') {
  395. return $this->AddAnAddress('ReplyTo', $address, $name);
  396. }
  397.  
  398. /**
  399. * Adds an address to one of the recipient arrays
  400. * Addresses that have been added already return false, but do not throw exceptions
  401. * @param string $kind One of 'to', 'cc', 'bcc', 'ReplyTo'
  402. * @param string $address The email address to send to
  403. * @param string $name
  404. * @return boolean true on success, false if address already used or invalid in some way
  405. * @access private
  406. */
  407. private function AddAnAddress($kind, $address, $name = '') {
  408. if (!preg_match('/^(to|cc|bcc|ReplyTo)$/', $kind)) {
  409. echo 'Invalid recipient array: ' . kind;
  410. return false;
  411. }
  412. $address = trim($address);
  413. $name = trim(preg_replace('/[\r\n]+/', '', $name)); //Strip breaks and trim
  414. if (!self::ValidateAddress($address)) {
  415. $this->SetError($this->Lang('invalid_address').': '. $address);
  416. if ($this->exceptions) {
  417. throw new phpmailerException($this->Lang('invalid_address').': '.$address);
  418. }
  419. echo $this->Lang('invalid_address').': '.$address;
  420. return false;
  421. }
  422. if ($kind != 'ReplyTo') {
  423. if (!isset($this->all_recipients[strtolower($address)])) {
  424. array_push($this->$kind, array($address, $name));
  425. $this->all_recipients[strtolower($address)] = true;
  426. return true;
  427. }
  428. } else {
  429. if (!array_key_exists(strtolower($address), $this->ReplyTo)) {
  430. $this->ReplyTo[strtolower($address)] = array($address, $name);
  431. return true;
  432. }
  433. }
  434. return false;
  435. }
  436.  
  437. /**
  438. * Set the From and FromName properties
  439. * @param string $address
  440. * @param string $name
  441. * @return boolean
  442. */
  443. public function SetFrom($address, $name = '') {
  444. $address = trim($address);
  445. $name = trim(preg_replace('/[\r\n]+/', '', $name)); //Strip breaks and trim
  446. if (!self::ValidateAddress($address)) {
  447. $this->SetError($this->Lang('invalid_address').': '. $address);
  448. if ($this->exceptions) {
  449. throw new phpmailerException($this->Lang('invalid_address').': '.$address);
  450. }
  451. echo $this->Lang('invalid_address').': '.$address;
  452. return false;
  453. }
  454. $this->From = $address;
  455. $this->FromName = $name;
  456. return true;
  457. }
  458.  
  459. /**
  460. * Check that a string looks roughly like an email address should
  461. * Static so it can be used without instantiation
  462. * Tries to use PHP built-in validator in the filter extension (from PHP 5.2), falls back to a reasonably competent regex validator
  463. * Conforms approximately to RFC2822
  464. * @link http://www.hexillion.com/samples/#Regex Original pattern found here
  465. * @param string $address The email address to check
  466. * @return boolean
  467. * @static
  468. * @access public
  469. */
  470. public static function ValidateAddress($address) {
  471. if (function_exists('filter_var')) { //Introduced in PHP 5.2
  472. if(filter_var($address, FILTER_VALIDATE_EMAIL) === FALSE) {
  473. return false;
  474. } else {
  475. return true;
  476. }
  477. } else {
  478. return preg_match('/^(?:[\w\!\#\$\%\&\'\*\+\-\/\=\?\^\`\{\|\}\~]+\.)*[\w\!\#\$\%\&\'\*\+\-\/\=\?\^\`\{\|\}\~]+@(?:(?:(?:[a-zA-Z0-9_](?:[a-zA-Z0-9_\-](?!\.)){0,61}[a-zA-Z0-9_-]?\.)+[a-zA-Z0-9_](?:[a-zA-Z0-9_\-](?!$)){0,61}[a-zA-Z0-9_]?)|(?:\[(?:(?:[01]?\d{1,2}|2[0-4]\d|25[0-5])\.){3}(?:[01]?\d{1,2}|2[0-4]\d|25[0-5])\]))$/', $address);
  479. }
  480. }
  481.  
  482. /////////////////////////////////////////////////
  483. // METHODS, MAIL SENDING
  484. /////////////////////////////////////////////////
  485.  
  486.  
  487. /**
  488. * Creates message and assigns Mailer. If the message is
  489. * not sent successfully then it returns false. Use the ErrorInfo
  490. * variable to view description of the error.
  491. * @return bool
  492. */
  493. public function Send() {
  494. try {
  495. if ((count($this->to) + count($this->cc) + count($this->bcc)) < 1) {
  496. throw new phpmailerException($this->Lang('provide_address'), self::STOP_CRITICAL);
  497. }
  498.  
  499. // Set whether the message is multipart/alternative
  500. if(!empty($this->AltBody)) {
  501. $this->ContentType = 'multipart/alternative';
  502. }
  503.  
  504. $this->error_count = 0; // reset errors
  505. $this->SetMessageType();
  506. $header = $this->CreateHeader();
  507. $body = $this->CreateBody();
  508.  
  509. if (empty($this->Body)) {
  510. throw new phpmailerException($this->Lang('empty_message'), self::STOP_CRITICAL);
  511. }
  512.  
  513. // Choose the mailer and send through it
  514. switch($this->Mailer) {
  515. case 'sendmail':
  516. return $this->SendmailSend($header, $body);
  517. case 'smtp':
  518. return $this->SmtpSend($header, $body);
  519. case 'mail':
  520. default:
  521. return $this->MailSend($header, $body);
  522. }
  523.  
  524. } catch (phpmailerException $e) {
  525. $this->SetError($e->getMessage());
  526. if ($this->exceptions) {
  527. throw $e;
  528. }
  529. echo $e->getMessage()."\n";
  530. return false;
  531. }
  532. }
  533.  
  534. /**
  535. * Sends mail using the $Sendmail program.
  536. * @param string $header The message headers
  537. * @param string $body The message body
  538. * @access protected
  539. * @return bool
  540. */
  541. protected function SendmailSend($header, $body) {
  542. if ($this->Sender != '') {
  543. $sendmail = sprintf("%s -oi -f %s -t", escapeshellcmd($this->Sendmail), escapeshellarg($this->Sender));
  544. } else {
  545. $sendmail = sprintf("%s -oi -t", escapeshellcmd($this->Sendmail));
  546. }
  547. if(!@$mail = popen($sendmail, 'w')) {
  548. throw new phpmailerException($this->Lang('execute') . $this->Sendmail, self::STOP_CRITICAL);
  549. }
  550. fputs($mail, $header);
  551. fputs($mail, $body);
  552. $result = pclose($mail);
  553. if($result != 0) {
  554. throw new phpmailerException($this->Lang('execute') . $this->Sendmail, self::STOP_CRITICAL);
  555. }
  556. return true;
  557. }
  558.  
  559. /**
  560. * Sends mail using the PHP mail() function.
  561. * @param string $header The message headers
  562. * @param string $body The message body
  563. * @access protected
  564. * @return bool
  565. */
  566. protected function MailSend($header, $body) {
  567. $toArr = array();
  568. foreach($this->to as $t) {
  569. $toArr[] = $this->AddrFormat($t);
  570. }
  571. $to = implode(', ', $toArr);
  572.  
  573. $params = sprintf("-oi -f %s", $this->Sender);
  574. if ($this->Sender != '' && strlen(ini_get('safe_mode'))< 1) {
  575. $old_from = ini_get('sendmail_from');
  576. ini_set('sendmail_from', $this->Sender);
  577. if ($this->SingleTo === true && count($toArr) > 1) {
  578. foreach ($toArr as $key => $val) {
  579. $rt = @mail($val, $this->EncodeHeader($this->SecureHeader($this->Subject)), $body, $header, $params);
  580. }
  581. } else {
  582. $rt = @mail($to, $this->EncodeHeader($this->SecureHeader($this->Subject)), $body, $header, $params);
  583. }
  584. } else {
  585. if ($this->SingleTo === true && count($toArr) > 1) {
  586. foreach ($toArr as $key => $val) {
  587. $rt = @mail($val, $this->EncodeHeader($this->SecureHeader($this->Subject)), $body, $header, $params);
  588. }
  589. } else {
  590. $rt = @mail($to, $this->EncodeHeader($this->SecureHeader($this->Subject)), $body, $header);
  591. }
  592. }
  593. if (isset($old_from)) {
  594. ini_set('sendmail_from', $old_from);
  595. }
  596. if(!$rt) {
  597. throw new phpmailerException($this->Lang('instantiate'), self::STOP_CRITICAL);
  598. }
  599. return true;
  600. }
  601.  
  602. /**
  603. * Sends mail via SMTP using PhpSMTP
  604. * Returns false if there is a bad MAIL FROM, RCPT, or DATA input.
  605. * @param string $header The message headers
  606. * @param string $body The message body
  607. * @uses SMTP
  608. * @access protected
  609. * @return bool
  610. */
  611. protected function SmtpSend($header, $body) {
  612. require_once $this->PluginDir . 'class.smtp.php';
  613. $bad_rcpt = array();
  614.  
  615. if(!$this->SmtpConnect()) {
  616. throw new phpmailerException($this->Lang('smtp_connect_failed'), self::STOP_CRITICAL);
  617. }
  618. $smtp_from = ($this->Sender == '') ? $this->From : $this->Sender;
  619. if(!$this->smtp->Mail($smtp_from)) {
  620. throw new phpmailerException($this->Lang('from_failed') . $smtp_from, self::STOP_CRITICAL);
  621. }
  622.  
  623. // Attempt to send attach all recipients
  624. foreach($this->to as $to) {
  625. if (!$this->smtp->Recipient($to[0])) {
  626. $bad_rcpt[] = $to[0];
  627. }
  628. }
  629. foreach($this->cc as $cc) {
  630. if (!$this->smtp->Recipient($cc[0])) {
  631. $bad_rcpt[] = $cc[0];
  632. }
  633. }
  634. foreach($this->bcc as $bcc) {
  635. if (!$this->smtp->Recipient($bcc[0])) {
  636. $bad_rcpt[] = $bcc[0];
  637. }
  638. }
  639. if (count($bad_rcpt) > 0 ) { //Create error message for any bad addresses
  640. $badaddresses = implode(', ', $bad_rcpt);
  641. throw new phpmailerException($this->Lang('recipients_failed') . $badaddresses);
  642. }
  643. if(!$this->smtp->Data($header . $body)) {
  644. throw new phpmailerException($this->Lang('data_not_accepted'), self::STOP_CRITICAL);
  645. }
  646. if($this->SMTPKeepAlive == true) {
  647. $this->smtp->Reset();
  648. }
  649. return true;
  650. }
  651.  
  652. /**
  653. * Initiates a connection to an SMTP server.
  654. * Returns false if the operation failed.
  655. * @uses SMTP
  656. * @access public
  657. * @return bool
  658. */
  659. public function SmtpConnect() {
  660. if(is_null($this->smtp)) {
  661. $this->smtp = new SMTP();
  662. }
  663.  
  664. $this->smtp->do_debug = $this->SMTPDebug;
  665. $hosts = explode(';', $this->Host);
  666. $index = 0;
  667. $connection = $this->smtp->Connected();
  668.  
  669. // Retry while there is no connection
  670. try {
  671. while($index < count($hosts) && !$connection) {
  672. $hostinfo = array();
  673. if (preg_match('/^(.+):([0-9]+)$/', $hosts[$index], $hostinfo)) {
  674. $host = $hostinfo[1];
  675. $port = $hostinfo[2];
  676. } else {
  677. $host = $hosts[$index];
  678. $port = $this->Port;
  679. }
  680.  
  681. $tls = ($this->SMTPSecure == 'tls');
  682. $ssl = ($this->SMTPSecure == 'ssl');
  683.  
  684. if ($this->smtp->Connect(($ssl ? 'ssl://':'').$host, $port, $this->Timeout)) {
  685.  
  686. $hello = ($this->Helo != '' ? $this->Helo : $this->ServerHostname());
  687. $this->smtp->Hello($hello);
  688.  
  689. if ($tls) {
  690. if (!$this->smtp->StartTLS()) {
  691. throw new phpmailerException($this->Lang('tls'));
  692. }
  693.  
  694. //We must resend HELO after tls negotiation
  695. $this->smtp->Hello($hello);
  696. }
  697.  
  698. $connection = true;
  699. if ($this->SMTPAuth) {
  700. if (!$this->smtp->Authenticate($this->Username, $this->Password)) {
  701. throw new phpmailerException($this->Lang('authenticate'));
  702. }
  703. }
  704. }
  705. $index++;
  706. if (!$connection) {
  707. throw new phpmailerException($this->Lang('connect_host'));
  708. }
  709. }
  710. } catch (phpmailerException $e) {
  711. $this->smtp->Reset();
  712. throw $e;
  713. }
  714. return true;
  715. }
  716.  
  717. /**
  718. * Closes the active SMTP session if one exists.
  719. * @return void
  720. */
  721. public function SmtpClose() {
  722. if(!is_null($this->smtp)) {
  723. if($this->smtp->Connected()) {
  724. $this->smtp->Quit();
  725. $this->smtp->Close();
  726. }
  727. }
  728. }
  729.  
  730. /**
  731. * Sets the language for all class error messages.
  732. * Returns false if it cannot load the language file. The default language is English.
  733. * @param string $langcode ISO 639-1 2-character language code (e.g. Portuguese: "br")
  734. * @param string $lang_path Path to the language file directory
  735. * @access public
  736. */
  737. function SetLanguage($langcode = 'en', $lang_path = 'language/') {
  738. //Define full set of translatable strings
  739. $PHPMAILER_LANG = array(
  740. 'provide_address' => 'You must provide at least one recipient email address.',
  741. 'mailer_not_supported' => ' mailer is not supported.',
  742. 'execute' => 'Could not execute: ',
  743. 'instantiate' => 'Could not instantiate mail function.',
  744. 'authenticate' => 'SMTP Error: Could not authenticate.',
  745. 'from_failed' => 'The following From address failed: ',
  746. 'recipients_failed' => 'SMTP Error: The following recipients failed: ',
  747. 'data_not_accepted' => 'SMTP Error: Data not accepted.',
  748. 'connect_host' => 'SMTP Error: Could not connect to SMTP host.',
  749. 'file_access' => 'Could not access file: ',
  750. 'file_open' => 'File Error: Could not open file: ',
  751. 'encoding' => 'Unknown encoding: ',
  752. 'signing' => 'Signing Error: ',
  753. 'smtp_error' => 'SMTP server error: ',
  754. 'empty_message' => 'Message body empty',
  755. 'invalid_address' => 'Invalid address',
  756. 'variable_set' => 'Cannot set or reset variable: '
  757. );
  758. //Overwrite language-specific strings. This way we'll never have missing translations - no more "language string failed to load"!
  759. $l = true;
  760. if ($langcode != 'en') { //There is no English translation file
  761. $l = @include $lang_path.'phpmailer.lang-'.$langcode.'.php';
  762. }
  763. $this->language = $PHPMAILER_LANG;
  764. return ($l == true); //Returns false if language not found
  765. }
  766.  
  767. /**
  768. * Return the current array of language strings
  769. * @return array
  770. */
  771. public function GetTranslations() {
  772. return $this->language;
  773. }
  774.  
  775. /////////////////////////////////////////////////
  776. // METHODS, MESSAGE CREATION
  777. /////////////////////////////////////////////////
  778.  
  779.  
  780. /**
  781. * Creates recipient headers.
  782. * @access public
  783. * @return string
  784. */
  785. public function AddrAppend($type, $addr) {
  786. $addr_str = $type . ': ';
  787. $addresses = array();
  788. foreach ($addr as $a) {
  789. $addresses[] = $this->AddrFormat($a);
  790. }
  791. $addr_str .= implode(', ', $addresses);
  792. $addr_str .= $this->LE;
  793.  
  794. return $addr_str;
  795. }
  796.  
  797. /**
  798. * Formats an address correctly.
  799. * @access public
  800. * @return string
  801. */
  802. public function AddrFormat($addr) {
  803. if (empty($addr[1])) {
  804. return $this->SecureHeader($addr[0]);
  805. } else {
  806. return $this->EncodeHeader($this->SecureHeader($addr[1]), 'phrase') . " <" . $this->SecureHeader($addr[0]) . ">";
  807. }
  808. }
  809.  
  810. /**
  811. * Wraps message for use with mailers that do not
  812. * automatically perform wrapping and for quoted-printable.
  813. * Original written by philippe.
  814. * @param string $message The message to wrap
  815. * @param integer $length The line length to wrap to
  816. * @param boolean $qp_mode Whether to run in Quoted-Printable mode
  817. * @access public
  818. * @return string
  819. */
  820. public function WrapText($message, $length, $qp_mode = false) {
  821. $soft_break = ($qp_mode) ? sprintf(" =%s", $this->LE) : $this->LE;
  822. // If utf-8 encoding is used, we will need to make sure we don't
  823. // split multibyte characters when we wrap
  824. $is_utf8 = (strtolower($this->CharSet) == "utf-8");
  825.  
  826. $message = $this->FixEOL($message);
  827. if (substr($message, -1) == $this->LE) {
  828. $message = substr($message, 0, -1);
  829. }
  830.  
  831. $line = explode($this->LE, $message);
  832. $message = '';
  833. for ($i=0 ;$i < count($line); $i++) {
  834. $line_part = explode(' ', $line[$i]);
  835. $buf = '';
  836. for ($e = 0; $e<count($line_part); $e++) {
  837. $word = $line_part[$e];
  838. if ($qp_mode and (strlen($word) > $length)) {
  839. $space_left = $length - strlen($buf) - 1;
  840. if ($e != 0) {
  841. if ($space_left > 20) {
  842. $len = $space_left;
  843. if ($is_utf8) {
  844. $len = $this->UTF8CharBoundary($word, $len);
  845. } elseif (substr($word, $len - 1, 1) == "=") {
  846. $len--;
  847. } elseif (substr($word, $len - 2, 1) == "=") {
  848. $len -= 2;
  849. }
  850. $part = substr($word, 0, $len);
  851. $word = substr($word, $len);
  852. $buf .= ' ' . $part;
  853. $message .= $buf . sprintf("=%s", $this->LE);
  854. } else {
  855. $message .= $buf . $soft_break;
  856. }
  857. $buf = '';
  858. }
  859. while (strlen($word) > 0) {
  860. $len = $length;
  861. if ($is_utf8) {
  862. $len = $this->UTF8CharBoundary($word, $len);
  863. } elseif (substr($word, $len - 1, 1) == "=") {
  864. $len--;
  865. } elseif (substr($word, $len - 2, 1) == "=") {
  866. $len -= 2;
  867. }
  868. $part = substr($word, 0, $len);
  869. $word = substr($word, $len);
  870.  
  871. if (strlen($word) > 0) {
  872. $message .= $part . sprintf("=%s", $this->LE);
  873. } else {
  874. $buf = $part;
  875. }
  876. }
  877. } else {
  878. $buf_o = $buf;
  879. $buf .= ($e == 0) ? $word : (' ' . $word);
  880.  
  881. if (strlen($buf) > $length and $buf_o != '') {
  882. $message .= $buf_o . $soft_break;
  883. $buf = $word;
  884. }
  885. }
  886. }
  887. $message .= $buf . $this->LE;
  888. }
  889.  
  890. return $message;
  891. }
  892.  
  893. /**
  894. * Finds last character boundary prior to maxLength in a utf-8
  895. * quoted (printable) encoded string.
  896. * Original written by Colin Brown.
  897. * @access public
  898. * @param string $encodedText utf-8 QP text
  899. * @param int $maxLength find last character boundary prior to this length
  900. * @return int
  901. */
  902. public function UTF8CharBoundary($encodedText, $maxLength) {
  903. $foundSplitPos = false;
  904. $lookBack = 3;
  905. while (!$foundSplitPos) {
  906. $lastChunk = substr($encodedText, $maxLength - $lookBack, $lookBack);
  907. $encodedCharPos = strpos($lastChunk, "=");
  908. if ($encodedCharPos !== false) {
  909. // Found start of encoded character byte within $lookBack block.
  910. // Check the encoded byte value (the 2 chars after the '=')
  911. $hex = substr($encodedText, $maxLength - $lookBack + $encodedCharPos + 1, 2);
  912. $dec = hexdec($hex);
  913. if ($dec < 128) { // Single byte character.
  914. // If the encoded char was found at pos 0, it will fit
  915. // otherwise reduce maxLength to start of the encoded char
  916. $maxLength = ($encodedCharPos == 0) ? $maxLength :
  917. $maxLength - ($lookBack - $encodedCharPos);
  918. $foundSplitPos = true;
  919. } elseif ($dec >= 192) { // First byte of a multi byte character
  920. // Reduce maxLength to split at start of character
  921. $maxLength = $maxLength - ($lookBack - $encodedCharPos);
  922. $foundSplitPos = true;
  923. } elseif ($dec < 192) { // Middle byte of a multi byte character, look further back
  924. $lookBack += 3;
  925. }
  926. } else {
  927. // No encoded character found
  928. $foundSplitPos = true;
  929. }
  930. }
  931. return $maxLength;
  932. }
  933.  
  934.  
  935. /**
  936. * Set the body wrapping.
  937. * @access public
  938. * @return void
  939. */
  940. public function SetWordWrap() {
  941. if($this->WordWrap < 1) {
  942. return;
  943. }
  944.  
  945. switch($this->message_type) {
  946. case 'alt':
  947. case 'alt_attachments':
  948. $this->AltBody = $this->WrapText($this->AltBody, $this->WordWrap);
  949. break;
  950. default:
  951. $this->Body = $this->WrapText($this->Body, $this->WordWrap);
  952. break;
  953. }
  954. }
  955.  
  956. /**
  957. * Assembles message header.
  958. * @access public
  959. * @return string The assembled header
  960. */
  961. public function CreateHeader() {
  962. $result = '';
  963.  
  964. // Set the boundaries
  965. $uniq_id = md5(uniqid(time()));
  966. $this->boundary[1] = 'b1_' . $uniq_id;
  967. $this->boundary[2] = 'b2_' . $uniq_id;
  968.  
  969. $result .= $this->HeaderLine('Date', self::RFCDate());
  970. if($this->Sender == '') {
  971. $result .= $this->HeaderLine('Return-Path', trim($this->From));
  972. } else {
  973. $result .= $this->HeaderLine('Return-Path', trim($this->Sender));
  974. }
  975.  
  976. // To be created automatically by mail()
  977. if($this->Mailer != 'mail') {
  978. if(count($this->to) > 0) {
  979. $result .= $this->AddrAppend('To', $this->to);
  980. } elseif (count($this->cc) == 0) {
  981. $result .= $this->HeaderLine('To', 'undisclosed-recipients:;');
  982. }
  983. }
  984.  
  985. $from = array();
  986. $from[0][0] = trim($this->From);
  987. $from[0][1] = $this->FromName;
  988. $result .= $this->AddrAppend('From', $from);
  989.  
  990. // sendmail and mail() extract Cc from the header before sending
  991. if((($this->Mailer == 'sendmail') || ($this->Mailer == 'mail')) && (count($this->cc) > 0)) {
  992. $result .= $this->AddrAppend('Cc', $this->cc);
  993. }
  994.  
  995. // sendmail and mail() extract Bcc from the header before sending
  996. if((($this->Mailer == 'sendmail') || ($this->Mailer == 'mail')) && (count($this->bcc) > 0)) {
  997. $result .= $this->AddrAppend('Bcc', $this->bcc);
  998. }
  999.  
  1000. if(count($this->ReplyTo) > 0) {
  1001. $result .= $this->AddrAppend('Reply-to', $this->ReplyTo);
  1002. }
  1003.  
  1004. // mail() sets the subject itself
  1005. if($this->Mailer != 'mail') {
  1006. $result .= $this->HeaderLine('Subject', $this->EncodeHeader($this->SecureHeader($this->Subject)));
  1007. }
  1008.  
  1009. if($this->MessageID != '') {
  1010. $result .= $this->HeaderLine('Message-ID',$this->MessageID);
  1011. } else {
  1012. $result .= sprintf("Message-ID: <%s@%s>%s", $uniq_id, $this->ServerHostname(), $this->LE);
  1013. }
  1014. $result .= $this->HeaderLine('X-Priority', $this->Priority);
  1015. $result .= $this->HeaderLine('X-Mailer', 'PHPMailer ' . self::VERSION . ' (phpmailer.codeworxtech.com)');
  1016.  
  1017. if($this->ConfirmReadingTo != '') {
  1018. $result .= $this->HeaderLine('Disposition-Notification-To', '<' . trim($this->ConfirmReadingTo) . '>');
  1019. }
  1020.  
  1021. // Add custom headers
  1022. for($index = 0; $index < count($this->CustomHeader); $index++) {
  1023. $result .= $this->HeaderLine(trim($this->CustomHeader[$index][0]), $this->EncodeHeader(trim($this->CustomHeader[$index][1])));
  1024. }
  1025. if (!$this->sign_key_file) {
  1026. $result .= $this->HeaderLine('MIME-Version', '1.0');
  1027. $result .= $this->GetMailMIME();
  1028. }
  1029.  
  1030. return $result;
  1031. }
  1032.  
  1033. /**
  1034. * Returns the message MIME.
  1035. * @access public
  1036. * @return string
  1037. */
  1038. public function GetMailMIME() {
  1039. $result = '';
  1040. switch($this->message_type) {
  1041. case 'plain':
  1042. $result .= $this->HeaderLine('Content-Transfer-Encoding', $this->Encoding);
  1043. $result .= sprintf("Content-Type: %s; charset=\"%s\"", $this->ContentType, $this->CharSet);
  1044. break;
  1045. case 'attachments':
  1046. case 'alt_attachments':
  1047. if($this->InlineImageExists()){
  1048. $result .= sprintf("Content-Type: %s;%s\ttype=\"text/html\";%s\tboundary=\"%s\"%s", 'multipart/related', $this->LE, $this->LE, $this->boundary[1], $this->LE);
  1049. } else {
  1050. $result .= $this->HeaderLine('Content-Type', 'multipart/mixed;');
  1051. $result .= $this->TextLine("\tboundary=\"" . $this->boundary[1] . '"');
  1052. }
  1053. break;
  1054. case 'alt':
  1055. $result .= $this->HeaderLine('Content-Type', 'multipart/alternative;');
  1056. $result .= $this->TextLine("\tboundary=\"" . $this->boundary[1] . '"');
  1057. break;
  1058. }
  1059.  
  1060. if($this->Mailer != 'mail') {
  1061. $result .= $this->LE.$this->LE;
  1062. }
  1063.  
  1064. return $result;
  1065. }
  1066.  
  1067. /**
  1068. * Assembles the message body. Returns an empty string on failure.
  1069. * @access public
  1070. * @return string The assembled message body
  1071. */
  1072. public function CreateBody() {
  1073. $body = '';
  1074.  
  1075. if ($this->sign_key_file) {
  1076. $body .= $this->GetMailMIME();
  1077. }
  1078.  
  1079. $this->SetWordWrap();
  1080.  
  1081. switch($this->message_type) {
  1082. case 'alt':
  1083. $body .= $this->GetBoundary($this->boundary[1], '', 'text/plain', '');
  1084. $body .= $this->EncodeString($this->AltBody, $this->Encoding);
  1085. $body .= $this->LE.$this->LE;
  1086. $body .= $this->GetBoundary($this->boundary[1], '', 'text/html', '');
  1087. $body .= $this->EncodeString($this->Body, $this->Encoding);
  1088. $body .= $this->LE.$this->LE;
  1089. $body .= $this->EndBoundary($this->boundary[1]);
  1090. break;
  1091. case 'plain':
  1092. $body .= $this->EncodeString($this->Body, $this->Encoding);
  1093. break;
  1094. case 'attachments':
  1095. $body .= $this->GetBoundary($this->boundary[1], '', '', '');
  1096. $body .= $this->EncodeString($this->Body, $this->Encoding);
  1097. $body .= $this->LE;
  1098. $body .= $this->AttachAll();
  1099. break;
  1100. case 'alt_attachments':
  1101. $body .= sprintf("--%s%s", $this->boundary[1], $this->LE);
  1102. $body .= sprintf("Content-Type: %s;%s" . "\tboundary=\"%s\"%s", 'multipart/alternative', $this->LE, $this->boundary[2], $this->LE.$this->LE);
  1103. $body .= $this->GetBoundary($this->boundary[2], '', 'text/plain', '') . $this->LE; // Create text body
  1104. $body .= $this->EncodeString($this->AltBody, $this->Encoding);
  1105. $body .= $this->LE.$this->LE;
  1106. $body .= $this->GetBoundary($this->boundary[2], '', 'text/html', '') . $this->LE; // Create the HTML body
  1107. $body .= $this->EncodeString($this->Body, $this->Encoding);
  1108. $body .= $this->LE.$this->LE;
  1109. $body .= $this->EndBoundary($this->boundary[2]);
  1110. $body .= $this->AttachAll();
  1111. break;
  1112. }
  1113.  
  1114. if ($this->IsError()) {
  1115. $body = '';
  1116. } elseif ($this->sign_key_file) {
  1117. try {
  1118. $file = tempnam('', 'mail');
  1119. file_put_contents($file, $body); //TODO check this worked
  1120. $signed = tempnam("", "signed");
  1121. if (@openssl_pkcs7_sign($file, $signed, "file://".$this->sign_cert_file, array("file://".$this->sign_key_file, $this->sign_key_pass), NULL)) {
  1122. @unlink($file);
  1123. @unlink($signed);
  1124. $body = file_get_contents($signed);
  1125. } else {
  1126. @unlink($file);
  1127. @unlink($signed);
  1128. throw new phpmailerException($this->Lang("signing").openssl_error_string());
  1129. }
  1130. } catch (phpmailerException $e) {
  1131. $body = '';
  1132. if ($this->exceptions) {
  1133. throw $e;
  1134. }
  1135. }
  1136. }
  1137.  
  1138. return $body;
  1139. }
  1140.  
  1141. /**
  1142. * Returns the start of a message boundary.
  1143. * @access private
  1144. */
  1145. private function GetBoundary($boundary, $charSet, $contentType, $encoding) {
  1146. $result = '';
  1147. if($charSet == '') {
  1148. $charSet = $this->CharSet;
  1149. }
  1150. if($contentType == '') {
  1151. $contentType = $this->ContentType;
  1152. }
  1153. if($encoding == '') {
  1154. $encoding = $this->Encoding;
  1155. }
  1156. $result .= $this->TextLine('--' . $boundary);
  1157. $result .= sprintf("Content-Type: %s; charset = \"%s\"", $contentType, $charSet);
  1158. $result .= $this->LE;
  1159. $result .= $this->HeaderLine('Content-Transfer-Encoding', $encoding);
  1160. $result .= $this->LE;
  1161.  
  1162. return $result;
  1163. }
  1164.  
  1165. /**
  1166. * Returns the end of a message boundary.
  1167. * @access private
  1168. */
  1169. private function EndBoundary($boundary) {
  1170. return $this->LE . '--' . $boundary . '--' . $this->LE;
  1171. }
  1172.  
  1173. /**
  1174. * Sets the message type.
  1175. * @access private
  1176. * @return void
  1177. */
  1178. private function SetMessageType() {
  1179. if(count($this->attachment) < 1 && strlen($this->AltBody) < 1) {
  1180. $this->message_type = 'plain';
  1181. } else {
  1182. if(count($this->attachment) > 0) {
  1183. $this->message_type = 'attachments';
  1184. }
  1185. if(strlen($this->AltBody) > 0 && count($this->attachment) < 1) {
  1186. $this->message_type = 'alt';
  1187. }
  1188. if(strlen($this->AltBody) > 0 && count($this->attachment) > 0) {
  1189. $this->message_type = 'alt_attachments';
  1190. }
  1191. }
  1192. }
  1193.  
  1194. /**
  1195. * Returns a formatted header line.
  1196. * @access public
  1197. * @return string
  1198. */
  1199. public function HeaderLine($name, $value) {
  1200. return $name . ': ' . $value . $this->LE;
  1201. }
  1202.  
  1203. /**
  1204. * Returns a formatted mail line.
  1205. * @access public
  1206. * @return string
  1207. */
  1208. public function TextLine($value) {
  1209. return $value . $this->LE;
  1210. }
  1211.  
  1212. /////////////////////////////////////////////////
  1213. // CLASS METHODS, ATTACHMENTS
  1214. /////////////////////////////////////////////////
  1215.  
  1216.  
  1217. /**
  1218. * Adds an attachment from a path on the filesystem.
  1219. * Returns false if the file could not be found
  1220. * or accessed.
  1221. * @param string $path Path to the attachment.
  1222. * @param string $name Overrides the attachment name.
  1223. * @param string $encoding File encoding (see $Encoding).
  1224. * @param string $type File extension (MIME) type.
  1225. * @return bool
  1226. */
  1227. public function AddAttachment($path, $name = '', $encoding = 'base64', $type = 'application/octet-stream') {
  1228. try {
  1229. if ( !@is_file($path) ) {
  1230. throw new phpmailerException($this->Lang('file_access') . $path, self::STOP_CONTINUE);
  1231. }
  1232. $filename = basename($path);
  1233. if ( $name == '' ) {
  1234. $name = $filename;
  1235. }
  1236.  
  1237. $this->attachment[] = array(
  1238. 0 => $path,
  1239. 1 => $filename,
  1240. 2 => $name,
  1241. 3 => $encoding,
  1242. 4 => $type,
  1243. 5 => false, // isStringAttachment
  1244. 6 => 'attachment',
  1245. 7 => 0
  1246. );
  1247.  
  1248. } catch (phpmailerException $e) {
  1249. $this->SetError($e->getMessage());
  1250. if ($this->exceptions) {
  1251. throw $e;
  1252. }
  1253. echo $e->getMessage()."\n";
  1254. if ( $e->getCode() == self::STOP_CRITICAL ) {
  1255. return false;
  1256. }
  1257. }
  1258. return true;
  1259. }
  1260.  
  1261. /**
  1262. * Return the current array of attachments
  1263. * @return array
  1264. */
  1265. public function GetAttachments() {
  1266. return $this->attachment;
  1267. }
  1268.  
  1269. /**
  1270. * Attaches all fs, string, and binary attachments to the message.
  1271. * Returns an empty string on failure.
  1272. * @access private
  1273. * @return string
  1274. */
  1275. private function AttachAll() {
  1276. // Return text of body
  1277. $mime = array();
  1278. $cidUniq = array();
  1279. $incl = array();
  1280.  
  1281. // Add all attachments
  1282. foreach ($this->attachment as $attachment) {
  1283. // Check for string attachment
  1284. $bString = $attachment[5];
  1285. if ($bString) {
  1286. $string = $attachment[0];
  1287. } else {
  1288. $path = $attachment[0];
  1289. }
  1290.  
  1291. if (in_array($attachment[0], $incl)) { continue; }
  1292. $filename = $attachment[1];
  1293. $name = $attachment[2];
  1294. $encoding = $attachment[3];
  1295. $type = $attachment[4];
  1296. $disposition = $attachment[6];
  1297. $cid = $attachment[7];
  1298. $incl[] = $attachment[0];
  1299. if ( isset($cidUniq[$cid]) ) { continue; }
  1300. $cidUniq[$cid] = true;
  1301.  
  1302. $mime[] = sprintf("--%s%s", $this->boundary[1], $this->LE);
  1303. $mime[] = sprintf("Content-Type: %s; name=\"%s\"%s", $type, $this->EncodeHeader($this->SecureHeader($name)), $this->LE);
  1304. $mime[] = sprintf("Content-Transfer-Encoding: %s%s", $encoding, $this->LE);
  1305.  
  1306. if($disposition == 'inline') {
  1307. $mime[] = sprintf("Content-ID: <%s>%s", $cid, $this->LE);
  1308. }
  1309.  
  1310. $mime[] = sprintf("Content-Disposition: %s; filename=\"%s\"%s", $disposition, $this->EncodeHeader($this->SecureHeader($name)), $this->LE.$this->LE);
  1311.  
  1312. // Encode as string attachment
  1313. if($bString) {
  1314. $mime[] = $this->EncodeString($string, $encoding);
  1315. if($this->IsError()) {
  1316. return '';
  1317. }
  1318. $mime[] = $this->LE.$this->LE;
  1319. } else {
  1320. $mime[] = $this->EncodeFile($path, $encoding);
  1321. if($this->IsError()) {
  1322. return '';
  1323. }
  1324. $mime[] = $this->LE.$this->LE;
  1325. }
  1326. }
  1327.  
  1328. $mime[] = sprintf("--%s--%s", $this->boundary[1], $this->LE);
  1329.  
  1330. return join('', $mime);
  1331. }
  1332.  
  1333. /**
  1334. * Encodes attachment in requested format.
  1335. * Returns an empty string on failure.
  1336. * @param string $path The full path to the file
  1337. * @param string $encoding The encoding to use; one of 'base64', '7bit', '8bit', 'binary', 'quoted-printable'
  1338. * @see EncodeFile()
  1339. * @access private
  1340. * @return string
  1341. */
  1342. private function EncodeFile($path, $encoding = 'base64') {
  1343. try {
  1344. if (!is_readable($path)) {
  1345. throw new phpmailerException($this->Lang('file_open') . $path, self::STOP_CONTINUE);
  1346. }
  1347. if (function_exists('get_magic_quotes')) {
  1348. function get_magic_quotes() {
  1349. return false;
  1350. }
  1351. }
  1352. if (PHP_VERSION < 6) {
  1353. $magic_quotes = get_magic_quotes_runtime();
  1354. set_magic_quotes_runtime(0);
  1355. }
  1356. $file_buffer = file_get_contents($path);
  1357. $file_buffer = $this->EncodeString($file_buffer, $encoding);
  1358. if (PHP_VERSION < 6) { set_magic_quotes_runtime($magic_quotes); }
  1359. return $file_buffer;
  1360. } catch (Exception $e) {
  1361. $this->SetError($e->getMessage());
  1362. return '';
  1363. }
  1364. }
  1365.  
  1366. /**
  1367. * Encodes string to requested format.
  1368. * Returns an empty string on failure.
  1369. * @param string $str The text to encode
  1370. * @param string $encoding The encoding to use; one of 'base64', '7bit', '8bit', 'binary', 'quoted-printable'
  1371. * @access public
  1372. * @return string
  1373. */
  1374. public function EncodeString ($str, $encoding = 'base64') {
  1375. $encoded = '';
  1376. switch(strtolower($encoding)) {
  1377. case 'base64':
  1378. $encoded = chunk_split(base64_encode($str), 76, $this->LE);
  1379. break;
  1380. case '7bit':
  1381. case '8bit':
  1382. $encoded = $this->FixEOL($str);
  1383. //Make sure it ends with a line break
  1384. if (substr($encoded, -(strlen($this->LE))) != $this->LE)
  1385. $encoded .= $this->LE;
  1386. break;
  1387. case 'binary':
  1388. $encoded = $str;
  1389. break;
  1390. case 'quoted-printable':
  1391. $encoded = $this->EncodeQP($str);
  1392. break;
  1393. default:
  1394. $this->SetError($this->Lang('encoding') . $encoding);
  1395. break;
  1396. }
  1397. return $encoded;
  1398. }
  1399.  
  1400. /**
  1401. * Encode a header string to best (shortest) of Q, B, quoted or none.
  1402. * @access public
  1403. * @return string
  1404. */
  1405. public function EncodeHeader($str, $position = 'text') {
  1406. $x = 0;
  1407.  
  1408. switch (strtolower($position)) {
  1409. case 'phrase':
  1410. if (!preg_match('/[\200-\377]/', $str)) {
  1411. // Can't use addslashes as we don't know what value has magic_quotes_sybase
  1412. $encoded = addcslashes($str, "\0..\37\177\\\"");
  1413. if (($str == $encoded) && !preg_match('/[^A-Za-z0-9!#$%&\'*+\/=?^_`{|}~ -]/', $str)) {
  1414. return ($encoded);
  1415. } else {
  1416. return ("\"$encoded\"");
  1417. }
  1418. }
  1419. $x = preg_match_all('/[^\040\041\043-\133\135-\176]/', $str, $matches);
  1420. break;
  1421. case 'comment':
  1422. $x = preg_match_all('/[()"]/', $str, $matches);
  1423. // Fall-through
  1424. case 'text':
  1425. default:
  1426. $x += preg_match_all('/[\000-\010\013\014\016-\037\177-\377]/', $str, $matches);
  1427. break;
  1428. }
  1429.  
  1430. if ($x == 0) {
  1431. return ($str);
  1432. }
  1433.  
  1434. $maxlen = 75 - 7 - strlen($this->CharSet);
  1435. // Try to select the encoding which should produce the shortest output
  1436. if (strlen($str)/3 < $x) {
  1437. $encoding = 'B';
  1438. if (function_exists('mb_strlen') && $this->HasMultiBytes($str)) {
  1439. // Use a custom function which correctly encodes and wraps long
  1440. // multibyte strings without breaking lines within a character
  1441. $encoded = $this->Base64EncodeWrapMB($str);
  1442. } else {
  1443. $encoded = base64_encode($str);
  1444. $maxlen -= $maxlen % 4;
  1445. $encoded = trim(chunk_split($encoded, $maxlen, "\n"));
  1446. }
  1447. } else {
  1448. $encoding = 'Q';
  1449. $encoded = $this->EncodeQ($str, $position);
  1450. $encoded = $this->WrapText($encoded, $maxlen, true);
  1451. $encoded = str_replace('='.$this->LE, "\n", trim($encoded));
  1452. }
  1453.  
  1454. $encoded = preg_replace('/^(.*)$/m', " =?".$this->CharSet."?$encoding?\\1?=", $encoded);
  1455. $encoded = trim(str_replace("\n", $this->LE, $encoded));
  1456.  
  1457. return $encoded;
  1458. }
  1459.  
  1460. /**
  1461. * Checks if a string contains multibyte characters.
  1462. * @access public
  1463. * @param string $str multi-byte text to wrap encode
  1464. * @return bool
  1465. */
  1466. public function HasMultiBytes($str) {
  1467. if (function_exists('mb_strlen')) {
  1468. return (strlen($str) > mb_strlen($str, $this->CharSet));
  1469. } else { // Assume no multibytes (we can't handle without mbstring functions anyway)
  1470. return false;
  1471. }
  1472. }
  1473.  
  1474. /**
  1475. * Correctly encodes and wraps long multibyte strings for mail headers
  1476. * without breaking lines within a character.
  1477. * Adapted from a function by paravoid at http://uk.php.net/manual/en/function.mb-encode-mimeheader.php
  1478. * @access public
  1479. * @param string $str multi-byte text to wrap encode
  1480. * @return string
  1481. */
  1482. public function Base64EncodeWrapMB($str) {
  1483. $start = "=?".$this->CharSet."?B?";
  1484. $end = "?=";
  1485. $encoded = "";
  1486.  
  1487. $mb_length = mb_strlen($str, $this->CharSet);
  1488. // Each line must have length <= 75, including $start and $end
  1489. $length = 75 - strlen($start) - strlen($end);
  1490. // Average multi-byte ratio
  1491. $ratio = $mb_length / strlen($str);
  1492. // Base64 has a 4:3 ratio
  1493. $offset = $avgLength = floor($length * $ratio * .75);
  1494.  
  1495. for ($i = 0; $i < $mb_length; $i += $offset) {
  1496. $lookBack = 0;
  1497.  
  1498. do {
  1499. $offset = $avgLength - $lookBack;
  1500. $chunk = mb_substr($str, $i, $offset, $this->CharSet);
  1501. $chunk = base64_encode($chunk);
  1502. $lookBack++;
  1503. }
  1504. while (strlen($chunk) > $length);
  1505.  
  1506. $encoded .= $chunk . $this->LE;
  1507. }
  1508.  
  1509. // Chomp the last linefeed
  1510. $encoded = substr($encoded, 0, -strlen($this->LE));
  1511. return $encoded;
  1512. }
  1513.  
  1514. /**
  1515. * Encode string to quoted-printable.
  1516. * Only uses standard PHP, slow, but will always work
  1517. * @access public
  1518. * @param string $string the text to encode
  1519. * @param integer $line_max Number of chars allowed on a line before wrapping
  1520. * @return string
  1521. */
  1522. public function EncodeQPphp( $input = '', $line_max = 76, $space_conv = false) {
  1523. $hex = array('0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F');
  1524. $lines = preg_split('/(?:\r\n|\r|\n)/', $input);
  1525. $eol = "\r\n";
  1526. $escape = '=';
  1527. $output = '';
  1528. while( list(, $line) = each($lines) ) {
  1529. $linlen = strlen($line);
  1530. $newline = '';
  1531. for($i = 0; $i < $linlen; $i++) {
  1532. $c = substr( $line, $i, 1 );
  1533. $dec = ord( $c );
  1534. if ( ( $i == 0 ) && ( $dec == 46 ) ) { // convert first point in the line into =2E
  1535. $c = '=2E';
  1536. }
  1537. if ( $dec == 32 ) {
  1538. if ( $i == ( $linlen - 1 ) ) { // convert space at eol only
  1539. $c = '=20';
  1540. } else if ( $space_conv ) {
  1541. $c = '=20';
  1542. }
  1543. } elseif ( ($dec == 61) || ($dec < 32 ) || ($dec > 126) ) { // always encode "\t", which is *not* required
  1544. $h2 = floor($dec/16);
  1545. $h1 = floor($dec%16);
  1546. $c = $escape.$hex[$h2].$hex[$h1];
  1547. }
  1548. if ( (strlen($newline) + strlen($c)) >= $line_max ) { // CRLF is not counted
  1549. $output .= $newline.$escape.$eol; // soft line break; " =\r\n" is okay
  1550. $newline = '';
  1551. // check if newline first character will be point or not
  1552. if ( $dec == 46 ) {
  1553. $c = '=2E';
  1554. }
  1555. }
  1556. $newline .= $c;
  1557. } // end of for
  1558. $output .= $newline.$eol;
  1559. } // end of while
  1560. return $output;
  1561. }
  1562.  
  1563. /**
  1564. * Encode string to RFC2045 (6.7) quoted-printable format
  1565. * Uses a PHP5 stream filter to do the encoding about 64x faster than the old version
  1566. * Also results in same content as you started with after decoding
  1567. * @see EncodeQPphp()
  1568. * @access public
  1569. * @param string $string the text to encode
  1570. * @param integer $line_max Number of chars allowed on a line before wrapping
  1571. * @param boolean $space_conv Dummy param for compatibility with existing EncodeQP function
  1572. * @return string
  1573. * @author Marcus Bointon
  1574. */
  1575. public function EncodeQP($string, $line_max = 76, $space_conv = false) {
  1576. if (function_exists('quoted_printable_encode')) { //Use native function if it's available (>= PHP5.3)
  1577. return quoted_printable_encode($string);
  1578. }
  1579. $filters = stream_get_filters();
  1580. if (!in_array('convert.*', $filters)) { //Got convert stream filter?
  1581. return $this->EncodeQPphp($string, $line_max, $space_conv); //Fall back to old implementation
  1582. }
  1583. $fp = fopen('php://temp/', 'r+');
  1584. $string = preg_replace('/\r\n?/', $this->LE, $string); //Normalise line breaks
  1585. $params = array('line-length' => $line_max, 'line-break-chars' => $this->LE);
  1586. $s = stream_filter_append($fp, 'convert.quoted-printable-encode', STREAM_FILTER_READ, $params);
  1587. fputs($fp, $string);
  1588. rewind($fp);
  1589. $out = stream_get_contents($fp);
  1590. stream_filter_remove($s);
  1591. $out = preg_replace('/^\./m', '=2E', $out); //Encode . if it is first char on a line, workaround for bug in Exchange
  1592. fclose($fp);
  1593. return $out;
  1594. }
  1595.  
  1596. /**
  1597. * Encode string to q encoding.
  1598. * @link http://tools.ietf.org/html/rfc2047
  1599. * @param string $str the text to encode
  1600. * @param string $position Where the text is going to be used, see the RFC for what that means
  1601. * @access public
  1602. * @return string
  1603. */
  1604. public function EncodeQ ($str, $position = 'text') {
  1605. // There should not be any EOL in the string
  1606. $encoded = preg_replace('/[\r\n]*/', '', $str);
  1607.  
  1608. switch (strtolower($position)) {
  1609. case 'phrase':
  1610. $encoded = preg_replace("/([^A-Za-z0-9!*+\/ -])/e", "'='.sprintf('%02X', ord('\\1'))", $encoded);
  1611. break;
  1612. case 'comment':
  1613. $encoded = preg_replace("/([\(\)\"])/e", "'='.sprintf('%02X', ord('\\1'))", $encoded);
  1614. case 'text':
  1615. default:
  1616. // Replace every high ascii, control =, ? and _ characters
  1617. //TODO using /e (equivalent to eval()) is probably not a good idea
  1618. $encoded = preg_replace('/([\000-\011\013\014\016-\037\075\077\137\177-\377])/e',
  1619. "'='.sprintf('%02X', ord('\\1'))", $encoded);
  1620. break;
  1621. }
  1622.  
  1623. // Replace every spaces to _ (more readable than =20)
  1624. $encoded = str_replace(' ', '_', $encoded);
  1625.  
  1626. return $encoded;
  1627. }
  1628.  
  1629. /**
  1630. * Adds a string or binary attachment (non-filesystem) to the list.
  1631. * This method can be used to attach ascii or binary data,
  1632. * such as a BLOB record from a database.
  1633. * @param string $string String attachment data.
  1634. * @param string $filename Name of the attachment.
  1635. * @param string $encoding File encoding (see $Encoding).
  1636. * @param string $type File extension (MIME) type.
  1637. * @return void
  1638. */
  1639. public function AddStringAttachment($string, $filename, $encoding = 'base64', $type = 'application/octet-stream') {
  1640. // Append to $attachment array
  1641. $this->attachment[] = array(
  1642. 0 => $string,
  1643. 1 => $filename,
  1644. 2 => $filename,
  1645. 3 => $encoding,
  1646. 4 => $type,
  1647. 5 => true, // isStringAttachment
  1648. 6 => 'attachment',
  1649. 7 => 0
  1650. );
  1651. }
  1652.  
  1653. /**
  1654. * Adds an embedded attachment. This can include images, sounds, and
  1655. * just about any other document. Make sure to set the $type to an
  1656. * image type. For JPEG images use "image/jpeg" and for GIF images
  1657. * use "image/gif".
  1658. * @param string $path Path to the attachment.
  1659. * @param string $cid Content ID of the attachment. Use this to identify
  1660. * the Id for accessing the image in an HTML form.
  1661. * @param string $name Overrides the attachment name.
  1662. * @param string $encoding File encoding (see $Encoding).
  1663. * @param string $type File extension (MIME) type.
  1664. * @return bool
  1665. */
  1666. public function AddEmbeddedImage($path, $cid, $name = '', $encoding = 'base64', $type = 'application/octet-stream') {
  1667.  
  1668. if ( !@is_file($path) ) {
  1669. $this->SetError($this->Lang('file_access') . $path);
  1670. return false;
  1671. }
  1672.  
  1673. $filename = basename($path);
  1674. if ( $name == '' ) {
  1675. $name = $filename;
  1676. }
  1677.  
  1678. // Append to $attachment array
  1679. $this->attachment[] = array(
  1680. 0 => $path,
  1681. 1 => $filename,
  1682. 2 => $name,
  1683. 3 => $encoding,
  1684. 4 => $type,
  1685. 5 => false, // isStringAttachment
  1686. 6 => 'inline',
  1687. 7 => $cid
  1688. );
  1689.  
  1690. return true;
  1691. }
  1692.  
  1693. /**
  1694. * Returns true if an inline attachment is present.
  1695. * @access public
  1696. * @return bool
  1697. */
  1698. public function InlineImageExists() {
  1699. foreach($this->attachment as $attachment) {
  1700. if ($attachment[6] == 'inline') {
  1701. return true;
  1702. }
  1703. }
  1704. return false;
  1705. }
  1706.  
  1707. /////////////////////////////////////////////////
  1708. // CLASS METHODS, MESSAGE RESET
  1709. /////////////////////////////////////////////////
  1710.  
  1711.  
  1712. /**
  1713. * Clears all recipients assigned in the TO array. Returns void.
  1714. * @return void
  1715. */
  1716. public function ClearAddresses() {
  1717. foreach($this->to as $to) {
  1718. unset($this->all_recipients[strtolower($to[0])]);
  1719. }
  1720. $this->to = array();
  1721. }
  1722.  
  1723. /**
  1724. * Clears all recipients assigned in the CC array. Returns void.
  1725. * @return void
  1726. */
  1727. public function ClearCCs() {
  1728. foreach($this->cc as $cc) {
  1729. unset($this->all_recipients[strtolower($cc[0])]);
  1730. }
  1731. $this->cc = array();
  1732. }
  1733.  
  1734. /**
  1735. * Clears all recipients assigned in the BCC array. Returns void.
  1736. * @return void
  1737. */
  1738. public function ClearBCCs() {
  1739. foreach($this->bcc as $bcc) {
  1740. unset($this->all_recipients[strtolower($bcc[0])]);
  1741. }
  1742. $this->bcc = array();
  1743. }
  1744.  
  1745. /**
  1746. * Clears all recipients assigned in the ReplyTo array. Returns void.
  1747. * @return void
  1748. */
  1749. public function ClearReplyTos() {
  1750. $this->ReplyTo = array();
  1751. }
  1752.  
  1753. /**
  1754. * Clears all recipients assigned in the TO, CC and BCC
  1755. * array. Returns void.
  1756. * @return void
  1757. */
  1758. public function ClearAllRecipients() {
  1759. $this->to = array();
  1760. $this->cc = array();
  1761. $this->bcc = array();
  1762. $this->all_recipients = array();
  1763. }
  1764.  
  1765. /**
  1766. * Clears all previously set filesystem, string, and binary
  1767. * attachments. Returns void.
  1768. * @return void
  1769. */
  1770. public function ClearAttachments() {
  1771. $this->attachment = array();
  1772. }
  1773.  
  1774. /**
  1775. * Clears all custom headers. Returns void.
  1776. * @return void
  1777. */
  1778. public function ClearCustomHeaders() {
  1779. $this->CustomHeader = array();
  1780. }
  1781.  
  1782. /////////////////////////////////////////////////
  1783. // CLASS METHODS, MISCELLANEOUS
  1784. /////////////////////////////////////////////////
  1785.  
  1786.  
  1787. /**
  1788. * Adds the error message to the error container.
  1789. * @access protected
  1790. * @return void
  1791. */
  1792. protected function SetError($msg) {
  1793. $this->error_count++;
  1794. if ($this->Mailer == 'smtp' and !is_null($this->smtp)) {
  1795. $lasterror = $this->smtp->getError();
  1796. if (!empty($lasterror) and array_key_exists('smtp_msg', $lasterror)) {
  1797. $msg .= '<p>' . $this->Lang('smtp_error') . $lasterror['smtp_msg'] . "</p>\n";
  1798. }
  1799. }
  1800. $this->ErrorInfo = $msg;
  1801. }
  1802.  
  1803. /**
  1804. * Returns the proper RFC 822 formatted date.
  1805. * @access public
  1806. * @return string
  1807. * @static
  1808. */
  1809. public static function RFCDate() {
  1810. $tz = date('Z');
  1811. $tzs = ($tz < 0) ? '-' : '+';
  1812. $tz = abs($tz);
  1813. $tz = (int)($tz/3600)*100 + ($tz%3600)/60;
  1814. $result = sprintf("%s %s%04d", date('D, j M Y H:i:s'), $tzs, $tz);
  1815.  
  1816. return $result;
  1817. }
  1818.  
  1819. /**
  1820. * Returns the server hostname or 'localhost.localdomain' if unknown.
  1821. * @access private
  1822. * @return string
  1823. */
  1824. private function ServerHostname() {
  1825. if (!empty($this->Hostname)) {
  1826. $result = $this->Hostname;
  1827. } elseif (isset($_SERVER['SERVER_NAME'])) {
  1828. $result = $_SERVER['SERVER_NAME'];
  1829. } else {
  1830. $result = 'localhost.localdomain';
  1831. }
  1832.  
  1833. return $result;
  1834. }
  1835.  
  1836. /**
  1837. * Returns a message in the appropriate language.
  1838. * @access private
  1839. * @return string
  1840. */
  1841. private function Lang($key) {
  1842. if(count($this->language) < 1) {
  1843. $this->SetLanguage('en'); // set the default language
  1844. }
  1845.  
  1846. if(isset($this->language[$key])) {
  1847. return $this->language[$key];
  1848. } else {
  1849. return 'Language string failed to load: ' . $key;
  1850. }
  1851. }
  1852.  
  1853. /**
  1854. * Returns true if an error occurred.
  1855. * @access public
  1856. * @return bool
  1857. */
  1858. public function IsError() {
  1859. return ($this->error_count > 0);
  1860. }
  1861.  
  1862. /**
  1863. * Changes every end of line from CR or LF to CRLF.
  1864. * @access private
  1865. * @return string
  1866. */
  1867. private function FixEOL($str) {
  1868. $str = str_replace("\r\n", "\n", $str);
  1869. $str = str_replace("\r", "\n", $str);
  1870. $str = str_replace("\n", $this->LE, $str);
  1871. return $str;
  1872. }
  1873.  
  1874. /**
  1875. * Adds a custom header.
  1876. * @access public
  1877. * @return void
  1878. */
  1879. public function AddCustomHeader($custom_header) {
  1880. $this->CustomHeader[] = explode(':', $custom_header, 2);
  1881. }
  1882.  
  1883. /**
  1884. * Evaluates the message and returns modifications for inline images and backgrounds
  1885. * @access public
  1886. * @return $message
  1887. */
  1888. public function MsgHTML($message, $basedir = '') {
  1889. preg_match_all("/(src|background)=\"(.*)\"/Ui", $message, $images);
  1890. if(isset($images[2])) {
  1891. foreach($images[2] as $i => $url) {
  1892. // do not change urls for absolute images (thanks to corvuscorax)
  1893. if (!preg_match('#^[A-z]+://#',$url)) {
  1894. $filename = basename($url);
  1895. $directory = dirname($url);
  1896. ($directory == '.')?$directory='':'';
  1897. $cid = 'cid:' . md5($filename);
  1898. $ext = pathinfo($filename, PATHINFO_EXTENSION);
  1899. $mimeType = self::_mime_types($ext);
  1900. if ( strlen($basedir) > 1 && substr($basedir,-1) != '/') { $basedir .= '/'; }
  1901. if ( strlen($directory) > 1 && substr($directory,-1) != '/') { $directory .= '/'; }
  1902. if ( $this->AddEmbeddedImage($basedir.$directory.$filename, md5($filename), $filename, 'base64',$mimeType) ) {
  1903. $message = preg_replace("/".$images[1][$i]."=\"".preg_quote($url, '/')."\"/Ui", $images[1][$i]."=\"".$cid."\"", $message);
  1904. }
  1905. }
  1906. }
  1907. }
  1908. $this->IsHTML(true);
  1909. $this->Body = $message;
  1910. $textMsg = trim(strip_tags(preg_replace('/<(head|title|style|script)[^>]*>.*?<\/\\1>/s','',$message)));
  1911. if (!empty($textMsg) && empty($this->AltBody)) {
  1912. $this->AltBody = html_entity_decode($textMsg);
  1913. }
  1914. if (empty($this->AltBody)) {
  1915. $this->AltBody = 'To view this email message, open it in a program that understands HTML!' . "\n\n";
  1916. }
  1917. }
  1918.  
  1919. /**
  1920. * Gets the MIME type of the embedded or inline image
  1921. * @param string File extension
  1922. * @access public
  1923. * @return string MIME type of ext
  1924. * @static
  1925. */
  1926. public static function _mime_types($ext = '') {
  1927. $mimes = array(
  1928. 'hqx' => 'application/mac-binhex40',
  1929. 'cpt' => 'application/mac-compactpro',
  1930. 'doc' => 'application/msword',
  1931. 'bin' => 'application/macbinary',
  1932. 'dms' => 'application/octet-stream',
  1933. 'lha' => 'application/octet-stream',
  1934. 'lzh' => 'application/octet-stream',
  1935. 'exe' => 'application/octet-stream',
  1936. 'class' => 'application/octet-stream',
  1937. 'psd' => 'application/octet-stream',
  1938. 'so' => 'application/octet-stream',
  1939. 'sea' => 'application/octet-stream',
  1940. 'dll' => 'application/octet-stream',
  1941. 'oda' => 'application/oda',
  1942. 'pdf' => 'application/pdf',
  1943. 'ai' => 'application/postscript',
  1944. 'eps' => 'application/postscript',
  1945. 'ps' => 'application/postscript',
  1946. 'smi' => 'application/smil',
  1947. 'smil' => 'application/smil',
  1948. 'mif' => 'application/vnd.mif',
  1949. 'xls' => 'application/vnd.ms-excel',
  1950. 'ppt' => 'application/vnd.ms-powerpoint',
  1951. 'wbxml' => 'application/vnd.wap.wbxml',
  1952. 'wmlc' => 'application/vnd.wap.wmlc',
  1953. 'dcr' => 'application/x-director',
  1954. 'dir' => 'application/x-director',
  1955. 'dxr' => 'application/x-director',
  1956. 'dvi' => 'application/x-dvi',
  1957. 'gtar' => 'application/x-gtar',
  1958. 'php' => 'application/x-httpd-php',
  1959. 'php4' => 'application/x-httpd-php',
  1960. 'php3' => 'application/x-httpd-php',
  1961. 'phtml' => 'application/x-httpd-php',
  1962. 'phps' => 'application/x-httpd-php-source',
  1963. 'js' => 'application/x-javascript',
  1964. 'swf' => 'application/x-shockwave-flash',
  1965. 'sit' => 'application/x-stuffit',
  1966. 'tar' => 'application/x-tar',
  1967. 'tgz' => 'application/x-tar',
  1968. 'xhtml' => 'application/xhtml+xml',
  1969. 'xht' => 'application/xhtml+xml',
  1970. 'zip' => 'application/zip',
  1971. 'mid' => 'audio/midi',
  1972. 'midi' => 'audio/midi',
  1973. 'mpga' => 'audio/mpeg',
  1974. 'mp2' => 'audio/mpeg',
  1975. 'mp3' => 'audio/mpeg',
  1976. 'aif' => 'audio/x-aiff',
  1977. 'aiff' => 'audio/x-aiff',
  1978. 'aifc' => 'audio/x-aiff',
  1979. 'ram' => 'audio/x-pn-realaudio',
  1980. 'rm' => 'audio/x-pn-realaudio',
  1981. 'rpm' => 'audio/x-pn-realaudio-plugin',
  1982. 'ra' => 'audio/x-realaudio',
  1983. 'rv' => 'video/vnd.rn-realvideo',
  1984. 'wav' => 'audio/x-wav',
  1985. 'bmp' => 'image/bmp',
  1986. 'gif' => 'image/gif',
  1987. 'jpeg' => 'image/jpeg',
  1988. 'jpg' => 'image/jpeg',
  1989. 'jpe' => 'image/jpeg',
  1990. 'png' => 'image/png',
  1991. 'tiff' => 'image/tiff',
  1992. 'tif' => 'image/tiff',
  1993. 'css' => 'text/css',
  1994. 'html' => 'text/html',
  1995. 'htm' => 'text/html',
  1996. 'shtml' => 'text/html',
  1997. 'txt' => 'text/plain',
  1998. 'text' => 'text/plain',
  1999. 'log' => 'text/plain',
  2000. 'rtx' => 'text/richtext',
  2001. 'rtf' => 'text/rtf',
  2002. 'xml' => 'text/xml',
  2003. 'xsl' => 'text/xml',
  2004. 'mpeg' => 'video/mpeg',
  2005. 'mpg' => 'video/mpeg',
  2006. 'mpe' => 'video/mpeg',
  2007. 'qt' => 'video/quicktime',
  2008. 'mov' => 'video/quicktime',
  2009. 'avi' => 'video/x-msvideo',
  2010. 'movie' => 'video/x-sgi-movie',
  2011. 'doc' => 'application/msword',
  2012. 'word' => 'application/msword',
  2013. 'xl' => 'application/excel',
  2014. 'eml' => 'message/rfc822'
  2015. );
  2016. return (!isset($mimes[strtolower($ext)])) ? 'application/octet-stream' : $mimes[strtolower($ext)];
  2017. }
  2018.  
  2019. /**
  2020. * Set (or reset) Class Objects (variables)
  2021. *
  2022. * Usage Example:
  2023. * $page->set('X-Priority', '3');
  2024. *
  2025. * @access public
  2026. * @param string $name Parameter Name
  2027. * @param mixed $value Parameter Value
  2028. * NOTE: will not work with arrays, there are no arrays to set/reset
  2029. * @todo Should this not be using __set() magic function?
  2030. */
  2031. public function set($name, $value = '') {
  2032. try {
  2033. if (isset($this->$name) ) {
  2034. $this->$name = $value;
  2035. } else {
  2036. throw new phpmailerException($this->Lang('variable_set') . $name, self::STOP_CRITICAL);
  2037. }
  2038. } catch (Exception $e) {
  2039. $this->SetError($e->getMessage());
  2040. if ($e->getCode() == self::STOP_CRITICAL) {
  2041. return false;
  2042. }
  2043. }
  2044. return true;
  2045. }
  2046.  
  2047. /**
  2048. * Strips newlines to prevent header injection.
  2049. * @access public
  2050. * @param string $str String
  2051. * @return string
  2052. */
  2053. public function SecureHeader($str) {
  2054. $str = str_replace("\r", '', $str);
  2055. $str = str_replace("\n", '', $str);
  2056. return trim($str);
  2057. }
  2058.  
  2059. /**
  2060. * Set the private key file and password to sign the message.
  2061. *
  2062. * @access public
  2063. * @param string $key_filename Parameter File Name
  2064. * @param string $key_pass Password for private key
  2065. */
  2066. public function Sign($cert_filename, $key_filename, $key_pass) {
  2067. $this->sign_cert_file = $cert_filename;
  2068. $this->sign_key_file = $key_filename;
  2069. $this->sign_key_pass = $key_pass;
  2070. }
  2071. }
  2072.  
  2073. class phpmailerException extends Exception {
  2074. public function errorMessage() {
  2075. $errorMsg = '<strong>' . $this->getMessage() . "</strong><br />\n";
  2076. return $errorMsg;
  2077. }
  2078. }
  2079. ?>

Documentation generated on Thu, 02 Apr 2009 17:51:25 -0400 by phpDocumentor 1.3.0RC3