403Webshell
Server IP : 193.86.120.172  /  Your IP : 216.73.216.67
Web Server : Apache/2.4.63 (Unix)
System : Linux JServices 3.10.108 #86003 SMP Wed Oct 22 13:20:46 CST 2025 x86_64
User : kubec ( 1026)
PHP Version : 8.2.28
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : OFF  |  Sudo : ON  |  Pkexec : OFF
Directory :  /volume1/web/hotellesnizatisi_cz/new/includes/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /volume1/web/hotellesnizatisi_cz/new/includes/smtp.php
<?php
// ============================================================
// Minimalistický SMTP klient bez závislostí (žádný Composer/
// PHPMailer není na NASu k dispozici) — posílá e-mail přes
// účet info@hotellesnizatisi.cz na Seznam.cz (SSL, port 465).
// ============================================================

require_once __DIR__ . '/config.php';

/**
 * Pošle jeden e-mail přes SMTP jako multipart/alternative (HTML + textová
 * záloha pro klienty/filtry, co HTML nezobrazí). Vrací true/false podle
 * úspěchu a do PHP error logu zapíše, na kterém kroku to případně selhalo.
 */
function smtp_send_mail(string $toEmail, string $subject, string $textBody, string $htmlBody, ?string $replyToEmail = null, ?string $replyToName = null): bool
{
    $errno = 0;
    $errstr = '';
    $socket = @stream_socket_client(
        'ssl://' . SMTP_HOST . ':' . SMTP_PORT,
        $errno,
        $errstr,
        15
    );

    if (!$socket) {
        error_log("SMTP: nepodařilo se připojit (" . SMTP_HOST . ':' . SMTP_PORT . ") — {$errstr} ({$errno})");
        return false;
    }

    $readResponse = function () use ($socket): string {
        $data = '';
        while (($line = fgets($socket, 515)) !== false) {
            $data .= $line;
            if (isset($line[3]) && $line[3] === ' ') {
                break;
            }
        }
        return $data;
    };

    $sendLine = function (string $cmd) use ($socket): void {
        fwrite($socket, $cmd . "\r\n");
    };

    $codeOf = function (string $resp): int {
        return (int) substr($resp, 0, 3);
    };

    $step = function (string $label, ?string $cmd, array $okCodes) use ($socket, $sendLine, $readResponse, $codeOf): bool {
        if ($cmd !== null) {
            $sendLine($cmd);
        }
        $resp = $readResponse();
        if (!in_array($codeOf($resp), $okCodes, true)) {
            error_log("SMTP: selhalo na kroku '{$label}': " . trim($resp));
            return false;
        }
        return true;
    };

    if (!$step('connect', null, [220])) { fclose($socket); return false; }
    if (!$step('EHLO', 'EHLO hotellesnizatisi.cz', [250])) { fclose($socket); return false; }
    if (!$step('AUTH LOGIN', 'AUTH LOGIN', [334])) { fclose($socket); return false; }
    if (!$step('AUTH user', base64_encode(SMTP_USER), [334])) { fclose($socket); return false; }
    if (!$step('AUTH pass', base64_encode(SMTP_PASS), [235])) { fclose($socket); return false; }
    if (!$step('MAIL FROM', 'MAIL FROM:<' . SMTP_FROM_EMAIL . '>', [250])) { fclose($socket); return false; }
    if (!$step('RCPT TO', 'RCPT TO:<' . $toEmail . '>', [250, 251])) { fclose($socket); return false; }
    if (!$step('DATA', 'DATA', [354])) { fclose($socket); return false; }

    $normalize = function (string $s): string {
        $s = str_replace(["\r\n", "\r", "\n"], "\n", $s);
        return str_replace("\n", "\r\n", $s);
    };

    $boundary = 'bound_' . bin2hex(random_bytes(12));

    $fromNameEnc = '=?UTF-8?B?' . base64_encode(SMTP_FROM_NAME) . '?=';
    $headers  = "From: {$fromNameEnc} <" . SMTP_FROM_EMAIL . ">\r\n";
    $headers .= "To: <{$toEmail}>\r\n";
    if ($replyToEmail) {
        $replyNameEnc = $replyToName !== null && $replyToName !== ''
            ? '=?UTF-8?B?' . base64_encode($replyToName) . '?=' : '';
        $headers .= "Reply-To: {$replyNameEnc} <{$replyToEmail}>\r\n";
    }
    $headers .= "Subject: =?UTF-8?B?" . base64_encode($subject) . "?=\r\n";
    $headers .= "MIME-Version: 1.0\r\n";
    $headers .= "Content-Type: multipart/alternative; boundary=\"{$boundary}\"\r\n";
    $headers .= "Date: " . date('r') . "\r\n";

    $message  = "--{$boundary}\r\n";
    $message .= "Content-Type: text/plain; charset=UTF-8\r\n";
    $message .= "Content-Transfer-Encoding: 8bit\r\n\r\n";
    $message .= $normalize($textBody) . "\r\n\r\n";
    $message .= "--{$boundary}\r\n";
    $message .= "Content-Type: text/html; charset=UTF-8\r\n";
    $message .= "Content-Transfer-Encoding: 8bit\r\n\r\n";
    $message .= $normalize($htmlBody) . "\r\n\r\n";
    $message .= "--{$boundary}--";

    // Tečky na začátku řádku se v SMTP DATA musí zdvojit (byte-stuffing)
    $fullData = $headers . "\r\n" . $message;
    $escapedData = preg_replace('/^\./m', '..', $fullData);

    if (!$step('DATA body', $escapedData . "\r\n.", [250])) { fclose($socket); return false; }

    $sendLine('QUIT');
    fclose($socket);

    return true;
}

Youez - 2016 - github.com/yon3zu
LinuXploit