Deathger

class.phpmailer

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