Guest User

Untitled

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