PageRenderTime 57ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 1ms

/vendor/PHPMailer/class.phpmailer.php

https://github.com/scogle/cockpit
PHP | 3419 lines | 2005 code | 230 blank | 1184 comment | 344 complexity | 48552a8e0d5d7dae7d6f855bf19f8e50 MD5 | raw file
Possible License(s): LGPL-2.1
  1. <?php
  2. /**
  3. * PHPMailer - PHP email creation and transport class.
  4. * PHP Version 5
  5. * @package PHPMailer
  6. * @link https://github.com/PHPMailer/PHPMailer/ The PHPMailer GitHub project
  7. * @author Marcus Bointon (Synchro/coolbru) <phpmailer@synchromedia.co.uk>
  8. * @author Jim Jagielski (jimjag) <jimjag@gmail.com>
  9. * @author Andy Prevost (codeworxtech) <codeworxtech@users.sourceforge.net>
  10. * @author Brent R. Matzelle (original founder)
  11. * @copyright 2012 - 2014 Marcus Bointon
  12. * @copyright 2010 - 2012 Jim Jagielski
  13. * @copyright 2004 - 2009 Andy Prevost
  14. * @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
  15. * @note This program is distributed in the hope that it will be useful - WITHOUT
  16. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  17. * FITNESS FOR A PARTICULAR PURPOSE.
  18. */
  19. /**
  20. * PHPMailer - PHP email creation and transport class.
  21. * @package PHPMailer
  22. * @author Marcus Bointon (Synchro/coolbru) <phpmailer@synchromedia.co.uk>
  23. * @author Jim Jagielski (jimjag) <jimjag@gmail.com>
  24. * @author Andy Prevost (codeworxtech) <codeworxtech@users.sourceforge.net>
  25. * @author Brent R. Matzelle (original founder)
  26. */
  27. class PHPMailer
  28. {
  29. /**
  30. * The PHPMailer Version number.
  31. * @type string
  32. */
  33. public $Version = '5.2.7';
  34. /**
  35. * Email priority.
  36. * Options: 1 = High, 3 = Normal, 5 = low.
  37. * @type int
  38. */
  39. public $Priority = 3;
  40. /**
  41. * The character set of the message.
  42. * @type string
  43. */
  44. public $CharSet = 'iso-8859-1';
  45. /**
  46. * The MIME Content-type of the message.
  47. * @type string
  48. */
  49. public $ContentType = 'text/plain';
  50. /**
  51. * The message encoding.
  52. * Options: "8bit", "7bit", "binary", "base64", and "quoted-printable".
  53. * @type string
  54. */
  55. public $Encoding = '8bit';
  56. /**
  57. * Holds the most recent mailer error message.
  58. * @type string
  59. */
  60. public $ErrorInfo = '';
  61. /**
  62. * The From email address for the message.
  63. * @type string
  64. */
  65. public $From = 'root@localhost';
  66. /**
  67. * The From name of the message.
  68. * @type string
  69. */
  70. public $FromName = 'Root User';
  71. /**
  72. * The Sender email (Return-Path) of the message.
  73. * If not empty, will be sent via -f to sendmail or as 'MAIL FROM' in smtp mode.
  74. * @type string
  75. */
  76. public $Sender = '';
  77. /**
  78. * The Return-Path of the message.
  79. * If empty, it will be set to either From or Sender.
  80. * @type string
  81. * @deprecated Email senders should never set a return-path header;
  82. * it's the receiver's job (RFC5321 section 4.4), so this no longer does anything.
  83. * @link https://tools.ietf.org/html/rfc5321#section-4.4 RFC5321 reference
  84. */
  85. public $ReturnPath = '';
  86. /**
  87. * The Subject of the message.
  88. * @type string
  89. */
  90. public $Subject = '';
  91. /**
  92. * An HTML or plain text message body.
  93. * If HTML then call isHTML(true).
  94. * @type string
  95. */
  96. public $Body = '';
  97. /**
  98. * The plain-text message body.
  99. * This body can be read by mail clients that do not have HTML email
  100. * capability such as mutt & Eudora.
  101. * Clients that can read HTML will view the normal Body.
  102. * @type string
  103. */
  104. public $AltBody = '';
  105. /**
  106. * An iCal message part body.
  107. * Only supported in simple alt or alt_inline message types
  108. * To generate iCal events, use the bundled extras/EasyPeasyICS.php class or iCalcreator
  109. * @link http://sprain.ch/blog/downloads/php-class-easypeasyics-create-ical-files-with-php/
  110. * @link http://kigkonsult.se/iCalcreator/
  111. * @type string
  112. */
  113. public $Ical = '';
  114. /**
  115. * The complete compiled MIME message body.
  116. * @access protected
  117. * @type string
  118. */
  119. protected $MIMEBody = '';
  120. /**
  121. * The complete compiled MIME message headers.
  122. * @type string
  123. * @access protected
  124. */
  125. protected $MIMEHeader = '';
  126. /**
  127. * Extra headers that createHeader() doesn't fold in.
  128. * @type string
  129. * @access protected
  130. */
  131. protected $mailHeader = '';
  132. /**
  133. * Word-wrap the message body to this number of chars.
  134. * @type int
  135. */
  136. public $WordWrap = 0;
  137. /**
  138. * Which method to use to send mail.
  139. * Options: "mail", "sendmail", or "smtp".
  140. * @type string
  141. */
  142. public $Mailer = 'mail';
  143. /**
  144. * The path to the sendmail program.
  145. * @type string
  146. */
  147. public $Sendmail = '/usr/sbin/sendmail';
  148. /**
  149. * Whether mail() uses a fully sendmail-compatible MTA.
  150. * One which supports sendmail's "-oi -f" options.
  151. * @type bool
  152. */
  153. public $UseSendmailOptions = true;
  154. /**
  155. * Path to PHPMailer plugins.
  156. * Useful if the SMTP class is not in the PHP include path.
  157. * @type string
  158. * @deprecated Should not be needed now there is an autoloader.
  159. */
  160. public $PluginDir = '';
  161. /**
  162. * The email address that a reading confirmation should be sent to.
  163. * @type string
  164. */
  165. public $ConfirmReadingTo = '';
  166. /**
  167. * The hostname to use in Message-Id and Received headers
  168. * and as default HELO string.
  169. * If empty, the value returned
  170. * by SERVER_NAME is used or 'localhost.localdomain'.
  171. * @type string
  172. */
  173. public $Hostname = '';
  174. /**
  175. * An ID to be used in the Message-Id header.
  176. * If empty, a unique id will be generated.
  177. * @type string
  178. */
  179. public $MessageID = '';
  180. /**
  181. * The message Date to be used in the Date header.
  182. * If empty, the current date will be added.
  183. * @type string
  184. */
  185. public $MessageDate = '';
  186. /**
  187. * SMTP hosts.
  188. * Either a single hostname or multiple semicolon-delimited hostnames.
  189. * You can also specify a different port
  190. * for each host by using this format: [hostname:port]
  191. * (e.g. "smtp1.example.com:25;smtp2.example.com").
  192. * Hosts will be tried in order.
  193. * @type string
  194. */
  195. public $Host = 'localhost';
  196. /**
  197. * The default SMTP server port.
  198. * @type int
  199. * @Todo Why is this needed when the SMTP class takes care of it?
  200. */
  201. public $Port = 25;
  202. /**
  203. * The SMTP HELO of the message.
  204. * Default is $Hostname.
  205. * @type string
  206. * @see PHPMailer::$Hostname
  207. */
  208. public $Helo = '';
  209. /**
  210. * The secure connection prefix.
  211. * Options: "", "ssl" or "tls"
  212. * @type string
  213. */
  214. public $SMTPSecure = '';
  215. /**
  216. * Whether to use SMTP authentication.
  217. * Uses the Username and Password properties.
  218. * @type bool
  219. * @see PHPMailer::$Username
  220. * @see PHPMailer::$Password
  221. */
  222. public $SMTPAuth = false;
  223. /**
  224. * SMTP username.
  225. * @type string
  226. */
  227. public $Username = '';
  228. /**
  229. * SMTP password.
  230. * @type string
  231. */
  232. public $Password = '';
  233. /**
  234. * SMTP auth type.
  235. * Options are LOGIN (default), PLAIN, NTLM, CRAM-MD5
  236. * @type string
  237. */
  238. public $AuthType = '';
  239. /**
  240. * SMTP realm.
  241. * Used for NTLM auth
  242. * @type string
  243. */
  244. public $Realm = '';
  245. /**
  246. * SMTP workstation.
  247. * Used for NTLM auth
  248. * @type string
  249. */
  250. public $Workstation = '';
  251. /**
  252. * The SMTP server timeout in seconds.
  253. * @type int
  254. */
  255. public $Timeout = 10;
  256. /**
  257. * SMTP class debug output mode.
  258. * Options:
  259. * 0: no output
  260. * 1: commands
  261. * 2: data and commands
  262. * 3: as 2 plus connection status
  263. * 4: low level data output
  264. * @type int
  265. * @see SMTP::$do_debug
  266. */
  267. public $SMTPDebug = 0;
  268. /**
  269. * How to handle debug output.
  270. * Options:
  271. * 'echo': Output plain-text as-is, appropriate for CLI
  272. * 'html': Output escaped, line breaks converted to <br>, appropriate for browser output
  273. * 'error_log': Output to error log as configured in php.ini
  274. * @type string
  275. * @see SMTP::$Debugoutput
  276. */
  277. public $Debugoutput = 'echo';
  278. /**
  279. * Whether to keep SMTP connection open after each message.
  280. * If this is set to true then to close the connection
  281. * requires an explicit call to smtpClose().
  282. * @type bool
  283. */
  284. public $SMTPKeepAlive = false;
  285. /**
  286. * Whether to split multiple to addresses into multiple messages
  287. * or send them all in one message.
  288. * @type bool
  289. */
  290. public $SingleTo = false;
  291. /**
  292. * Storage for addresses when SingleTo is enabled.
  293. * @type array
  294. * @todo This should really not be public
  295. */
  296. public $SingleToArray = array();
  297. /**
  298. * Whether to generate VERP addresses on send.
  299. * Only applicable when sending via SMTP.
  300. * @link http://en.wikipedia.org/wiki/Variable_envelope_return_path
  301. * @link http://www.postfix.org/VERP_README.html Postfix VERP info
  302. * @type bool
  303. */
  304. public $do_verp = false;
  305. /**
  306. * Whether to allow sending messages with an empty body.
  307. * @type bool
  308. */
  309. public $AllowEmpty = false;
  310. /**
  311. * The default line ending.
  312. * @note The default remains "\n". We force CRLF where we know
  313. * it must be used via self::CRLF.
  314. * @type string
  315. */
  316. public $LE = "\n";
  317. /**
  318. * DKIM selector.
  319. * @type string
  320. */
  321. public $DKIM_selector = '';
  322. /**
  323. * DKIM Identity.
  324. * Usually the email address used as the source of the email
  325. * @type string
  326. */
  327. public $DKIM_identity = '';
  328. /**
  329. * DKIM passphrase.
  330. * Used if your key is encrypted.
  331. * @type string
  332. */
  333. public $DKIM_passphrase = '';
  334. /**
  335. * DKIM signing domain name.
  336. * @example 'example.com'
  337. * @type string
  338. */
  339. public $DKIM_domain = '';
  340. /**
  341. * DKIM private key file path.
  342. * @type string
  343. */
  344. public $DKIM_private = '';
  345. /**
  346. * Callback Action function name.
  347. *
  348. * The function that handles the result of the send email action.
  349. * It is called out by send() for each email sent.
  350. *
  351. * Value can be any php callable: http://www.php.net/is_callable
  352. *
  353. * Parameters:
  354. * bool $result result of the send action
  355. * string $to email address of the recipient
  356. * string $cc cc email addresses
  357. * string $bcc bcc email addresses
  358. * string $subject the subject
  359. * string $body the email body
  360. * string $from email address of sender
  361. * @type string
  362. */
  363. public $action_function = '';
  364. /**
  365. * What to use in the X-Mailer header.
  366. * Options: null for default, whitespace for none, or a string to use
  367. * @type string
  368. */
  369. public $XMailer = '';
  370. /**
  371. * An instance of the SMTP sender class.
  372. * @type SMTP
  373. * @access protected
  374. */
  375. protected $smtp = null;
  376. /**
  377. * The array of 'to' addresses.
  378. * @type array
  379. * @access protected
  380. */
  381. protected $to = array();
  382. /**
  383. * The array of 'cc' addresses.
  384. * @type array
  385. * @access protected
  386. */
  387. protected $cc = array();
  388. /**
  389. * The array of 'bcc' addresses.
  390. * @type array
  391. * @access protected
  392. */
  393. protected $bcc = array();
  394. /**
  395. * The array of reply-to names and addresses.
  396. * @type array
  397. * @access protected
  398. */
  399. protected $ReplyTo = array();
  400. /**
  401. * An array of all kinds of addresses.
  402. * Includes all of $to, $cc, $bcc, $replyto
  403. * @type array
  404. * @access protected
  405. */
  406. protected $all_recipients = array();
  407. /**
  408. * The array of attachments.
  409. * @type array
  410. * @access protected
  411. */
  412. protected $attachment = array();
  413. /**
  414. * The array of custom headers.
  415. * @type array
  416. * @access protected
  417. */
  418. protected $CustomHeader = array();
  419. /**
  420. * The most recent Message-ID (including angular brackets).
  421. * @type string
  422. * @access protected
  423. */
  424. protected $lastMessageID = '';
  425. /**
  426. * The message's MIME type.
  427. * @type string
  428. * @access protected
  429. */
  430. protected $message_type = '';
  431. /**
  432. * The array of MIME boundary strings.
  433. * @type array
  434. * @access protected
  435. */
  436. protected $boundary = array();
  437. /**
  438. * The array of available languages.
  439. * @type array
  440. * @access protected
  441. */
  442. protected $language = array();
  443. /**
  444. * The number of errors encountered.
  445. * @type integer
  446. * @access protected
  447. */
  448. protected $error_count = 0;
  449. /**
  450. * The S/MIME certificate file path.
  451. * @type string
  452. * @access protected
  453. */
  454. protected $sign_cert_file = '';
  455. /**
  456. * The S/MIME key file path.
  457. * @type string
  458. * @access protected
  459. */
  460. protected $sign_key_file = '';
  461. /**
  462. * The S/MIME password for the key.
  463. * Used only if the key is encrypted.
  464. * @type string
  465. * @access protected
  466. */
  467. protected $sign_key_pass = '';
  468. /**
  469. * Whether to throw exceptions for errors.
  470. * @type bool
  471. * @access protected
  472. */
  473. protected $exceptions = false;
  474. /**
  475. * Error severity: message only, continue processing
  476. */
  477. const STOP_MESSAGE = 0;
  478. /**
  479. * Error severity: message, likely ok to continue processing
  480. */
  481. const STOP_CONTINUE = 1;
  482. /**
  483. * Error severity: message, plus full stop, critical error reached
  484. */
  485. const STOP_CRITICAL = 2;
  486. /**
  487. * SMTP RFC standard line ending
  488. */
  489. const CRLF = "\r\n";
  490. /**
  491. * Constructor
  492. * @param bool $exceptions Should we throw external exceptions?
  493. */
  494. public function __construct($exceptions = false)
  495. {
  496. if (version_compare(PHP_VERSION, '5.0.0', '<')) {
  497. exit("Sorry, PHPMailer will only run on PHP version 5 or greater!\n");
  498. }
  499. $this->exceptions = ($exceptions == true);
  500. //Make sure our autoloader is loaded
  501. if (version_compare(PHP_VERSION, '5.1.2', '>=')) {
  502. $autoload = spl_autoload_functions();
  503. if ($autoload === false or !in_array('PHPMailerAutoload', $autoload)) {
  504. require 'PHPMailerAutoload.php';
  505. }
  506. }
  507. }
  508. /**
  509. * Destructor.
  510. */
  511. public function __destruct()
  512. {
  513. if ($this->Mailer == 'smtp') { //close any open SMTP connection nicely
  514. $this->smtpClose();
  515. }
  516. }
  517. /**
  518. * Call mail() in a safe_mode-aware fashion.
  519. * Also, unless sendmail_path points to sendmail (or something that
  520. * claims to be sendmail), don't pass params (not a perfect fix,
  521. * but it will do)
  522. * @param string $to To
  523. * @param string $subject Subject
  524. * @param string $body Message Body
  525. * @param string $header Additional Header(s)
  526. * @param string $params Params
  527. * @access private
  528. * @return bool
  529. */
  530. private function mailPassthru($to, $subject, $body, $header, $params)
  531. {
  532. //Check overloading of mail function to avoid double-encoding
  533. if (ini_get('mbstring.func_overload') & 1) {
  534. $subject = $this->secureHeader($subject);
  535. } else {
  536. $subject = $this->encodeHeader($this->secureHeader($subject));
  537. }
  538. if (ini_get('safe_mode') || !($this->UseSendmailOptions)) {
  539. $result = @mail($to, $subject, $body, $header);
  540. } else {
  541. $result = @mail($to, $subject, $body, $header, $params);
  542. }
  543. return $result;
  544. }
  545. /**
  546. * Output debugging info via user-defined method.
  547. * Only if debug output is enabled.
  548. * @see PHPMailer::$Debugoutput
  549. * @see PHPMailer::$SMTPDebug
  550. * @param string $str
  551. */
  552. protected function edebug($str)
  553. {
  554. if (!$this->SMTPDebug) {
  555. return;
  556. }
  557. switch ($this->Debugoutput) {
  558. case 'error_log':
  559. error_log($str);
  560. break;
  561. case 'html':
  562. //Cleans up output a bit for a better looking display that's HTML-safe
  563. echo htmlentities(preg_replace('/[\r\n]+/', '', $str), ENT_QUOTES, $this->CharSet) . "<br>\n";
  564. break;
  565. case 'echo':
  566. default:
  567. echo $str."\n";
  568. }
  569. }
  570. /**
  571. * Sets message type to HTML or plain.
  572. * @param bool $ishtml True for HTML mode.
  573. * @return void
  574. */
  575. public function isHTML($ishtml = true)
  576. {
  577. if ($ishtml) {
  578. $this->ContentType = 'text/html';
  579. } else {
  580. $this->ContentType = 'text/plain';
  581. }
  582. }
  583. /**
  584. * Send messages using SMTP.
  585. * @return void
  586. */
  587. public function isSMTP()
  588. {
  589. $this->Mailer = 'smtp';
  590. }
  591. /**
  592. * Send messages using PHP's mail() function.
  593. * @return void
  594. */
  595. public function isMail()
  596. {
  597. $this->Mailer = 'mail';
  598. }
  599. /**
  600. * Send messages using $Sendmail.
  601. * @return void
  602. */
  603. public function isSendmail()
  604. {
  605. $ini_sendmail_path = ini_get('sendmail_path');
  606. if (!stristr($ini_sendmail_path, 'sendmail')) {
  607. $this->Sendmail = '/usr/sbin/sendmail';
  608. } else {
  609. $this->Sendmail = $ini_sendmail_path;
  610. }
  611. $this->Mailer = 'sendmail';
  612. }
  613. /**
  614. * Send messages using qmail.
  615. * @return void
  616. */
  617. public function isQmail()
  618. {
  619. $ini_sendmail_path = ini_get('sendmail_path');
  620. if (!stristr($ini_sendmail_path, 'qmail')) {
  621. $this->Sendmail = '/var/qmail/bin/qmail-inject';
  622. } else {
  623. $this->Sendmail = $ini_sendmail_path;
  624. }
  625. $this->Mailer = 'qmail';
  626. }
  627. /**
  628. * Add a "To" address.
  629. * @param string $address
  630. * @param string $name
  631. * @return bool true on success, false if address already used
  632. */
  633. public function addAddress($address, $name = '')
  634. {
  635. return $this->addAnAddress('to', $address, $name);
  636. }
  637. /**
  638. * Add a "CC" address.
  639. * @note: This function works with the SMTP mailer on win32, not with the "mail" mailer.
  640. * @param string $address
  641. * @param string $name
  642. * @return bool true on success, false if address already used
  643. */
  644. public function addCC($address, $name = '')
  645. {
  646. return $this->addAnAddress('cc', $address, $name);
  647. }
  648. /**
  649. * Add a "BCC" address.
  650. * @note: This function works with the SMTP mailer on win32, not with the "mail" mailer.
  651. * @param string $address
  652. * @param string $name
  653. * @return bool true on success, false if address already used
  654. */
  655. public function addBCC($address, $name = '')
  656. {
  657. return $this->addAnAddress('bcc', $address, $name);
  658. }
  659. /**
  660. * Add a "Reply-to" address.
  661. * @param string $address
  662. * @param string $name
  663. * @return bool
  664. */
  665. public function addReplyTo($address, $name = '')
  666. {
  667. return $this->addAnAddress('Reply-To', $address, $name);
  668. }
  669. /**
  670. * Add an address to one of the recipient arrays.
  671. * Addresses that have been added already return false, but do not throw exceptions
  672. * @param string $kind One of 'to', 'cc', 'bcc', 'ReplyTo'
  673. * @param string $address The email address to send to
  674. * @param string $name
  675. * @throws phpmailerException
  676. * @return bool true on success, false if address already used or invalid in some way
  677. * @access protected
  678. */
  679. protected function addAnAddress($kind, $address, $name = '')
  680. {
  681. if (!preg_match('/^(to|cc|bcc|Reply-To)$/', $kind)) {
  682. $this->setError($this->lang('Invalid recipient array') . ': ' . $kind);
  683. $this->edebug($this->lang('Invalid recipient array') . ': ' . $kind);
  684. if ($this->exceptions) {
  685. throw new phpmailerException('Invalid recipient array: ' . $kind);
  686. }
  687. return false;
  688. }
  689. $address = trim($address);
  690. $name = trim(preg_replace('/[\r\n]+/', '', $name)); //Strip breaks and trim
  691. if (!$this->validateAddress($address)) {
  692. $this->setError($this->lang('invalid_address') . ': ' . $address);
  693. $this->edebug($this->lang('invalid_address') . ': ' . $address);
  694. if ($this->exceptions) {
  695. throw new phpmailerException($this->lang('invalid_address') . ': ' . $address);
  696. }
  697. return false;
  698. }
  699. if ($kind != 'Reply-To') {
  700. if (!isset($this->all_recipients[strtolower($address)])) {
  701. array_push($this->$kind, array($address, $name));
  702. $this->all_recipients[strtolower($address)] = true;
  703. return true;
  704. }
  705. } else {
  706. if (!array_key_exists(strtolower($address), $this->ReplyTo)) {
  707. $this->ReplyTo[strtolower($address)] = array($address, $name);
  708. return true;
  709. }
  710. }
  711. return false;
  712. }
  713. /**
  714. * Set the From and FromName properties.
  715. * @param string $address
  716. * @param string $name
  717. * @param bool $auto Whether to also set the Sender address, defaults to true
  718. * @throws phpmailerException
  719. * @return bool
  720. */
  721. public function setFrom($address, $name = '', $auto = true)
  722. {
  723. $address = trim($address);
  724. $name = trim(preg_replace('/[\r\n]+/', '', $name)); //Strip breaks and trim
  725. if (!$this->validateAddress($address)) {
  726. $this->setError($this->lang('invalid_address') . ': ' . $address);
  727. $this->edebug($this->lang('invalid_address') . ': ' . $address);
  728. if ($this->exceptions) {
  729. throw new phpmailerException($this->lang('invalid_address') . ': ' . $address);
  730. }
  731. return false;
  732. }
  733. $this->From = $address;
  734. $this->FromName = $name;
  735. if ($auto) {
  736. if (empty($this->Sender)) {
  737. $this->Sender = $address;
  738. }
  739. }
  740. return true;
  741. }
  742. /**
  743. * Return the Message-ID header of the last email.
  744. * Technically this is the value from the last time the headers were created,
  745. * but it's also the message ID of the last sent message except in
  746. * pathological cases.
  747. * @return string
  748. */
  749. public function getLastMessageID()
  750. {
  751. return $this->lastMessageID;
  752. }
  753. /**
  754. * Check that a string looks like an email address.
  755. * @param string $address The email address to check
  756. * @param string $patternselect A selector for the validation pattern to use :
  757. * * `auto` Pick strictest one automatically;
  758. * * `pcre8` Use the squiloople.com pattern, requires PCRE > 8.0, PHP >= 5.3.2, 5.2.14;
  759. * * `pcre` Use old PCRE implementation;
  760. * * `php` Use PHP built-in FILTER_VALIDATE_EMAIL; same as pcre8 but does not allow 'dotless' domains;
  761. * * `html5` Use the pattern given by the HTML5 spec for 'email' type form input elements.
  762. * * `noregex` Don't use a regex: super fast, really dumb.
  763. * @return bool
  764. * @static
  765. * @access public
  766. */
  767. public static function validateAddress($address, $patternselect = 'auto')
  768. {
  769. if (!$patternselect or $patternselect == 'auto') {
  770. if (defined('PCRE_VERSION')) { //Check this constant so it works when extension_loaded() is disabled
  771. if (version_compare(PCRE_VERSION, '8.0') >= 0) {
  772. $patternselect = 'pcre8';
  773. } else {
  774. $patternselect = 'pcre';
  775. }
  776. } else {
  777. //Filter_var appeared in PHP 5.2.0 and does not require the PCRE extension
  778. if (version_compare(PHP_VERSION, '5.2.0') >= 0) {
  779. $patternselect = 'php';
  780. } else {
  781. $patternselect = 'noregex';
  782. }
  783. }
  784. }
  785. switch ($patternselect) {
  786. case 'pcre8':
  787. /**
  788. * Uses the same RFC5322 regex on which FILTER_VALIDATE_EMAIL is based, but allows dotless domains.
  789. * @link http://squiloople.com/2009/12/20/email-address-validation/
  790. * @copyright 2009-2010 Michael Rushton
  791. * Feel free to use and redistribute this code. But please keep this copyright notice.
  792. */
  793. return (bool)preg_match(
  794. '/^(?!(?>(?1)"?(?>\\\[ -~]|[^"])"?(?1)){255,})(?!(?>(?1)"?(?>\\\[ -~]|[^"])"?(?1)){65,}@)' .
  795. '((?>(?>(?>((?>(?>(?>\x0D\x0A)?[\t ])+|(?>[\t ]*\x0D\x0A)?[\t ]+)?)(\((?>(?2)' .
  796. '(?>[\x01-\x08\x0B\x0C\x0E-\'*-\[\]-\x7F]|\\\[\x00-\x7F]|(?3)))*(?2)\)))+(?2))|(?2))?)' .
  797. '([!#-\'*+\/-9=?^-~-]+|"(?>(?2)(?>[\x01-\x08\x0B\x0C\x0E-!#-\[\]-\x7F]|\\\[\x00-\x7F]))*' .
  798. '(?2)")(?>(?1)\.(?1)(?4))*(?1)@(?!(?1)[a-z0-9-]{64,})(?1)(?>([a-z0-9](?>[a-z0-9-]*[a-z0-9])?)' .
  799. '(?>(?1)\.(?!(?1)[a-z0-9-]{64,})(?1)(?5)){0,126}|\[(?:(?>IPv6:(?>([a-f0-9]{1,4})(?>:(?6)){7}' .
  800. '|(?!(?:.*[a-f0-9][:\]]){8,})((?6)(?>:(?6)){0,6})?::(?7)?))|(?>(?>IPv6:(?>(?6)(?>:(?6)){5}:' .
  801. '|(?!(?:.*[a-f0-9]:){6,})(?8)?::(?>((?6)(?>:(?6)){0,4}):)?))?(25[0-5]|2[0-4][0-9]|1[0-9]{2}' .
  802. '|[1-9]?[0-9])(?>\.(?9)){3}))\])(?1)$/isD',
  803. $address
  804. );
  805. break;
  806. case 'pcre':
  807. //An older regex that doesn't need a recent PCRE
  808. return (bool)preg_match(
  809. '/^(?!(?>"?(?>\\\[ -~]|[^"])"?){255,})(?!(?>"?(?>\\\[ -~]|[^"])"?){65,}@)(?>' .
  810. '[!#-\'*+\/-9=?^-~-]+|"(?>(?>[\x01-\x08\x0B\x0C\x0E-!#-\[\]-\x7F]|\\\[\x00-\xFF]))*")' .
  811. '(?>\.(?>[!#-\'*+\/-9=?^-~-]+|"(?>(?>[\x01-\x08\x0B\x0C\x0E-!#-\[\]-\x7F]|\\\[\x00-\xFF]))*"))*' .
  812. '@(?>(?![a-z0-9-]{64,})(?>[a-z0-9](?>[a-z0-9-]*[a-z0-9])?)(?>\.(?![a-z0-9-]{64,})' .
  813. '(?>[a-z0-9](?>[a-z0-9-]*[a-z0-9])?)){0,126}|\[(?:(?>IPv6:(?>(?>[a-f0-9]{1,4})(?>:' .
  814. '[a-f0-9]{1,4}){7}|(?!(?:.*[a-f0-9][:\]]){8,})(?>[a-f0-9]{1,4}(?>:[a-f0-9]{1,4}){0,6})?' .
  815. '::(?>[a-f0-9]{1,4}(?>:[a-f0-9]{1,4}){0,6})?))|(?>(?>IPv6:(?>[a-f0-9]{1,4}(?>:' .
  816. '[a-f0-9]{1,4}){5}:|(?!(?:.*[a-f0-9]:){6,})(?>[a-f0-9]{1,4}(?>:[a-f0-9]{1,4}){0,4})?' .
  817. '::(?>(?:[a-f0-9]{1,4}(?>:[a-f0-9]{1,4}){0,4}):)?))?(?>25[0-5]|2[0-4][0-9]|1[0-9]{2}' .
  818. '|[1-9]?[0-9])(?>\.(?>25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])){3}))\])$/isD',
  819. $address
  820. );
  821. break;
  822. case 'html5':
  823. /**
  824. * This is the pattern used in the HTML5 spec for validation of 'email' type form input elements.
  825. * @link http://www.whatwg.org/specs/web-apps/current-work/#e-mail-state-(type=email)
  826. */
  827. return (bool)preg_match('/^[a-zA-Z0-9.!#$%&\'*+\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}' .
  828. '[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/sD', $address);
  829. break;
  830. case 'php':
  831. default:
  832. return (bool)filter_var($address, FILTER_VALIDATE_EMAIL);
  833. break;
  834. case 'noregex':
  835. //No PCRE! Do something _very_ approximate!
  836. //Check the address is 3 chars or longer and contains an @ that's not the first or last char
  837. return (strlen($address) >= 3
  838. and strpos($address, '@') >= 1
  839. and strpos($address, '@') != strlen($address) - 1);
  840. break;
  841. }
  842. }
  843. /**
  844. * Create a message and send it.
  845. * Uses the sending method specified by $Mailer.
  846. * @throws phpmailerException
  847. * @return bool false on error - See the ErrorInfo property for details of the error.
  848. */
  849. public function send()
  850. {
  851. try {
  852. if (!$this->preSend()) {
  853. return false;
  854. }
  855. return $this->postSend();
  856. } catch (phpmailerException $exc) {
  857. $this->mailHeader = '';
  858. $this->setError($exc->getMessage());
  859. if ($this->exceptions) {
  860. throw $exc;
  861. }
  862. return false;
  863. }
  864. }
  865. /**
  866. * Prepare a message for sending.
  867. * @throws phpmailerException
  868. * @return bool
  869. */
  870. public function preSend()
  871. {
  872. try {
  873. $this->mailHeader = '';
  874. if ((count($this->to) + count($this->cc) + count($this->bcc)) < 1) {
  875. throw new phpmailerException($this->lang('provide_address'), self::STOP_CRITICAL);
  876. }
  877. // Set whether the message is multipart/alternative
  878. if (!empty($this->AltBody)) {
  879. $this->ContentType = 'multipart/alternative';
  880. }
  881. $this->error_count = 0; // reset errors
  882. $this->setMessageType();
  883. // Refuse to send an empty message unless we are specifically allowing it
  884. if (!$this->AllowEmpty and empty($this->Body)) {
  885. throw new phpmailerException($this->lang('empty_message'), self::STOP_CRITICAL);
  886. }
  887. $this->MIMEHeader = $this->createHeader();
  888. $this->MIMEBody = $this->createBody();
  889. // To capture the complete message when using mail(), create
  890. // an extra header list which createHeader() doesn't fold in
  891. if ($this->Mailer == 'mail') {
  892. if (count($this->to) > 0) {
  893. $this->mailHeader .= $this->addrAppend('To', $this->to);
  894. } else {
  895. $this->mailHeader .= $this->headerLine('To', 'undisclosed-recipients:;');
  896. }
  897. $this->mailHeader .= $this->headerLine(
  898. 'Subject',
  899. $this->encodeHeader($this->secureHeader(trim($this->Subject)))
  900. );
  901. }
  902. // Sign with DKIM if enabled
  903. if (!empty($this->DKIM_domain)
  904. && !empty($this->DKIM_private)
  905. && !empty($this->DKIM_selector)
  906. && !empty($this->DKIM_domain)
  907. && file_exists($this->DKIM_private)) {
  908. $header_dkim = $this->DKIM_Add(
  909. $this->MIMEHeader . $this->mailHeader,
  910. $this->encodeHeader($this->secureHeader($this->Subject)),
  911. $this->MIMEBody
  912. );
  913. $this->MIMEHeader = rtrim($this->MIMEHeader, "\r\n ") . self::CRLF .
  914. str_replace("\r\n", "\n", $header_dkim) . self::CRLF;
  915. }
  916. return true;
  917. } catch (phpmailerException $exc) {
  918. $this->setError($exc->getMessage());
  919. if ($this->exceptions) {
  920. throw $exc;
  921. }
  922. return false;
  923. }
  924. }
  925. /**
  926. * Actually send a message.
  927. * Send the email via the selected mechanism
  928. * @throws phpmailerException
  929. * @return bool
  930. */
  931. public function postSend()
  932. {
  933. try {
  934. // Choose the mailer and send through it
  935. switch ($this->Mailer) {
  936. case 'sendmail':
  937. case 'qmail':
  938. return $this->sendmailSend($this->MIMEHeader, $this->MIMEBody);
  939. case 'smtp':
  940. return $this->smtpSend($this->MIMEHeader, $this->MIMEBody);
  941. case 'mail':
  942. return $this->mailSend($this->MIMEHeader, $this->MIMEBody);
  943. default:
  944. $sendMethod = $this->Mailer.'Send';
  945. if (method_exists($this, $sendMethod)) {
  946. return $this->$sendMethod($this->MIMEHeader, $this->MIMEBody);
  947. }
  948. return $this->mailSend($this->MIMEHeader, $this->MIMEBody);
  949. }
  950. } catch (phpmailerException $exc) {
  951. $this->setError($exc->getMessage());
  952. $this->edebug($exc->getMessage());
  953. if ($this->exceptions) {
  954. throw $exc;
  955. }
  956. }
  957. return false;
  958. }
  959. /**
  960. * Send mail using the $Sendmail program.
  961. * @param string $header The message headers
  962. * @param string $body The message body
  963. * @see PHPMailer::$Sendmail
  964. * @throws phpmailerException
  965. * @access protected
  966. * @return bool
  967. */
  968. protected function sendmailSend($header, $body)
  969. {
  970. if ($this->Sender != '') {
  971. if ($this->Mailer == 'qmail') {
  972. $sendmail = sprintf('%s -f%s', escapeshellcmd($this->Sendmail), escapeshellarg($this->Sender));
  973. } else {
  974. $sendmail = sprintf('%s -oi -f%s -t', escapeshellcmd($this->Sendmail), escapeshellarg($this->Sender));
  975. }
  976. } else {
  977. if ($this->Mailer == 'qmail') {
  978. $sendmail = sprintf('%s', escapeshellcmd($this->Sendmail));
  979. } else {
  980. $sendmail = sprintf('%s -oi -t', escapeshellcmd($this->Sendmail));
  981. }
  982. }
  983. if ($this->SingleTo === true) {
  984. foreach ($this->SingleToArray as $val) {
  985. if (!@$mail = popen($sendmail, 'w')) {
  986. throw new phpmailerException($this->lang('execute') . $this->Sendmail, self::STOP_CRITICAL);
  987. }
  988. fputs($mail, 'To: ' . $val . "\n");
  989. fputs($mail, $header);
  990. fputs($mail, $body);
  991. $result = pclose($mail);
  992. // implement call back function if it exists
  993. $isSent = ($result == 0) ? 1 : 0;
  994. $this->doCallback($isSent, $val, $this->cc, $this->bcc, $this->Subject, $body, $this->From);
  995. if ($result != 0) {
  996. throw new phpmailerException($this->lang('execute') . $this->Sendmail, self::STOP_CRITICAL);
  997. }
  998. }
  999. } else {
  1000. if (!@$mail = popen($sendmail, 'w')) {
  1001. throw new phpmailerException($this->lang('execute') . $this->Sendmail, self::STOP_CRITICAL);
  1002. }
  1003. fputs($mail, $header);
  1004. fputs($mail, $body);
  1005. $result = pclose($mail);
  1006. // implement call back function if it exists
  1007. $isSent = ($result == 0) ? 1 : 0;
  1008. $this->doCallback($isSent, $this->to, $this->cc, $this->bcc, $this->Subject, $body, $this->From);
  1009. if ($result != 0) {
  1010. throw new phpmailerException($this->lang('execute') . $this->Sendmail, self::STOP_CRITICAL);
  1011. }
  1012. }
  1013. return true;
  1014. }
  1015. /**
  1016. * Send mail using the PHP mail() function.
  1017. * @param string $header The message headers
  1018. * @param string $body The message body
  1019. * @link http://www.php.net/manual/en/book.mail.php
  1020. * @throws phpmailerException
  1021. * @access protected
  1022. * @return bool
  1023. */
  1024. protected function mailSend($header, $body)
  1025. {
  1026. $toArr = array();
  1027. foreach ($this->to as $toaddr) {
  1028. $toArr[] = $this->addrFormat($toaddr);
  1029. }
  1030. $to = implode(', ', $toArr);
  1031. if (empty($this->Sender)) {
  1032. $params = ' ';
  1033. } else {
  1034. $params = sprintf('-f%s', $this->Sender);
  1035. }
  1036. if ($this->Sender != '' and !ini_get('safe_mode')) {
  1037. $old_from = ini_get('sendmail_from');
  1038. ini_set('sendmail_from', $this->Sender);
  1039. }
  1040. $result = false;
  1041. if ($this->SingleTo === true && count($toArr) > 1) {
  1042. foreach ($toArr as $val) {
  1043. $result = $this->mailPassthru($val, $this->Subject, $body, $header, $params);
  1044. // implement call back function if it exists
  1045. $isSent = ($result == 1) ? 1 : 0;
  1046. $this->doCallback($isSent, $val, $this->cc, $this->bcc, $this->Subject, $body, $this->From);
  1047. }
  1048. } else {
  1049. $result = $this->mailPassthru($to, $this->Subject, $body, $header, $params);
  1050. // implement call back function if it exists
  1051. $isSent = ($result == 1) ? 1 : 0;
  1052. $this->doCallback($isSent, $to, $this->cc, $this->bcc, $this->Subject, $body, $this->From);
  1053. }
  1054. if (isset($old_from)) {
  1055. ini_set('sendmail_from', $old_from);
  1056. }
  1057. if (!$result) {
  1058. throw new phpmailerException($this->lang('instantiate'), self::STOP_CRITICAL);
  1059. }
  1060. return true;
  1061. }
  1062. /**
  1063. * Get an instance to use for SMTP operations.
  1064. * Override this function to load your own SMTP implementation
  1065. * @return SMTP
  1066. */
  1067. public function getSMTPInstance()
  1068. {
  1069. if (!is_object($this->smtp)) {
  1070. $this->smtp = new SMTP;
  1071. }
  1072. return $this->smtp;
  1073. }
  1074. /**
  1075. * Send mail via SMTP.
  1076. * Returns false if there is a bad MAIL FROM, RCPT, or DATA input.
  1077. * Uses the PHPMailerSMTP class by default.
  1078. * @see PHPMailer::getSMTPInstance() to use a different class.
  1079. * @param string $header The message headers
  1080. * @param string $body The message body
  1081. * @throws phpmailerException
  1082. * @uses SMTP
  1083. * @access protected
  1084. * @return bool
  1085. */
  1086. protected function smtpSend($header, $body)
  1087. {
  1088. $bad_rcpt = array();
  1089. if (!$this->smtpConnect()) {
  1090. throw new phpmailerException($this->lang('smtp_connect_failed'), self::STOP_CRITICAL);
  1091. }
  1092. $smtp_from = ($this->Sender == '') ? $this->From : $this->Sender;
  1093. if (!$this->smtp->mail($smtp_from)) {
  1094. $this->setError($this->lang('from_failed') . $smtp_from . ' : ' . implode(',', $this->smtp->getError()));
  1095. throw new phpmailerException($this->ErrorInfo, self::STOP_CRITICAL);
  1096. }
  1097. // Attempt to send to all recipients
  1098. foreach ($this->to as $to) {
  1099. if (!$this->smtp->recipient($to[0])) {
  1100. $bad_rcpt[] = $to[0];
  1101. $isSent = 0;
  1102. } else {
  1103. $isSent = 1;
  1104. }
  1105. $this->doCallback($isSent, $to[0], '', '', $this->Subject, $body, $this->From);
  1106. }
  1107. foreach ($this->cc as $cc) {
  1108. if (!$this->smtp->recipient($cc[0])) {
  1109. $bad_rcpt[] = $cc[0];
  1110. $isSent = 0;
  1111. } else {
  1112. $isSent = 1;
  1113. }
  1114. $this->doCallback($isSent, '', $cc[0], '', $this->Subject, $body, $this->From);
  1115. }
  1116. foreach ($this->bcc as $bcc) {
  1117. if (!$this->smtp->recipient($bcc[0])) {
  1118. $bad_rcpt[] = $bcc[0];
  1119. $isSent = 0;
  1120. } else {
  1121. $isSent = 1;
  1122. }
  1123. $this->doCallback($isSent, '', '', $bcc[0], $this->Subject, $body, $this->From);
  1124. }
  1125. //Only send the DATA command if we have viable recipients
  1126. if ((count($this->all_recipients) > count($bad_rcpt)) and !$this->smtp->data($header . $body)) {
  1127. throw new phpmailerException($this->lang('data_not_accepted'), self::STOP_CRITICAL);
  1128. }
  1129. if ($this->SMTPKeepAlive == true) {
  1130. $this->smtp->reset();
  1131. } else {
  1132. $this->smtp->quit();
  1133. $this->smtp->close();
  1134. }
  1135. if (count($bad_rcpt) > 0) { //Create error message for any bad addresses
  1136. throw new phpmailerException(
  1137. $this->lang('recipients_failed') . implode(', ', $bad_rcpt),
  1138. self::STOP_CONTINUE
  1139. );
  1140. }
  1141. return true;
  1142. }
  1143. /**
  1144. * Initiate a connection to an SMTP server.
  1145. * Returns false if the operation failed.
  1146. * @param array $options An array of options compatible with stream_context_create()
  1147. * @uses SMTP
  1148. * @access public
  1149. * @throws phpmailerException
  1150. * @return bool
  1151. */
  1152. public function smtpConnect($options = array())
  1153. {
  1154. if (is_null($this->smtp)) {
  1155. $this->smtp = $this->getSMTPInstance();
  1156. }
  1157. //Already connected?
  1158. if ($this->smtp->connected()) {
  1159. return true;
  1160. }
  1161. $this->smtp->setTimeout($this->Timeout);
  1162. $this->smtp->setDebugLevel($this->SMTPDebug);
  1163. $this->smtp->setDebugOutput($this->Debugoutput);
  1164. $this->smtp->setVerp($this->do_verp);
  1165. $hosts = explode(';', $this->Host);
  1166. $lastexception = null;
  1167. foreach ($hosts as $hostentry) {
  1168. $hostinfo = array();
  1169. if (!preg_match('/^((ssl|tls):\/\/)*([a-zA-Z0-9\.-]*):?([0-9]*)$/', trim($hostentry), $hostinfo)) {
  1170. //Not a valid host entry
  1171. continue;
  1172. }
  1173. //$hostinfo[2]: optional ssl or tls prefix
  1174. //$hostinfo[3]: the hostname
  1175. //$hostinfo[4]: optional port number
  1176. //The host string prefix can temporarily override the current setting for SMTPSecure
  1177. //If it's not specified, the default value is used
  1178. $prefix = '';
  1179. $tls = ($this->SMTPSecure == 'tls');
  1180. if ($hostinfo[2] == 'ssl' or ($hostinfo[2] == '' and $this->SMTPSecure == 'ssl')) {
  1181. $prefix = 'ssl://';
  1182. $tls = false; //Can't have SSL and TLS at once
  1183. } elseif ($hostinfo[2] == 'tls') {
  1184. $tls = true;
  1185. //tls doesn't use a prefix
  1186. }
  1187. $host = $hostinfo[3];
  1188. $port = $this->Port;
  1189. $tport = (integer)$hostinfo[4];
  1190. if ($tport > 0 and $tport < 65536) {
  1191. $port = $tport;
  1192. }
  1193. if ($this->smtp->connect($prefix . $host, $port, $this->Timeout, $options)) {
  1194. try {
  1195. if ($this->Helo) {
  1196. $hello = $this->Helo;
  1197. } else {
  1198. $hello = $this->serverHostname();
  1199. }
  1200. $this->smtp->hello($hello);
  1201. if ($tls) {
  1202. if (!$this->smtp->startTLS()) {
  1203. throw new phpmailerException($this->lang('connect_host'));
  1204. }
  1205. //We must resend HELO after tls negotiation
  1206. $this->smtp->hello($hello);
  1207. }
  1208. if ($this->SMTPAuth) {
  1209. if (!$this->smtp->authenticate(
  1210. $this->Username,
  1211. $this->Password,
  1212. $this->AuthType,
  1213. $this->Realm,
  1214. $this->Workstation
  1215. )
  1216. ) {
  1217. throw new phpmailerException($this->lang('authenticate'));
  1218. }
  1219. }
  1220. return true;
  1221. } catch (phpmailerException $exc) {
  1222. $lastexception = $exc;
  1223. //We must have connected, but then failed TLS or Auth, so close connection nicely
  1224. $this->smtp->quit();
  1225. }
  1226. }
  1227. }
  1228. //If we get here, all connection attempts have failed, so close connection hard
  1229. $this->smtp->close();
  1230. //As we've caught all exceptions, just report whatever the last one was
  1231. if ($this->exceptions and !is_null($lastexception)) {
  1232. throw $lastexception;
  1233. }
  1234. return false;
  1235. }
  1236. /**
  1237. * Close the active SMTP session if one exists.
  1238. * @return void
  1239. */
  1240. public function smtpClose()
  1241. {
  1242. if ($this->smtp !== null) {
  1243. if ($this->smtp->connected()) {
  1244. $this->smtp->quit();
  1245. $this->smtp->close();
  1246. }
  1247. }
  1248. }
  1249. /**
  1250. * Set the language for error messages.
  1251. * Returns false if it cannot load the language file.
  1252. * The default language is English.
  1253. * @param string $langcode ISO 639-1 2-character language code (e.g. French is "fr")
  1254. * @param string $lang_path Path to the language file directory, with trailing separator (slash)
  1255. * @return bool
  1256. * @access public
  1257. */
  1258. public function setLanguage($langcode = 'en', $lang_path = '')
  1259. {
  1260. //Define full set of translatable strings in English
  1261. $PHPMAILER_LANG = array(
  1262. 'authenticate' => 'SMTP Error: Could not authenticate.',
  1263. 'connect_host' => 'SMTP Error: Could not connect to SMTP host.',
  1264. 'data_not_accepted' => 'SMTP Error: data not accepted.',
  1265. 'empty_message' => 'Message body empty',
  1266. 'encoding' => 'Unknown encoding: ',
  1267. 'execute' => 'Could not execute: ',
  1268. 'file_access' => 'Could not access file: ',
  1269. 'file_open' => 'File Error: Could not open file: ',
  1270. 'from_failed' => 'The following From address failed: ',
  1271. 'instantiate' => 'Could not instantiate mail function.',
  1272. 'invalid_address' => 'Invalid address',
  1273. 'mailer_not_supported' => ' mailer is not supported.',
  1274. 'provide_address' => 'You must provide at least one recipient email address.',
  1275. 'recipients_failed' => 'SMTP Error: The following recipients failed: ',
  1276. 'signing' => 'Signing Error: ',
  1277. 'smtp_connect_failed' => 'SMTP connect() failed.',
  1278. 'smtp_error' => 'SMTP server error: ',
  1279. 'variable_set' => 'Cannot set or reset variable: '
  1280. );
  1281. if (empty($lang_path)) {
  1282. //Calculate an absolute path so it can work if CWD is not here
  1283. $lang_path = dirname(__FILE__). DIRECTORY_SEPARATOR . 'language'. DIRECTORY_SEPARATOR;
  1284. }
  1285. $foundlang = true;
  1286. $lang_file = $lang_path . 'phpmailer.lang-' . $langcode . '.php';
  1287. if ($langcode != 'en') { //There is no English translation file
  1288. //Make sure language file path is readable
  1289. if (!is_readable($lang_file)) {
  1290. $foundlang = false;
  1291. } else {
  1292. //Overwrite language-specific strings.
  1293. //This way we'll never have missing translations.
  1294. $foundlang = include $lang_file;
  1295. }
  1296. }
  1297. $this->language = $PHPMAILER_LANG;
  1298. return ($foundlang == true); //Returns false if language not found
  1299. }
  1300. /**
  1301. * Get the array of strings for the current language.
  1302. * @return array
  1303. */
  1304. public function getTranslations()
  1305. {
  1306. return $this->language;
  1307. }
  1308. /**
  1309. * Create recipient headers.
  1310. * @access public
  1311. * @param string $type
  1312. * @param array $addr An array of recipient,
  1313. * where each recipient is a 2-element indexed array with element 0 containing an address
  1314. * and element 1 containing a name, like:
  1315. * array(array('joe@example.com', 'Joe User'), array('zoe@example.com', 'Zoe User'))
  1316. * @return string
  1317. */
  1318. public function addrAppend($type, $addr)
  1319. {
  1320. $addresses = array();
  1321. foreach ($addr as $address) {
  1322. $addresses[] = $this->addrFormat($address);
  1323. }
  1324. return $type . ': ' . implode(', ', $addresses) . $this->LE;
  1325. }
  1326. /**
  1327. * Format an address for use in a message header.
  1328. * @access public
  1329. * @param array $addr A 2-element indexed array, element 0 containing an address, element 1 containing a name
  1330. * like array('joe@example.com', 'Joe User')
  1331. * @return string
  1332. */
  1333. public function addrFormat($addr)
  1334. {
  1335. if (empty($addr[1])) { // No name provided
  1336. return $this->secureHeader($addr[0]);
  1337. } else {
  1338. return $this->encodeHeader($this->secureHeader($addr[1]), 'phrase') . ' <' . $this->secureHeader(
  1339. $addr[0]
  1340. ) . '>';
  1341. }
  1342. }
  1343. /**
  1344. * Word-wrap message.
  1345. * For use with mailers that do not automatically perform wrapping
  1346. * and for quoted-printable encoded messages.
  1347. * Original written by philippe.
  1348. * @param string $message The message to wrap
  1349. * @param integer $length The line length to wrap to
  1350. * @param bool $qp_mode Whether to run in Quoted-Printable mode
  1351. * @access public
  1352. * @return string
  1353. */
  1354. public function wrapText($message, $length, $qp_mode = false)
  1355. {
  1356. $soft_break = ($qp_mode) ? sprintf(' =%s', $this->LE) : $this->LE;
  1357. // If utf-8 encoding is used, we will need to make sure we don't
  1358. // split multibyte characters when we wrap
  1359. $is_utf8 = (strtolower($this->CharSet) == 'utf-8');
  1360. $lelen = strlen($this->LE);
  1361. $crlflen = strlen(self::CRLF);
  1362. $message = $this->fixEOL($message);
  1363. if (substr($message, -$lelen) == $this->LE) {
  1364. $message = substr($message, 0, -$lelen);
  1365. }
  1366. $line = explode($this->LE, $message); // Magic. We know fixEOL uses $LE
  1367. $message = '';
  1368. for ($i = 0; $i < count($line); $i++) {
  1369. $line_part = explode(' ', $line[$i]);
  1370. $buf = '';
  1371. for ($e = 0; $e < count($line_part); $e++) {
  1372. $word = $line_part[$e];
  1373. if ($qp_mode and (strlen($word) > $length)) {
  1374. $space_left = $length - strlen($buf) - $crlflen;
  1375. if ($e != 0) {
  1376. if ($space_left > 20) {
  1377. $len = $space_left;
  1378. if ($is_utf8) {
  1379. $len = $this->utf8CharBoundary($word, $len);
  1380. } elseif (substr($word, $len - 1, 1) == '=') {
  1381. $len--;
  1382. } elseif (substr($word, $len - 2, 1) == '=') {
  1383. $len -= 2;
  1384. }
  1385. $part = substr($word, 0, $len);
  1386. $word = substr($word, $len);
  1387. $buf .= ' ' . $part;
  1388. $message .= $buf . sprintf('=%s', self::CRLF);
  1389. } else {
  1390. $message .= $buf . $soft_break;
  1391. }
  1392. $buf = '';
  1393. }
  1394. while (strlen($word) > 0) {
  1395. if ($length <= 0) {
  1396. break;
  1397. }
  1398. $len = $length;
  1399. if ($is_utf8) {
  1400. $len = $this->utf8CharBoundary($word, $len);
  1401. } elseif (substr($word, $len - 1, 1) == '=') {
  1402. $len--;
  1403. } elseif (substr($word, $len - 2, 1) == '=') {
  1404. $len -= 2;
  1405. }
  1406. $part = substr($word, 0, $len);
  1407. $word = substr($word, $len);
  1408. if (strlen($word) > 0) {
  1409. $message .= $part . sprintf('=%s', self::CRLF);
  1410. } else {
  1411. $buf = $part;
  1412. }
  1413. }
  1414. } else {
  1415. $buf_o = $buf;
  1416. $buf .= ($e == 0) ? $word : (' ' . $word);
  1417. if (strlen($buf) > $length and $buf_o != '') {
  1418. $message .= $buf_o . $soft_break;
  1419. $buf = $word;
  1420. }
  1421. }
  1422. }
  1423. $message .= $buf . self::CRLF;
  1424. }
  1425. return $message;
  1426. }
  1427. /**
  1428. * Find the last character boundary prior to $maxLength in a utf-8
  1429. * quoted (printable) encoded string.
  1430. * Original written by Colin Brown.
  1431. * @access public
  1432. * @param string $encodedText utf-8 QP text
  1433. * @param int $maxLength find last character boundary prior to this length
  1434. * @return int
  1435. */
  1436. public function utf8CharBoundary($encodedText, $maxLength)
  1437. {
  1438. $foundSplitPos = false;
  1439. $lookBack = 3;
  1440. while (!$foundSplitPos) {
  1441. $lastChunk = substr($encodedText, $maxLength - $lookBack, $lookBack);
  1442. $encodedCharPos = strpos($lastChunk, '=');
  1443. if ($encodedCharPos !== false) {
  1444. // Found start of encoded character byte within $lookBack block.
  1445. // Check the encoded byte value (the 2 chars after the '=')
  1446. $hex = substr($encodedText, $maxLength - $lookBack + $encodedCharPos + 1, 2);
  1447. $dec = hexdec($hex);
  1448. if ($dec < 128) { // Single byte character.
  1449. // If the encoded char was found at pos 0, it will fit
  1450. // otherwise reduce maxLength to start of the encoded char
  1451. $maxLength = ($encodedCharPos == 0) ? $maxLength :
  1452. $maxLength - ($lookBack - $encodedCharPos);
  1453. $foundSplitPos = true;
  1454. } elseif ($dec >= 192) { // First byte of a multi byte character
  1455. // Reduce maxLength to split at start of character
  1456. $maxLength = $maxLength - ($lookBack - $encodedCharPos);
  1457. $foundSplitPos = true;
  1458. } elseif ($dec < 192) { // Middle byte of a multi byte character, look further back
  1459. $lookBack += 3;
  1460. }
  1461. } else {
  1462. // No encoded character found
  1463. $foundSplitPos = true;
  1464. }
  1465. }
  1466. return $maxLength;
  1467. }
  1468. /**
  1469. * Set the body wrapping.
  1470. * @access public
  1471. * @return void
  1472. */
  1473. public function setWordWrap()
  1474. {
  1475. if ($this->WordWrap < 1) {
  1476. return;
  1477. }
  1478. switch ($this->message_type) {
  1479. case 'alt':
  1480. case 'alt_inline':
  1481. case 'alt_attach':
  1482. case 'alt_inline_attach':
  1483. $this->AltBody = $this->wrapText($this->AltBody, $this->WordWrap);
  1484. break;
  1485. default:
  1486. $this->Body = $this->wrapText($this->Body, $this->WordWrap);
  1487. break;
  1488. }
  1489. }
  1490. /**
  1491. * Assemble message headers.
  1492. * @access public
  1493. * @return string The assembled headers
  1494. */
  1495. public function createHeader()
  1496. {
  1497. $result = '';
  1498. // Set the boundaries
  1499. $uniq_id = md5(uniqid(time()));
  1500. $this->boundary[1] = 'b1_' . $uniq_id;
  1501. $this->boundary[2] = 'b2_' . $uniq_id;
  1502. $this->boundary[3] = 'b3_' . $uniq_id;
  1503. if ($this->MessageDate == '') {
  1504. $this->MessageDate = self::rfcDate();
  1505. }
  1506. $result .= $this->headerLine('Date', $this->MessageDate);
  1507. // To be created automatically by mail()
  1508. if ($this->SingleTo === true) {
  1509. if ($this->Mailer != 'mail') {
  1510. foreach ($this->to as $toaddr) {
  1511. $this->SingleToArray[] = $this->addrFormat($toaddr);
  1512. }
  1513. }
  1514. } else {
  1515. if (count($this->to) > 0) {
  1516. if ($this->Mailer != 'mail') {
  1517. $result .= $this->addrAppend('To', $this->to);
  1518. }
  1519. } elseif (count($this->cc) == 0) {
  1520. $result .= $this->headerLine('To', 'undisclosed-recipients:;');
  1521. }
  1522. }
  1523. $result .= $this->addrAppend('From', array(array(trim($this->From), $this->FromName)));
  1524. // sendmail and mail() extract Cc from the header before sending
  1525. if (count($this->cc) > 0) {
  1526. $result .= $this->addrAppend('Cc', $this->cc);
  1527. }
  1528. // sendmail and mail() extract Bcc from the header before sending
  1529. if ((
  1530. $this->Mailer == 'sendmail' or $this->Mailer == 'qmail' or $this->Mailer == 'mail'
  1531. )
  1532. and count($this->bcc) > 0
  1533. ) {
  1534. $result .= $this->addrAppend('Bcc', $this->bcc);
  1535. }
  1536. if (count($this->ReplyTo) > 0) {
  1537. $result .= $this->addrAppend('Reply-To', $this->ReplyTo);
  1538. }
  1539. // mail() sets the subject itself
  1540. if ($this->Mailer != 'mail') {
  1541. $result .= $this->headerLine('Subject', $this->encodeHeader($this->secureHeader($this->Subject)));
  1542. }
  1543. if ($this->MessageID != '') {
  1544. $this->lastMessageID = $this->MessageID;
  1545. } else {
  1546. $this->lastMessageID = sprintf('<%s@%s>', $uniq_id, $this->ServerHostname());
  1547. }
  1548. $result .= $this->HeaderLine('Message-ID', $this->lastMessageID);
  1549. $result .= $this->headerLine('X-Priority', $this->Priority);
  1550. if ($this->XMailer == '') {
  1551. $result .= $this->headerLine(
  1552. 'X-Mailer',
  1553. 'PHPMailer ' . $this->Version . ' (https://github.com/PHPMailer/PHPMailer/)'
  1554. );
  1555. } else {
  1556. $myXmailer = trim($this->XMailer);
  1557. if ($myXmailer) {
  1558. $result .= $this->headerLine('X-Mailer', $myXmailer);
  1559. }
  1560. }
  1561. if ($this->ConfirmReadingTo != '') {
  1562. $result .= $this->headerLine('Disposition-Notification-To', '<' . trim($this->ConfirmReadingTo) . '>');
  1563. }
  1564. // Add custom headers
  1565. for ($index = 0; $index < count($this->CustomHeader); $index++) {
  1566. $result .= $this->headerLine(
  1567. trim($this->CustomHeader[$index][0]),
  1568. $this->encodeHeader(trim($this->CustomHeader[$index][1]))
  1569. );
  1570. }
  1571. if (!$this->sign_key_file) {
  1572. $result .= $this->headerLine('MIME-Version', '1.0');
  1573. $result .= $this->getMailMIME();
  1574. }
  1575. return $result;
  1576. }
  1577. /**
  1578. * Get the message MIME type headers.
  1579. * @access public
  1580. * @return string
  1581. */
  1582. public function getMailMIME()
  1583. {
  1584. $result = '';
  1585. $ismultipart = true;
  1586. switch ($this->message_type) {
  1587. case 'inline':
  1588. $result .= $this->headerLine('Content-Type', 'multipart/related;');
  1589. $result .= $this->textLine("\tboundary=\"" . $this->boundary[1] . '"');
  1590. break;
  1591. case 'attach':
  1592. case 'inline_attach':
  1593. case 'alt_attach':
  1594. case 'alt_inline_attach':
  1595. $result .= $this->headerLine('Content-Type', 'multipart/mixed;');
  1596. $result .= $this->textLine("\tboundary=\"" . $this->boundary[1] . '"');
  1597. break;
  1598. case 'alt':
  1599. case 'alt_inline':
  1600. $result .= $this->headerLine('Content-Type', 'multipart/alternative;');
  1601. $result .= $this->textLine("\tboundary=\"" . $this->boundary[1] . '"');
  1602. break;
  1603. default:
  1604. // Catches case 'plain': and case '':
  1605. $result .= $this->textLine('Content-Type: ' . $this->ContentType . '; charset=' . $this->CharSet);
  1606. $ismultipart = false;
  1607. break;
  1608. }
  1609. //RFC1341 part 5 says 7bit is assumed if not specified
  1610. if ($this->Encoding != '7bit') {
  1611. //RFC 2045 section 6.4 says multipart MIME parts may only use 7bit, 8bit or binary CTE
  1612. if ($ismultipart) {
  1613. if ($this->Encoding == '8bit') {
  1614. $result .= $this->headerLine('Content-Transfer-Encoding', '8bit');
  1615. }
  1616. //The only remaining alternatives are quoted-printable and base64, which are both 7bit compatible
  1617. } else {
  1618. $result .= $this->headerLine('Content-Transfer-Encoding', $this->Encoding);
  1619. }
  1620. }
  1621. if ($this->Mailer != 'mail') {
  1622. $result .= $this->LE;
  1623. }
  1624. return $result;
  1625. }
  1626. /**
  1627. * Returns the whole MIME message.
  1628. * Includes complete headers and body.
  1629. * Only valid post preSend().
  1630. * @see PHPMailer::preSend()
  1631. * @access public
  1632. * @return string
  1633. */
  1634. public function getSentMIMEMessage()
  1635. {
  1636. return $this->MIMEHeader . $this->mailHeader . self::CRLF . $this->MIMEBody;
  1637. }
  1638. /**
  1639. * Assemble the message body.
  1640. * Returns an empty string on failure.
  1641. * @access public
  1642. * @throws phpmailerException
  1643. * @return string The assembled message body
  1644. */
  1645. public function createBody()
  1646. {
  1647. $body = '';
  1648. if ($this->sign_key_file) {
  1649. $body .= $this->getMailMIME() . $this->LE;
  1650. }
  1651. $this->setWordWrap();
  1652. $bodyEncoding = $this->Encoding;
  1653. $bodyCharSet = $this->CharSet;
  1654. if ($bodyEncoding == '8bit' and !$this->has8bitChars($this->Body)) {
  1655. $bodyEncoding = '7bit';
  1656. $bodyCharSet = 'us-ascii';
  1657. }
  1658. $altBodyEncoding = $this->Encoding;
  1659. $altBodyCharSet = $this->CharSet;
  1660. if ($altBodyEncoding == '8bit' and !$this->has8bitChars($this->AltBody)) {
  1661. $altBodyEncoding = '7bit';
  1662. $altBodyCharSet = 'us-ascii';
  1663. }
  1664. switch ($this->message_type) {
  1665. case 'inline':
  1666. $body .= $this->getBoundary($this->boundary[1], $bodyCharSet, '', $bodyEncoding);
  1667. $body .= $this->encodeString($this->Body, $bodyEncoding);
  1668. $body .= $this->LE . $this->LE;
  1669. $body .= $this->attachAll('inline', $this->boundary[1]);
  1670. break;
  1671. case 'attach':
  1672. $body .= $this->getBoundary($this->boundary[1], $bodyCharSet, '', $bodyEncoding);
  1673. $body .= $this->encodeString($this->Body, $bodyEncoding);
  1674. $body .= $this->LE . $this->LE;
  1675. $body .= $this->attachAll('attachment', $this->boundary[1]);
  1676. break;
  1677. case 'inline_attach':
  1678. $body .= $this->textLine('--' . $this->boundary[1]);
  1679. $body .= $this->headerLine('Content-Type', 'multipart/related;');
  1680. $body .= $this->textLine("\tboundary=\"" . $this->boundary[2] . '"');
  1681. $body .= $this->LE;
  1682. $body .= $this->getBoundary($this->boundary[2], $bodyCharSet, '', $bodyEncoding);
  1683. $body .= $this->encodeString($this->Body, $bodyEncoding);
  1684. $body .= $this->LE . $this->LE;
  1685. $body .= $this->attachAll('inline', $this->boundary[2]);
  1686. $body .= $this->LE;
  1687. $body .= $this->attachAll('attachment', $this->boundary[1]);
  1688. break;
  1689. case 'alt':
  1690. $body .= $this->getBoundary($this->boundary[1], $altBodyCharSet, 'text/plain', $altBodyEncoding);
  1691. $body .= $this->encodeString($this->AltBody, $altBodyEncoding);
  1692. $body .= $this->LE . $this->LE;
  1693. $body .= $this->getBoundary($this->boundary[1], $bodyCharSet, 'text/html', $bodyEncoding);
  1694. $body .= $this->encodeString($this->Body, $bodyEncoding);
  1695. $body .= $this->LE . $this->LE;
  1696. if (!empty($this->Ical)) {
  1697. $body .= $this->getBoundary($this->boundary[1], '', 'text/calendar; method=REQUEST', '');
  1698. $body .= $this->encodeString($this->Ical, $this->Encoding);
  1699. $body .= $this->LE . $this->LE;
  1700. }
  1701. $body .= $this->endBoundary($this->boundary[1]);
  1702. break;
  1703. case 'alt_inline':
  1704. $body .= $this->getBoundary($this->boundary[1], $altBodyCharSet, 'text/plain', $altBodyEncoding);
  1705. $body .= $this->encodeString($this->AltBody, $altBodyEncoding);
  1706. $body .= $this->LE . $this->LE;
  1707. $body .= $this->textLine('--' . $this->boundary[1]);
  1708. $body .= $this->headerLine('Content-Type', 'multipart/related;');
  1709. $body .= $this->textLine("\tboundary=\"" . $this->boundary[2] . '"');
  1710. $body .= $this->LE;
  1711. $body .= $this->getBoundary($this->boundary[2], $bodyCharSet, 'text/html', $bodyEncoding);
  1712. $body .= $this->encodeString($this->Body, $bodyEncoding);
  1713. $body .= $this->LE . $this->LE;
  1714. $body .= $this->attachAll('inline', $this->boundary[2]);
  1715. $body .= $this->LE;
  1716. $body .= $this->endBoundary($this->boundary[1]);
  1717. break;
  1718. case 'alt_attach':
  1719. $body .= $this->textLine('--' . $this->boundary[1]);
  1720. $body .= $this->headerLine('Content-Type', 'multipart/alternative;');
  1721. $body .= $this->textLine("\tboundary=\"" . $this->boundary[2] . '"');
  1722. $body .= $this->LE;
  1723. $body .= $this->getBoundary($this->boundary[2], $altBodyCharSet, 'text/plain', $altBodyEncoding);
  1724. $body .= $this->encodeString($this->AltBody, $altBodyEncoding);
  1725. $body .= $this->LE . $this->LE;
  1726. $body .= $this->getBoundary($this->boundary[2], $bodyCharSet, 'text/html', $bodyEncoding);
  1727. $body .= $this->encodeString($this->Body, $bodyEncoding);
  1728. $body .= $this->LE . $this->LE;
  1729. $body .= $this->endBoundary($this->boundary[2]);
  1730. $body .= $this->LE;
  1731. $body .= $this->attachAll('attachment', $this->boundary[1]);
  1732. break;
  1733. case 'alt_inline_attach':
  1734. $body .= $this->textLine('--' . $this->boundary[1]);
  1735. $body .= $this->headerLine('Content-Type', 'multipart/alternative;');
  1736. $body .= $this->textLine("\tboundary=\"" . $this->boundary[2] . '"');
  1737. $body .= $this->LE;
  1738. $body .= $this->getBoundary($this->boundary[2], $altBodyCharSet, 'text/plain', $altBodyEncoding);
  1739. $body .= $this->encodeString($this->AltBody, $altBodyEncoding);
  1740. $body .= $this->LE . $this->LE;
  1741. $body .= $this->textLine('--' . $this->boundary[2]);
  1742. $body .= $this->headerLine('Content-Type', 'multipart/related;');
  1743. $body .= $this->textLine("\tboundary=\"" . $this->boundary[3] . '"');
  1744. $body .= $this->LE;
  1745. $body .= $this->getBoundary($this->boundary[3], $bodyCharSet, 'text/html', $bodyEncoding);
  1746. $body .= $this->encodeString($this->Body, $bodyEncoding);
  1747. $body .= $this->LE . $this->LE;
  1748. $body .= $this->attachAll('inline', $this->boundary[3]);
  1749. $body .= $this->LE;
  1750. $body .= $this->endBoundary($this->boundary[2]);
  1751. $body .= $this->LE;
  1752. $body .= $this->attachAll('attachment', $this->boundary[1]);
  1753. break;
  1754. default:
  1755. // catch case 'plain' and case ''
  1756. $body .= $this->encodeString($this->Body, $bodyEncoding);
  1757. break;
  1758. }
  1759. if ($this->isError()) {
  1760. $body = '';
  1761. } elseif ($this->sign_key_file) {
  1762. try {
  1763. if (!defined('PKCS7_TEXT')) {
  1764. throw new phpmailerException($this->lang('signing') . ' OpenSSL extension missing.');
  1765. }
  1766. //TODO would be nice to use php://temp streams here, but need to wrap for PHP < 5.1
  1767. $file = tempnam(sys_get_temp_dir(), 'mail');
  1768. file_put_contents($file, $body); //TODO check this worked
  1769. $signed = tempnam(sys_get_temp_dir(), 'signed');
  1770. if (@openssl_pkcs7_sign(
  1771. $file,
  1772. $signed,
  1773. 'file://' . realpath($this->sign_cert_file),
  1774. array('file://' . realpath($this->sign_key_file), $this->sign_key_pass),
  1775. null
  1776. )
  1777. ) {
  1778. @unlink($file);
  1779. $body = file_get_contents($signed);
  1780. @unlink($signed);
  1781. } else {
  1782. @unlink($file);
  1783. @unlink($signed);
  1784. throw new phpmailerException($this->lang('signing') . openssl_error_string());
  1785. }
  1786. } catch (phpmailerException $exc) {
  1787. $body = '';
  1788. if ($this->exceptions) {
  1789. throw $exc;
  1790. }
  1791. }
  1792. }
  1793. return $body;
  1794. }
  1795. /**
  1796. * Return the start of a message boundary.
  1797. * @access protected
  1798. * @param string $boundary
  1799. * @param string $charSet
  1800. * @param string $contentType
  1801. * @param string $encoding
  1802. * @return string
  1803. */
  1804. protected function getBoundary($boundary, $charSet, $contentType, $encoding)
  1805. {
  1806. $result = '';
  1807. if ($charSet == '') {
  1808. $charSet = $this->CharSet;
  1809. }
  1810. if ($contentType == '') {
  1811. $contentType = $this->ContentType;
  1812. }
  1813. if ($encoding == '') {
  1814. $encoding = $this->Encoding;
  1815. }
  1816. $result .= $this->textLine('--' . $boundary);
  1817. $result .= sprintf('Content-Type: %s; charset=%s', $contentType, $charSet);
  1818. $result .= $this->LE;
  1819. //RFC1341 part 5 says 7bit is assumed if not specified
  1820. if ($encoding != '7bit') {
  1821. $result .= $this->headerLine('Content-Transfer-Encoding', $encoding);
  1822. }
  1823. $result .= $this->LE;
  1824. return $result;
  1825. }
  1826. /**
  1827. * Return the end of a message boundary.
  1828. * @access protected
  1829. * @param string $boundary
  1830. * @return string
  1831. */
  1832. protected function endBoundary($boundary)
  1833. {
  1834. return $this->LE . '--' . $boundary . '--' . $this->LE;
  1835. }
  1836. /**
  1837. * Set the message type.
  1838. * PHPMailer only supports some preset message types,
  1839. * not arbitrary MIME structures.
  1840. * @access protected
  1841. * @return void
  1842. */
  1843. protected function setMessageType()
  1844. {
  1845. $this->message_type = array();
  1846. if ($this->alternativeExists()) {
  1847. $this->message_type[] = 'alt';
  1848. }
  1849. if ($this->inlineImageExists()) {
  1850. $this->message_type[] = 'inline';
  1851. }
  1852. if ($this->attachmentExists()) {
  1853. $this->message_type[] = 'attach';
  1854. }
  1855. $this->message_type = implode('_', $this->message_type);
  1856. if ($this->message_type == '') {
  1857. $this->message_type = 'plain';
  1858. }
  1859. }
  1860. /**
  1861. * Format a header line.
  1862. * @access public
  1863. * @param string $name
  1864. * @param string $value
  1865. * @return string
  1866. */
  1867. public function headerLine($name, $value)
  1868. {
  1869. return $name . ': ' . $value . $this->LE;
  1870. }
  1871. /**
  1872. * Return a formatted mail line.
  1873. * @access public
  1874. * @param string $value
  1875. * @return string
  1876. */
  1877. public function textLine($value)
  1878. {
  1879. return $value . $this->LE;
  1880. }
  1881. /**
  1882. * Add an attachment from a path on the filesystem.
  1883. * Returns false if the file could not be found or read.
  1884. * @param string $path Path to the attachment.
  1885. * @param string $name Overrides the attachment name.
  1886. * @param string $encoding File encoding (see $Encoding).
  1887. * @param string $type File extension (MIME) type.
  1888. * @param string $disposition Disposition to use
  1889. * @throws phpmailerException
  1890. * @return bool
  1891. */
  1892. public function addAttachment($path, $name = '', $encoding = 'base64', $type = '', $disposition = 'attachment')
  1893. {
  1894. try {
  1895. if (!@is_file($path)) {
  1896. throw new phpmailerException($this->lang('file_access') . $path, self::STOP_CONTINUE);
  1897. }
  1898. //If a MIME type is not specified, try to work it out from the file name
  1899. if ($type == '') {
  1900. $type = self::filenameToType($path);
  1901. }
  1902. $filename = basename($path);
  1903. if ($name == '') {
  1904. $name = $filename;
  1905. }
  1906. $this->attachment[] = array(
  1907. 0 => $path,
  1908. 1 => $filename,
  1909. 2 => $name,
  1910. 3 => $encoding,
  1911. 4 => $type,
  1912. 5 => false, // isStringAttachment
  1913. 6 => $disposition,
  1914. 7 => 0
  1915. );
  1916. } catch (phpmailerException $exc) {
  1917. $this->setError($exc->getMessage());
  1918. $this->edebug($exc->getMessage());
  1919. if ($this->exceptions) {
  1920. throw $exc;
  1921. }
  1922. return false;
  1923. }
  1924. return true;
  1925. }
  1926. /**
  1927. * Return the array of attachments.
  1928. * @return array
  1929. */
  1930. public function getAttachments()
  1931. {
  1932. return $this->attachment;
  1933. }
  1934. /**
  1935. * Attach all file, string, and binary attachments to the message.
  1936. * Returns an empty string on failure.
  1937. * @access protected
  1938. * @param string $disposition_type
  1939. * @param string $boundary
  1940. * @return string
  1941. */
  1942. protected function attachAll($disposition_type, $boundary)
  1943. {
  1944. // Return text of body
  1945. $mime = array();
  1946. $cidUniq = array();
  1947. $incl = array();
  1948. // Add all attachments
  1949. foreach ($this->attachment as $attachment) {
  1950. // Check if it is a valid disposition_filter
  1951. if ($attachment[6] == $disposition_type) {
  1952. // Check for string attachment
  1953. $string = '';
  1954. $path = '';
  1955. $bString = $attachment[5];
  1956. if ($bString) {
  1957. $string = $attachment[0];
  1958. } else {
  1959. $path = $attachment[0];
  1960. }
  1961. $inclhash = md5(serialize($attachment));
  1962. if (in_array($inclhash, $incl)) {
  1963. continue;
  1964. }
  1965. $incl[] = $inclhash;
  1966. $name = $attachment[2];
  1967. $encoding = $attachment[3];
  1968. $type = $attachment[4];
  1969. $disposition = $attachment[6];
  1970. $cid = $attachment[7];
  1971. if ($disposition == 'inline' && isset($cidUniq[$cid])) {
  1972. continue;
  1973. }
  1974. $cidUniq[$cid] = true;
  1975. $mime[] = sprintf('--%s%s', $boundary, $this->LE);
  1976. $mime[] = sprintf(
  1977. 'Content-Type: %s; name="%s"%s',
  1978. $type,
  1979. $this->encodeHeader($this->secureHeader($name)),
  1980. $this->LE
  1981. );
  1982. //RFC1341 part 5 says 7bit is assumed if not specified
  1983. if ($encoding != '7bit') {
  1984. $mime[] = sprintf('Content-Transfer-Encoding: %s%s', $encoding, $this->LE);
  1985. }
  1986. if ($disposition == 'inline') {
  1987. $mime[] = sprintf('Content-ID: <%s>%s', $cid, $this->LE);
  1988. }
  1989. // If a filename contains any of these chars, it should be quoted,
  1990. // but not otherwise: RFC2183 & RFC2045 5.1
  1991. // Fixes a warning in IETF's msglint MIME checker
  1992. // Allow for bypassing the Content-Disposition header totally
  1993. if (!(empty($disposition))) {
  1994. if (preg_match('/[ \(\)<>@,;:\\"\/\[\]\?=]/', $name)) {
  1995. $mime[] = sprintf(
  1996. 'Content-Disposition: %s; filename="%s"%s',
  1997. $disposition,
  1998. $this->encodeHeader($this->secureHeader($name)),
  1999. $this->LE . $this->LE
  2000. );
  2001. } else {
  2002. $mime[] = sprintf(
  2003. 'Content-Disposition: %s; filename=%s%s',
  2004. $disposition,
  2005. $this->encodeHeader($this->secureHeader($name)),
  2006. $this->LE . $this->LE
  2007. );
  2008. }
  2009. } else {
  2010. $mime[] = $this->LE;
  2011. }
  2012. // Encode as string attachment
  2013. if ($bString) {
  2014. $mime[] = $this->encodeString($string, $encoding);
  2015. if ($this->isError()) {
  2016. return '';
  2017. }
  2018. $mime[] = $this->LE . $this->LE;
  2019. } else {
  2020. $mime[] = $this->encodeFile($path, $encoding);
  2021. if ($this->isError()) {
  2022. return '';
  2023. }
  2024. $mime[] = $this->LE . $this->LE;
  2025. }
  2026. }
  2027. }
  2028. $mime[] = sprintf('--%s--%s', $boundary, $this->LE);
  2029. return implode('', $mime);
  2030. }
  2031. /**
  2032. * Encode a file attachment in requested format.
  2033. * Returns an empty string on failure.
  2034. * @param string $path The full path to the file
  2035. * @param string $encoding The encoding to use; one of 'base64', '7bit', '8bit', 'binary', 'quoted-printable'
  2036. * @throws phpmailerException
  2037. * @see EncodeFile(encodeFile
  2038. * @access protected
  2039. * @return string
  2040. */
  2041. protected function encodeFile($path, $encoding = 'base64')
  2042. {
  2043. try {
  2044. if (!is_readable($path)) {
  2045. throw new phpmailerException($this->lang('file_open') . $path, self::STOP_CONTINUE);
  2046. }
  2047. $magic_quotes = get_magic_quotes_runtime();
  2048. if ($magic_quotes) {
  2049. if (version_compare(PHP_VERSION, '5.3.0', '<')) {
  2050. set_magic_quotes_runtime(0);
  2051. } else {
  2052. ini_set('magic_quotes_runtime', 0);
  2053. }
  2054. }
  2055. $file_buffer = file_get_contents($path);
  2056. $file_buffer = $this->encodeString($file_buffer, $encoding);
  2057. if ($magic_quotes) {
  2058. if (version_compare(PHP_VERSION, '5.3.0', '<')) {
  2059. set_magic_quotes_runtime($magic_quotes);
  2060. } else {
  2061. ini_set('magic_quotes_runtime', $magic_quotes);
  2062. }
  2063. }
  2064. return $file_buffer;
  2065. } catch (Exception $exc) {
  2066. $this->setError($exc->getMessage());
  2067. return '';
  2068. }
  2069. }
  2070. /**
  2071. * Encode a string in requested format.
  2072. * Returns an empty string on failure.
  2073. * @param string $str The text to encode
  2074. * @param string $encoding The encoding to use; one of 'base64', '7bit', '8bit', 'binary', 'quoted-printable'
  2075. * @access public
  2076. * @return string
  2077. */
  2078. public function encodeString($str, $encoding = 'base64')
  2079. {
  2080. $encoded = '';
  2081. switch (strtolower($encoding)) {
  2082. case 'base64':
  2083. $encoded = chunk_split(base64_encode($str), 76, $this->LE);
  2084. break;
  2085. case '7bit':
  2086. case '8bit':
  2087. $encoded = $this->fixEOL($str);
  2088. //Make sure it ends with a line break
  2089. if (substr($encoded, -(strlen($this->LE))) != $this->LE) {
  2090. $encoded .= $this->LE;
  2091. }
  2092. break;
  2093. case 'binary':
  2094. $encoded = $str;
  2095. break;
  2096. case 'quoted-printable':
  2097. $encoded = $this->encodeQP($str);
  2098. break;
  2099. default:
  2100. $this->setError($this->lang('encoding') . $encoding);
  2101. break;
  2102. }
  2103. return $encoded;
  2104. }
  2105. /**
  2106. * Encode a header string optimally.
  2107. * Picks shortest of Q, B, quoted-printable or none.
  2108. * @access public
  2109. * @param string $str
  2110. * @param string $position
  2111. * @return string
  2112. */
  2113. public function encodeHeader($str, $position = 'text')
  2114. {
  2115. $matchcount = 0;
  2116. switch (strtolower($position)) {
  2117. case 'phrase':
  2118. if (!preg_match('/[\200-\377]/', $str)) {
  2119. // Can't use addslashes as we don't know the value of magic_quotes_sybase
  2120. $encoded = addcslashes($str, "\0..\37\177\\\"");
  2121. if (($str == $encoded) && !preg_match('/[^A-Za-z0-9!#$%&\'*+\/=?^_`{|}~ -]/', $str)) {
  2122. return ($encoded);
  2123. } else {
  2124. return ("\"$encoded\"");
  2125. }
  2126. }
  2127. $matchcount = preg_match_all('/[^\040\041\043-\133\135-\176]/', $str, $matches);
  2128. break;
  2129. /** @noinspection PhpMissingBreakStatementInspection */
  2130. case 'comment':
  2131. $matchcount = preg_match_all('/[()"]/', $str, $matches);
  2132. // Intentional fall-through
  2133. case 'text':
  2134. default:
  2135. $matchcount += preg_match_all('/[\000-\010\013\014\016-\037\177-\377]/', $str, $matches);
  2136. break;
  2137. }
  2138. if ($matchcount == 0) { //There are no chars that need encoding
  2139. return ($str);
  2140. }
  2141. $maxlen = 75 - 7 - strlen($this->CharSet);
  2142. // Try to select the encoding which should produce the shortest output
  2143. if ($matchcount > strlen($str) / 3) {
  2144. //More than a third of the content will need encoding, so B encoding will be most efficient
  2145. $encoding = 'B';
  2146. if (function_exists('mb_strlen') && $this->hasMultiBytes($str)) {
  2147. // Use a custom function which correctly encodes and wraps long
  2148. // multibyte strings without breaking lines within a character
  2149. $encoded = $this->base64EncodeWrapMB($str, "\n");
  2150. } else {
  2151. $encoded = base64_encode($str);
  2152. $maxlen -= $maxlen % 4;
  2153. $encoded = trim(chunk_split($encoded, $maxlen, "\n"));
  2154. }
  2155. } else {
  2156. $encoding = 'Q';
  2157. $encoded = $this->encodeQ($str, $position);
  2158. $encoded = $this->wrapText($encoded, $maxlen, true);
  2159. $encoded = str_replace('=' . self::CRLF, "\n", trim($encoded));
  2160. }
  2161. $encoded = preg_replace('/^(.*)$/m', ' =?' . $this->CharSet . "?$encoding?\\1?=", $encoded);
  2162. $encoded = trim(str_replace("\n", $this->LE, $encoded));
  2163. return $encoded;
  2164. }
  2165. /**
  2166. * Check if a string contains multi-byte characters.
  2167. * @access public
  2168. * @param string $str multi-byte text to wrap encode
  2169. * @return bool
  2170. */
  2171. public function hasMultiBytes($str)
  2172. {
  2173. if (function_exists('mb_strlen')) {
  2174. return (strlen($str) > mb_strlen($str, $this->CharSet));
  2175. } else { // Assume no multibytes (we can't handle without mbstring functions anyway)
  2176. return false;
  2177. }
  2178. }
  2179. /**
  2180. * Does a string contain any 8-bit chars (in any charset)?
  2181. * @param string $text
  2182. * @return bool
  2183. */
  2184. public function has8bitChars($text)
  2185. {
  2186. return (bool)preg_match('/[\x80-\xFF]/', $text);
  2187. }
  2188. /**
  2189. * Encode and wrap long multibyte strings for mail headers
  2190. * without breaking lines within a character.
  2191. * Adapted from a function by paravoid
  2192. * @link http://www.php.net/manual/en/function.mb-encode-mimeheader.php#60283
  2193. * @access public
  2194. * @param string $str multi-byte text to wrap encode
  2195. * @param string $linebreak string to use as linefeed/end-of-line
  2196. * @return string
  2197. */
  2198. public function base64EncodeWrapMB($str, $linebreak = null)
  2199. {
  2200. $start = '=?' . $this->CharSet . '?B?';
  2201. $end = '?=';
  2202. $encoded = '';
  2203. if ($linebreak === null) {
  2204. $linebreak = $this->LE;
  2205. }
  2206. $mb_length = mb_strlen($str, $this->CharSet);
  2207. // Each line must have length <= 75, including $start and $end
  2208. $length = 75 - strlen($start) - strlen($end);
  2209. // Average multi-byte ratio
  2210. $ratio = $mb_length / strlen($str);
  2211. // Base64 has a 4:3 ratio
  2212. $avgLength = floor($length * $ratio * .75);
  2213. for ($i = 0; $i < $mb_length; $i += $offset) {
  2214. $lookBack = 0;
  2215. do {
  2216. $offset = $avgLength - $lookBack;
  2217. $chunk = mb_substr($str, $i, $offset, $this->CharSet);
  2218. $chunk = base64_encode($chunk);
  2219. $lookBack++;
  2220. } while (strlen($chunk) > $length);
  2221. $encoded .= $chunk . $linebreak;
  2222. }
  2223. // Chomp the last linefeed
  2224. $encoded = substr($encoded, 0, -strlen($linebreak));
  2225. return $encoded;
  2226. }
  2227. /**
  2228. * Encode a string in quoted-printable format.
  2229. * According to RFC2045 section 6.7.
  2230. * @access public
  2231. * @param string $string The text to encode
  2232. * @param integer $line_max Number of chars allowed on a line before wrapping
  2233. * @return string
  2234. * @link http://www.php.net/manual/en/function.quoted-printable-decode.php#89417 Adapted from this comment
  2235. */
  2236. public function encodeQP($string, $line_max = 76)
  2237. {
  2238. if (function_exists('quoted_printable_encode')) { //Use native function if it's available (>= PHP5.3)
  2239. return $this->fixEOL(quoted_printable_encode($string));
  2240. }
  2241. //Fall back to a pure PHP implementation
  2242. $string = str_replace(
  2243. array('%20', '%0D%0A.', '%0D%0A', '%'),
  2244. array(' ', "\r\n=2E", "\r\n", '='),
  2245. rawurlencode($string)
  2246. );
  2247. $string = preg_replace('/[^\r\n]{' . ($line_max - 3) . '}[^=\r\n]{2}/', "$0=\r\n", $string);
  2248. return $this->fixEOL($string);
  2249. }
  2250. /**
  2251. * Backward compatibility wrapper for an old QP encoding function that was removed.
  2252. * @see PHPMailer::encodeQP()
  2253. * @access public
  2254. * @param string $string
  2255. * @param integer $line_max
  2256. * @param bool $space_conv
  2257. * @return string
  2258. * @deprecated Use encodeQP instead.
  2259. */
  2260. public function encodeQPphp(
  2261. $string,
  2262. $line_max = 76,
  2263. /** @noinspection PhpUnusedParameterInspection */ $space_conv = false
  2264. ) {
  2265. return $this->encodeQP($string, $line_max);
  2266. }
  2267. /**
  2268. * Encode a string using Q encoding.
  2269. * @link http://tools.ietf.org/html/rfc2047
  2270. * @param string $str the text to encode
  2271. * @param string $position Where the text is going to be used, see the RFC for what that means
  2272. * @access public
  2273. * @return string
  2274. */
  2275. public function encodeQ($str, $position = 'text')
  2276. {
  2277. //There should not be any EOL in the string
  2278. $pattern = '';
  2279. $encoded = str_replace(array("\r", "\n"), '', $str);
  2280. switch (strtolower($position)) {
  2281. case 'phrase':
  2282. //RFC 2047 section 5.3
  2283. $pattern = '^A-Za-z0-9!*+\/ -';
  2284. break;
  2285. /** @noinspection PhpMissingBreakStatementInspection */
  2286. case 'comment':
  2287. //RFC 2047 section 5.2
  2288. $pattern = '\(\)"';
  2289. //intentional fall-through
  2290. //for this reason we build the $pattern without including delimiters and []
  2291. case 'text':
  2292. default:
  2293. //RFC 2047 section 5.1
  2294. //Replace every high ascii, control, =, ? and _ characters
  2295. $pattern = '\000-\011\013\014\016-\037\075\077\137\177-\377' . $pattern;
  2296. break;
  2297. }
  2298. $matches = array();
  2299. if (preg_match_all("/[{$pattern}]/", $encoded, $matches)) {
  2300. //If the string contains an '=', make sure it's the first thing we replace
  2301. //so as to avoid double-encoding
  2302. $eqkey = array_search('=', $matches[0]);
  2303. if ($eqkey !== false) {
  2304. unset($matches[0][$eqkey]);
  2305. array_unshift($matches[0], '=');
  2306. }
  2307. foreach (array_unique($matches[0]) as $char) {
  2308. $encoded = str_replace($char, '=' . sprintf('%02X', ord($char)), $encoded);
  2309. }
  2310. }
  2311. //Replace every spaces to _ (more readable than =20)
  2312. return str_replace(' ', '_', $encoded);
  2313. }
  2314. /**
  2315. * Add a string or binary attachment (non-filesystem).
  2316. * This method can be used to attach ascii or binary data,
  2317. * such as a BLOB record from a database.
  2318. * @param string $string String attachment data.
  2319. * @param string $filename Name of the attachment.
  2320. * @param string $encoding File encoding (see $Encoding).
  2321. * @param string $type File extension (MIME) type.
  2322. * @param string $disposition Disposition to use
  2323. * @return void
  2324. */
  2325. public function addStringAttachment(
  2326. $string,
  2327. $filename,
  2328. $encoding = 'base64',
  2329. $type = '',
  2330. $disposition = 'attachment'
  2331. ) {
  2332. //If a MIME type is not specified, try to work it out from the file name
  2333. if ($type == '') {
  2334. $type = self::filenameToType($filename);
  2335. }
  2336. // Append to $attachment array
  2337. $this->attachment[] = array(
  2338. 0 => $string,
  2339. 1 => $filename,
  2340. 2 => basename($filename),
  2341. 3 => $encoding,
  2342. 4 => $type,
  2343. 5 => true, // isStringAttachment
  2344. 6 => $disposition,
  2345. 7 => 0
  2346. );
  2347. }
  2348. /**
  2349. * Add an embedded (inline) attachment from a file.
  2350. * This can include images, sounds, and just about any other document type.
  2351. * These differ from 'regular' attachmants in that they are intended to be
  2352. * displayed inline with the message, not just attached for download.
  2353. * This is used in HTML messages that embed the images
  2354. * the HTML refers to using the $cid value.
  2355. * @param string $path Path to the attachment.
  2356. * @param string $cid Content ID of the attachment; Use this to reference
  2357. * the content when using an embedded image in HTML.
  2358. * @param string $name Overrides the attachment name.
  2359. * @param string $encoding File encoding (see $Encoding).
  2360. * @param string $type File MIME type.
  2361. * @param string $disposition Disposition to use
  2362. * @return bool True on successfully adding an attachment
  2363. */
  2364. public function addEmbeddedImage($path, $cid, $name = '', $encoding = 'base64', $type = '', $disposition = 'inline')
  2365. {
  2366. if (!@is_file($path)) {
  2367. $this->setError($this->lang('file_access') . $path);
  2368. return false;
  2369. }
  2370. //If a MIME type is not specified, try to work it out from the file name
  2371. if ($type == '') {
  2372. $type = self::filenameToType($path);
  2373. }
  2374. $filename = basename($path);
  2375. if ($name == '') {
  2376. $name = $filename;
  2377. }
  2378. // Append to $attachment array
  2379. $this->attachment[] = array(
  2380. 0 => $path,
  2381. 1 => $filename,
  2382. 2 => $name,
  2383. 3 => $encoding,
  2384. 4 => $type,
  2385. 5 => false, // isStringAttachment
  2386. 6 => $disposition,
  2387. 7 => $cid
  2388. );
  2389. return true;
  2390. }
  2391. /**
  2392. * Add an embedded stringified attachment.
  2393. * This can include images, sounds, and just about any other document type.
  2394. * Be sure to set the $type to an image type for images:
  2395. * JPEG images use 'image/jpeg', GIF uses 'image/gif', PNG uses 'image/png'.
  2396. * @param string $string The attachment binary data.
  2397. * @param string $cid Content ID of the attachment; Use this to reference
  2398. * the content when using an embedded image in HTML.
  2399. * @param string $name
  2400. * @param string $encoding File encoding (see $Encoding).
  2401. * @param string $type MIME type.
  2402. * @param string $disposition Disposition to use
  2403. * @return bool True on successfully adding an attachment
  2404. */
  2405. public function addStringEmbeddedImage(
  2406. $string,
  2407. $cid,
  2408. $name = '',
  2409. $encoding = 'base64',
  2410. $type = '',
  2411. $disposition = 'inline'
  2412. ) {
  2413. //If a MIME type is not specified, try to work it out from the name
  2414. if ($type == '') {
  2415. $type = self::filenameToType($name);
  2416. }
  2417. // Append to $attachment array
  2418. $this->attachment[] = array(
  2419. 0 => $string,
  2420. 1 => $name,
  2421. 2 => $name,
  2422. 3 => $encoding,
  2423. 4 => $type,
  2424. 5 => true, // isStringAttachment
  2425. 6 => $disposition,
  2426. 7 => $cid
  2427. );
  2428. return true;
  2429. }
  2430. /**
  2431. * Check if an inline attachment is present.
  2432. * @access public
  2433. * @return bool
  2434. */
  2435. public function inlineImageExists()
  2436. {
  2437. foreach ($this->attachment as $attachment) {
  2438. if ($attachment[6] == 'inline') {
  2439. return true;
  2440. }
  2441. }
  2442. return false;
  2443. }
  2444. /**
  2445. * Check if an attachment (non-inline) is present.
  2446. * @return bool
  2447. */
  2448. public function attachmentExists()
  2449. {
  2450. foreach ($this->attachment as $attachment) {
  2451. if ($attachment[6] == 'attachment') {
  2452. return true;
  2453. }
  2454. }
  2455. return false;
  2456. }
  2457. /**
  2458. * Check if this message has an alternative body set.
  2459. * @return bool
  2460. */
  2461. public function alternativeExists()
  2462. {
  2463. return !empty($this->AltBody);
  2464. }
  2465. /**
  2466. * Clear all To recipients.
  2467. * @return void
  2468. */
  2469. public function clearAddresses()
  2470. {
  2471. foreach ($this->to as $to) {
  2472. unset($this->all_recipients[strtolower($to[0])]);
  2473. }
  2474. $this->to = array();
  2475. }
  2476. /**
  2477. * Clear all CC recipients.
  2478. * @return void
  2479. */
  2480. public function clearCCs()
  2481. {
  2482. foreach ($this->cc as $cc) {
  2483. unset($this->all_recipients[strtolower($cc[0])]);
  2484. }
  2485. $this->cc = array();
  2486. }
  2487. /**
  2488. * Clear all BCC recipients.
  2489. * @return void
  2490. */
  2491. public function clearBCCs()
  2492. {
  2493. foreach ($this->bcc as $bcc) {
  2494. unset($this->all_recipients[strtolower($bcc[0])]);
  2495. }
  2496. $this->bcc = array();
  2497. }
  2498. /**
  2499. * Clear all ReplyTo recipients.
  2500. * @return void
  2501. */
  2502. public function clearReplyTos()
  2503. {
  2504. $this->ReplyTo = array();
  2505. }
  2506. /**
  2507. * Clear all recipient types.
  2508. * @return void
  2509. */
  2510. public function clearAllRecipients()
  2511. {
  2512. $this->to = array();
  2513. $this->cc = array();
  2514. $this->bcc = array();
  2515. $this->all_recipients = array();
  2516. }
  2517. /**
  2518. * Clear all filesystem, string, and binary attachments.
  2519. * @return void
  2520. */
  2521. public function clearAttachments()
  2522. {
  2523. $this->attachment = array();
  2524. }
  2525. /**
  2526. * Clear all custom headers.
  2527. * @return void
  2528. */
  2529. public function clearCustomHeaders()
  2530. {
  2531. $this->CustomHeader = array();
  2532. }
  2533. /**
  2534. * Add an error message to the error container.
  2535. * @access protected
  2536. * @param string $msg
  2537. * @return void
  2538. */
  2539. protected function setError($msg)
  2540. {
  2541. $this->error_count++;
  2542. if ($this->Mailer == 'smtp' and !is_null($this->smtp)) {
  2543. $lasterror = $this->smtp->getError();
  2544. if (!empty($lasterror) and array_key_exists('smtp_msg', $lasterror)) {
  2545. $msg .= '<p>' . $this->lang('smtp_error') . $lasterror['smtp_msg'] . "</p>\n";
  2546. }
  2547. }
  2548. $this->ErrorInfo = $msg;
  2549. }
  2550. /**
  2551. * Return an RFC 822 formatted date.
  2552. * @access public
  2553. * @return string
  2554. * @static
  2555. */
  2556. public static function rfcDate()
  2557. {
  2558. //Set the time zone to whatever the default is to avoid 500 errors
  2559. //Will default to UTC if it's not set properly in php.ini
  2560. date_default_timezone_set(@date_default_timezone_get());
  2561. return date('D, j M Y H:i:s O');
  2562. }
  2563. /**
  2564. * Get the server hostname.
  2565. * Returns 'localhost.localdomain' if unknown.
  2566. * @access protected
  2567. * @return string
  2568. */
  2569. protected function serverHostname()
  2570. {
  2571. $result = 'localhost.localdomain';
  2572. if (!empty($this->Hostname)) {
  2573. $result = $this->Hostname;
  2574. } elseif (isset($_SERVER) and array_key_exists('SERVER_NAME', $_SERVER) and !empty($_SERVER['SERVER_NAME'])) {
  2575. $result = $_SERVER['SERVER_NAME'];
  2576. } elseif (function_exists('gethostname') && gethostname() !== false) {
  2577. $result = gethostname();
  2578. } elseif (php_uname('n') !== false) {
  2579. $result = php_uname('n');
  2580. }
  2581. return $result;
  2582. }
  2583. /**
  2584. * Get an error message in the current language.
  2585. * @access protected
  2586. * @param string $key
  2587. * @return string
  2588. */
  2589. protected function lang($key)
  2590. {
  2591. if (count($this->language) < 1) {
  2592. $this->setLanguage('en'); // set the default language
  2593. }
  2594. if (isset($this->language[$key])) {
  2595. return $this->language[$key];
  2596. } else {
  2597. return 'Language string failed to load: ' . $key;
  2598. }
  2599. }
  2600. /**
  2601. * Check if an error occurred.
  2602. * @access public
  2603. * @return bool True if an error did occur.
  2604. */
  2605. public function isError()
  2606. {
  2607. return ($this->error_count > 0);
  2608. }
  2609. /**
  2610. * Ensure consistent line endings in a string.
  2611. * Changes every end of line from CRLF, CR or LF to $this->LE.
  2612. * @access public
  2613. * @param string $str String to fixEOL
  2614. * @return string
  2615. */
  2616. public function fixEOL($str)
  2617. {
  2618. // Normalise to \n
  2619. $nstr = str_replace(array("\r\n", "\r"), "\n", $str);
  2620. // Now convert LE as needed
  2621. if ($this->LE !== "\n") {
  2622. $nstr = str_replace("\n", $this->LE, $nstr);
  2623. }
  2624. return $nstr;
  2625. }
  2626. /**
  2627. * Add a custom header.
  2628. * $name value can be overloaded to contain
  2629. * both header name and value (name:value)
  2630. * @access public
  2631. * @param string $name Custom header name
  2632. * @param string $value Header value
  2633. * @return void
  2634. */
  2635. public function addCustomHeader($name, $value = null)
  2636. {
  2637. if ($value === null) {
  2638. // Value passed in as name:value
  2639. $this->CustomHeader[] = explode(':', $name, 2);
  2640. } else {
  2641. $this->CustomHeader[] = array($name, $value);
  2642. }
  2643. }
  2644. /**
  2645. * Create a message from an HTML string.
  2646. * Automatically makes modifications for inline images and backgrounds
  2647. * and creates a plain-text version by converting the HTML.
  2648. * Overwrites any existing values in $this->Body and $this->AltBody
  2649. * @access public
  2650. * @param string $message HTML message string
  2651. * @param string $basedir baseline directory for path
  2652. * @param bool $advanced Whether to use the advanced HTML to text converter
  2653. * @return string $message
  2654. */
  2655. public function msgHTML($message, $basedir = '', $advanced = false)
  2656. {
  2657. preg_match_all('/(src|background)=["\'](.*)["\']/Ui', $message, $images);
  2658. if (isset($images[2])) {
  2659. foreach ($images[2] as $imgindex => $url) {
  2660. // do not change urls for absolute images (thanks to corvuscorax)
  2661. if (!preg_match('#^[A-z]+://#', $url)) {
  2662. $filename = basename($url);
  2663. $directory = dirname($url);
  2664. if ($directory == '.') {
  2665. $directory = '';
  2666. }
  2667. $cid = md5($url) . '@phpmailer.0'; //RFC2392 S 2
  2668. if (strlen($basedir) > 1 && substr($basedir, -1) != '/') {
  2669. $basedir .= '/';
  2670. }
  2671. if (strlen($directory) > 1 && substr($directory, -1) != '/') {
  2672. $directory .= '/';
  2673. }
  2674. if ($this->addEmbeddedImage(
  2675. $basedir . $directory . $filename,
  2676. $cid,
  2677. $filename,
  2678. 'base64',
  2679. self::_mime_types(self::mb_pathinfo($filename, PATHINFO_EXTENSION))
  2680. )
  2681. ) {
  2682. $message = preg_replace(
  2683. '/' . $images[1][$imgindex] . '=["\']' . preg_quote($url, '/') . '["\']/Ui',
  2684. $images[1][$imgindex] . '="cid:' . $cid . '"',
  2685. $message
  2686. );
  2687. }
  2688. }
  2689. }
  2690. }
  2691. $this->isHTML(true);
  2692. //Convert all message body line breaks to CRLF, makes quoted-printable encoding work much better
  2693. $this->Body = $this->normalizeBreaks($message);
  2694. $this->AltBody = $this->normalizeBreaks($this->html2text($message, $advanced));
  2695. if (empty($this->AltBody)) {
  2696. $this->AltBody = 'To view this email message, open it in a program that understands HTML!' .
  2697. self::CRLF . self::CRLF;
  2698. }
  2699. return $this->Body;
  2700. }
  2701. /**
  2702. * Convert an HTML string into plain text.
  2703. * @param string $html The HTML text to convert
  2704. * @param bool $advanced Should this use the more complex html2text converter or just a simple one?
  2705. * @return string
  2706. */
  2707. public function html2text($html, $advanced = false)
  2708. {
  2709. if ($advanced) {
  2710. require_once 'extras/class.html2text.php';
  2711. $htmlconverter = new html2text($html);
  2712. return $htmlconverter->get_text();
  2713. }
  2714. return html_entity_decode(
  2715. trim(strip_tags(preg_replace('/<(head|title|style|script)[^>]*>.*?<\/\\1>/si', '', $html))),
  2716. ENT_QUOTES,
  2717. $this->CharSet
  2718. );
  2719. }
  2720. /**
  2721. * Get the MIME type for a file extension.
  2722. * @param string $ext File extension
  2723. * @access public
  2724. * @return string MIME type of file.
  2725. * @static
  2726. */
  2727. public static function _mime_types($ext = '')
  2728. {
  2729. $mimes = array(
  2730. 'xl' => 'application/excel',
  2731. 'hqx' => 'application/mac-binhex40',
  2732. 'cpt' => 'application/mac-compactpro',
  2733. 'bin' => 'application/macbinary',
  2734. 'doc' => 'application/msword',
  2735. 'word' => 'application/msword',
  2736. 'class' => 'application/octet-stream',
  2737. 'dll' => 'application/octet-stream',
  2738. 'dms' => 'application/octet-stream',
  2739. 'exe' => 'application/octet-stream',
  2740. 'lha' => 'application/octet-stream',
  2741. 'lzh' => 'application/octet-stream',
  2742. 'psd' => 'application/octet-stream',
  2743. 'sea' => 'application/octet-stream',
  2744. 'so' => 'application/octet-stream',
  2745. 'oda' => 'application/oda',
  2746. 'pdf' => 'application/pdf',
  2747. 'ai' => 'application/postscript',
  2748. 'eps' => 'application/postscript',
  2749. 'ps' => 'application/postscript',
  2750. 'smi' => 'application/smil',
  2751. 'smil' => 'application/smil',
  2752. 'mif' => 'application/vnd.mif',
  2753. 'xls' => 'application/vnd.ms-excel',
  2754. 'ppt' => 'application/vnd.ms-powerpoint',
  2755. 'wbxml' => 'application/vnd.wap.wbxml',
  2756. 'wmlc' => 'application/vnd.wap.wmlc',
  2757. 'dcr' => 'application/x-director',
  2758. 'dir' => 'application/x-director',
  2759. 'dxr' => 'application/x-director',
  2760. 'dvi' => 'application/x-dvi',
  2761. 'gtar' => 'application/x-gtar',
  2762. 'php3' => 'application/x-httpd-php',
  2763. 'php4' => 'application/x-httpd-php',
  2764. 'php' => 'application/x-httpd-php',
  2765. 'phtml' => 'application/x-httpd-php',
  2766. 'phps' => 'application/x-httpd-php-source',
  2767. 'js' => 'application/x-javascript',
  2768. 'swf' => 'application/x-shockwave-flash',
  2769. 'sit' => 'application/x-stuffit',
  2770. 'tar' => 'application/x-tar',
  2771. 'tgz' => 'application/x-tar',
  2772. 'xht' => 'application/xhtml+xml',
  2773. 'xhtml' => 'application/xhtml+xml',
  2774. 'zip' => 'application/zip',
  2775. 'mid' => 'audio/midi',
  2776. 'midi' => 'audio/midi',
  2777. 'mp2' => 'audio/mpeg',
  2778. 'mp3' => 'audio/mpeg',
  2779. 'mpga' => 'audio/mpeg',
  2780. 'aif' => 'audio/x-aiff',
  2781. 'aifc' => 'audio/x-aiff',
  2782. 'aiff' => 'audio/x-aiff',
  2783. 'ram' => 'audio/x-pn-realaudio',
  2784. 'rm' => 'audio/x-pn-realaudio',
  2785. 'rpm' => 'audio/x-pn-realaudio-plugin',
  2786. 'ra' => 'audio/x-realaudio',
  2787. 'wav' => 'audio/x-wav',
  2788. 'bmp' => 'image/bmp',
  2789. 'gif' => 'image/gif',
  2790. 'jpeg' => 'image/jpeg',
  2791. 'jpe' => 'image/jpeg',
  2792. 'jpg' => 'image/jpeg',
  2793. 'png' => 'image/png',
  2794. 'tiff' => 'image/tiff',
  2795. 'tif' => 'image/tiff',
  2796. 'eml' => 'message/rfc822',
  2797. 'css' => 'text/css',
  2798. 'html' => 'text/html',
  2799. 'htm' => 'text/html',
  2800. 'shtml' => 'text/html',
  2801. 'log' => 'text/plain',
  2802. 'text' => 'text/plain',
  2803. 'txt' => 'text/plain',
  2804. 'rtx' => 'text/richtext',
  2805. 'rtf' => 'text/rtf',
  2806. 'vcf' => 'text/vcard',
  2807. 'vcard' => 'text/vcard',
  2808. 'xml' => 'text/xml',
  2809. 'xsl' => 'text/xml',
  2810. 'mpeg' => 'video/mpeg',
  2811. 'mpe' => 'video/mpeg',
  2812. 'mpg' => 'video/mpeg',
  2813. 'mov' => 'video/quicktime',
  2814. 'qt' => 'video/quicktime',
  2815. 'rv' => 'video/vnd.rn-realvideo',
  2816. 'avi' => 'video/x-msvideo',
  2817. 'movie' => 'video/x-sgi-movie'
  2818. );
  2819. return (array_key_exists(strtolower($ext), $mimes) ? $mimes[strtolower($ext)]: 'application/octet-stream');
  2820. }
  2821. /**
  2822. * Map a file name to a MIME type.
  2823. * Defaults to 'application/octet-stream', i.e.. arbitrary binary data.
  2824. * @param string $filename A file name or full path, does not need to exist as a file
  2825. * @return string
  2826. * @static
  2827. */
  2828. public static function filenameToType($filename)
  2829. {
  2830. //In case the path is a URL, strip any query string before getting extension
  2831. $qpos = strpos($filename, '?');
  2832. if ($qpos !== false) {
  2833. $filename = substr($filename, 0, $qpos);
  2834. }
  2835. $pathinfo = self::mb_pathinfo($filename);
  2836. return self::_mime_types($pathinfo['extension']);
  2837. }
  2838. /**
  2839. * Multi-byte-safe pathinfo replacement.
  2840. * Drop-in replacement for pathinfo(), but multibyte-safe, cross-platform-safe, old-version-safe.
  2841. * Works similarly to the one in PHP >= 5.2.0
  2842. * @link http://www.php.net/manual/en/function.pathinfo.php#107461
  2843. * @param string $path A filename or path, does not need to exist as a file
  2844. * @param integer|string $options Either a PATHINFO_* constant,
  2845. * or a string name to return only the specified piece, allows 'filename' to work on PHP < 5.2
  2846. * @return string|array
  2847. * @static
  2848. */
  2849. public static function mb_pathinfo($path, $options = null)
  2850. {
  2851. $ret = array('dirname' => '', 'basename' => '', 'extension' => '', 'filename' => '');
  2852. $pathinfo = array();
  2853. preg_match('%^(.*?)[\\\\/]*(([^/\\\\]*?)(\.([^\.\\\\/]+?)|))[\\\\/\.]*$%im', $path, $pathinfo);
  2854. if (array_key_exists(1, $pathinfo)) {
  2855. $ret['dirname'] = $pathinfo[1];
  2856. }
  2857. if (array_key_exists(2, $pathinfo)) {
  2858. $ret['basename'] = $pathinfo[2];
  2859. }
  2860. if (array_key_exists(5, $pathinfo)) {
  2861. $ret['extension'] = $pathinfo[5];
  2862. }
  2863. if (array_key_exists(3, $pathinfo)) {
  2864. $ret['filename'] = $pathinfo[3];
  2865. }
  2866. switch ($options) {
  2867. case PATHINFO_DIRNAME:
  2868. case 'dirname':
  2869. return $ret['dirname'];
  2870. break;
  2871. case PATHINFO_BASENAME:
  2872. case 'basename':
  2873. return $ret['basename'];
  2874. break;
  2875. case PATHINFO_EXTENSION:
  2876. case 'extension':
  2877. return $ret['extension'];
  2878. break;
  2879. case PATHINFO_FILENAME:
  2880. case 'filename':
  2881. return $ret['filename'];
  2882. break;
  2883. default:
  2884. return $ret;
  2885. }
  2886. }
  2887. /**
  2888. * Set or reset instance properties.
  2889. *
  2890. * Usage Example:
  2891. * $page->set('X-Priority', '3');
  2892. *
  2893. * @access public
  2894. * @param string $name
  2895. * @param mixed $value
  2896. * NOTE: will not work with arrays, there are no arrays to set/reset
  2897. * @throws phpmailerException
  2898. * @return bool
  2899. * @todo Should this not be using __set() magic function?
  2900. */
  2901. public function set($name, $value = '')
  2902. {
  2903. try {
  2904. if (isset($this->$name)) {
  2905. $this->$name = $value;
  2906. } else {
  2907. throw new phpmailerException($this->lang('variable_set') . $name, self::STOP_CRITICAL);
  2908. }
  2909. } catch (Exception $exc) {
  2910. $this->setError($exc->getMessage());
  2911. if ($exc->getCode() == self::STOP_CRITICAL) {
  2912. return false;
  2913. }
  2914. }
  2915. return true;
  2916. }
  2917. /**
  2918. * Strip newlines to prevent header injection.
  2919. * @access public
  2920. * @param string $str
  2921. * @return string
  2922. */
  2923. public function secureHeader($str)
  2924. {
  2925. return trim(str_replace(array("\r", "\n"), '', $str));
  2926. }
  2927. /**
  2928. * Normalize line breaks in a string.
  2929. * Converts UNIX LF, Mac CR and Windows CRLF line breaks into a single line break format.
  2930. * Defaults to CRLF (for message bodies) and preserves consecutive breaks.
  2931. * @param string $text
  2932. * @param string $breaktype What kind of line break to use, defaults to CRLF
  2933. * @return string
  2934. * @access public
  2935. * @static
  2936. */
  2937. public static function normalizeBreaks($text, $breaktype = "\r\n")
  2938. {
  2939. return preg_replace('/(\r\n|\r|\n)/ms', $breaktype, $text);
  2940. }
  2941. /**
  2942. * Set the public and private key files and password for S/MIME signing.
  2943. * @access public
  2944. * @param string $cert_filename
  2945. * @param string $key_filename
  2946. * @param string $key_pass Password for private key
  2947. */
  2948. public function sign($cert_filename, $key_filename, $key_pass)
  2949. {
  2950. $this->sign_cert_file = $cert_filename;
  2951. $this->sign_key_file = $key_filename;
  2952. $this->sign_key_pass = $key_pass;
  2953. }
  2954. /**
  2955. * Quoted-Printable-encode a DKIM header.
  2956. * @access public
  2957. * @param string $txt
  2958. * @return string
  2959. */
  2960. public function DKIM_QP($txt)
  2961. {
  2962. $line = '';
  2963. for ($i = 0; $i < strlen($txt); $i++) {
  2964. $ord = ord($txt[$i]);
  2965. if (((0x21 <= $ord) && ($ord <= 0x3A)) || $ord == 0x3C || ((0x3E <= $ord) && ($ord <= 0x7E))) {
  2966. $line .= $txt[$i];
  2967. } else {
  2968. $line .= '=' . sprintf('%02X', $ord);
  2969. }
  2970. }
  2971. return $line;
  2972. }
  2973. /**
  2974. * Generate a DKIM signature.
  2975. * @access public
  2976. * @param string $signheader Header
  2977. * @throws phpmailerException
  2978. * @return string
  2979. */
  2980. public function DKIM_Sign($signheader)
  2981. {
  2982. if (!defined('PKCS7_TEXT')) {
  2983. if ($this->exceptions) {
  2984. throw new phpmailerException($this->lang('signing') . ' OpenSSL extension missing.');
  2985. }
  2986. return '';
  2987. }
  2988. $privKeyStr = file_get_contents($this->DKIM_private);
  2989. if ($this->DKIM_passphrase != '') {
  2990. $privKey = openssl_pkey_get_private($privKeyStr, $this->DKIM_passphrase);
  2991. } else {
  2992. $privKey = $privKeyStr;
  2993. }
  2994. if (openssl_sign($signheader, $signature, $privKey)) {
  2995. return base64_encode($signature);
  2996. }
  2997. return '';
  2998. }
  2999. /**
  3000. * Generate a DKIM canonicalization header.
  3001. * @access public
  3002. * @param string $signheader Header
  3003. * @return string
  3004. */
  3005. public function DKIM_HeaderC($signheader)
  3006. {
  3007. $signheader = preg_replace('/\r\n\s+/', ' ', $signheader);
  3008. $lines = explode("\r\n", $signheader);
  3009. foreach ($lines as $key => $line) {
  3010. list($heading, $value) = explode(':', $line, 2);
  3011. $heading = strtolower($heading);
  3012. $value = preg_replace('/\s+/', ' ', $value); // Compress useless spaces
  3013. $lines[$key] = $heading . ':' . trim($value); // Don't forget to remove WSP around the value
  3014. }
  3015. $signheader = implode("\r\n", $lines);
  3016. return $signheader;
  3017. }
  3018. /**
  3019. * Generate a DKIM canonicalization body.
  3020. * @access public
  3021. * @param string $body Message Body
  3022. * @return string
  3023. */
  3024. public function DKIM_BodyC($body)
  3025. {
  3026. if ($body == '') {
  3027. return "\r\n";
  3028. }
  3029. // stabilize line endings
  3030. $body = str_replace("\r\n", "\n", $body);
  3031. $body = str_replace("\n", "\r\n", $body);
  3032. // END stabilize line endings
  3033. while (substr($body, strlen($body) - 4, 4) == "\r\n\r\n") {
  3034. $body = substr($body, 0, strlen($body) - 2);
  3035. }
  3036. return $body;
  3037. }
  3038. /**
  3039. * Create the DKIM header and body in a new message header.
  3040. * @access public
  3041. * @param string $headers_line Header lines
  3042. * @param string $subject Subject
  3043. * @param string $body Body
  3044. * @return string
  3045. */
  3046. public function DKIM_Add($headers_line, $subject, $body)
  3047. {
  3048. $DKIMsignatureType = 'rsa-sha1'; // Signature & hash algorithms
  3049. $DKIMcanonicalization = 'relaxed/simple'; // Canonicalization of header/body
  3050. $DKIMquery = 'dns/txt'; // Query method
  3051. $DKIMtime = time(); // Signature Timestamp = seconds since 00:00:00 - Jan 1, 1970 (UTC time zone)
  3052. $subject_header = "Subject: $subject";
  3053. $headers = explode($this->LE, $headers_line);
  3054. $from_header = '';
  3055. $to_header = '';
  3056. $current = '';
  3057. foreach ($headers as $header) {
  3058. if (strpos($header, 'From:') === 0) {
  3059. $from_header = $header;
  3060. $current = 'from_header';
  3061. } elseif (strpos($header, 'To:') === 0) {
  3062. $to_header = $header;
  3063. $current = 'to_header';
  3064. } else {
  3065. if ($current && strpos($header, ' =?') === 0) {
  3066. $current .= $header;
  3067. } else {
  3068. $current = '';
  3069. }
  3070. }
  3071. }
  3072. $from = str_replace('|', '=7C', $this->DKIM_QP($from_header));
  3073. $to = str_replace('|', '=7C', $this->DKIM_QP($to_header));
  3074. $subject = str_replace(
  3075. '|',
  3076. '=7C',
  3077. $this->DKIM_QP($subject_header)
  3078. ); // Copied header fields (dkim-quoted-printable)
  3079. $body = $this->DKIM_BodyC($body);
  3080. $DKIMlen = strlen($body); // Length of body
  3081. $DKIMb64 = base64_encode(pack('H*', sha1($body))); // Base64 of packed binary SHA-1 hash of body
  3082. $ident = ($this->DKIM_identity == '') ? '' : ' i=' . $this->DKIM_identity . ';';
  3083. $dkimhdrs = 'DKIM-Signature: v=1; a=' .
  3084. $DKIMsignatureType . '; q=' .
  3085. $DKIMquery . '; l=' .
  3086. $DKIMlen . '; s=' .
  3087. $this->DKIM_selector .
  3088. ";\r\n" .
  3089. "\tt=" . $DKIMtime . '; c=' . $DKIMcanonicalization . ";\r\n" .
  3090. "\th=From:To:Subject;\r\n" .
  3091. "\td=" . $this->DKIM_domain . ';' . $ident . "\r\n" .
  3092. "\tz=$from\r\n" .
  3093. "\t|$to\r\n" .
  3094. "\t|$subject;\r\n" .
  3095. "\tbh=" . $DKIMb64 . ";\r\n" .
  3096. "\tb=";
  3097. $toSign = $this->DKIM_HeaderC(
  3098. $from_header . "\r\n" . $to_header . "\r\n" . $subject_header . "\r\n" . $dkimhdrs
  3099. );
  3100. $signed = $this->DKIM_Sign($toSign);
  3101. return $dkimhdrs . $signed . "\r\n";
  3102. }
  3103. /**
  3104. * Allows for public read access to 'to' property.
  3105. * @access public
  3106. * @return array
  3107. */
  3108. public function getToAddresses()
  3109. {
  3110. return $this->to;
  3111. }
  3112. /**
  3113. * Allows for public read access to 'cc' property.
  3114. * @access public
  3115. * @return array
  3116. */
  3117. public function getCcAddresses()
  3118. {
  3119. return $this->cc;
  3120. }
  3121. /**
  3122. * Allows for public read access to 'bcc' property.
  3123. * @access public
  3124. * @return array
  3125. */
  3126. public function getBccAddresses()
  3127. {
  3128. return $this->bcc;
  3129. }
  3130. /**
  3131. * Allows for public read access to 'ReplyTo' property.
  3132. * @access public
  3133. * @return array
  3134. */
  3135. public function getReplyToAddresses()
  3136. {
  3137. return $this->ReplyTo;
  3138. }
  3139. /**
  3140. * Allows for public read access to 'all_recipients' property.
  3141. * @access public
  3142. * @return array
  3143. */
  3144. public function getAllRecipientAddresses()
  3145. {
  3146. return $this->all_recipients;
  3147. }
  3148. /**
  3149. * Perform a callback.
  3150. * @param bool $isSent
  3151. * @param string $to
  3152. * @param string $cc
  3153. * @param string $bcc
  3154. * @param string $subject
  3155. * @param string $body
  3156. * @param string $from
  3157. */
  3158. protected function doCallback($isSent, $to, $cc, $bcc, $subject, $body, $from = null)
  3159. {
  3160. if (!empty($this->action_function) && is_callable($this->action_function)) {
  3161. $params = array($isSent, $to, $cc, $bcc, $subject, $body, $from);
  3162. call_user_func_array($this->action_function, $params);
  3163. }
  3164. }
  3165. }
  3166. /**
  3167. * PHPMailer exception handler
  3168. * @package PHPMailer
  3169. */
  3170. class phpmailerException extends Exception
  3171. {
  3172. /**
  3173. * Prettify error message output
  3174. * @return string
  3175. */
  3176. public function errorMessage()
  3177. {
  3178. $errorMsg = '<strong>' . $this->getMessage() . "</strong><br />\n";
  3179. return $errorMsg;
  3180. }
  3181. }