PageRenderTime 64ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 1ms

/PHPMailer/class.phpmailer.php

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