PageRenderTime 63ms CodeModel.GetById 19ms RepoModel.GetById 1ms app.codeStats 0ms

/class.phpmailer.php

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