IsSMTP(); $mail -> SMTPAuth = true; $mail -> Host = 'mail.ostal.pl'; $mail -> Port = 25; $mail -> Username = 'konfigurator@ostal.pl'; $mail -> Password = 'x6rpeUG5tW'; $mail -> CharSet = "UTF-8"; $mail -> SMTPOptions = array( 'ssl' => array( 'verify_peer' => false, 'verify_peer_name' => false, 'allow_self_signed' => true ) ); $mail -> From = 'konfigurator@ostal.pl'; $mail -> FromName = 'Ostal'; $mail -> addAddress( $email, $email ); $mail -> addReplyTo( $reply, $reply ); $mail -> isHTML( true ); $mail -> Subject = $subject; $mail -> Body = $text; // Obsługa wielu załączników if (is_array($attachments) && count($attachments) > 0) { foreach ($attachments as $attachment) { if (isset($attachment['tmp_name']) && file_exists($attachment['tmp_name'])) { $mail->addAttachment($attachment['tmp_name'], $attachment['name']); } } } return $mail -> send(); } function validate_file($file) { $maxSize = 10 * 1024 * 1024; // 10MB $allowedExtensions = array('jpg', 'jpeg', 'png', 'pdf', 'doc', 'docx', 'xls', 'xlsx'); $allowedMimeTypes = array( 'image/jpeg', 'image/jpg', 'image/png', 'application/pdf', 'application/msword', 'application/vnd.openxmlformats-officedocument.wordprocessingml.document', 'application/vnd.ms-excel', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' ); // Sprawdź czy plik istnieje if (!isset($file['tmp_name']) || !file_exists($file['tmp_name'])) { return array('valid' => false, 'error' => 'Plik nie istnieje'); } // Sprawdź rozmiar if ($file['size'] > $maxSize) { return array('valid' => false, 'error' => 'Plik jest za duży (max 10MB)'); } // Sprawdź rozszerzenie $fileExtension = strtolower(pathinfo($file['name'], PATHINFO_EXTENSION)); if (!in_array($fileExtension, $allowedExtensions)) { return array('valid' => false, 'error' => 'Niedozwolone rozszerzenie pliku'); } // Sprawdź MIME type $finfo = finfo_open(FILEINFO_MIME_TYPE); $mimeType = finfo_file($finfo, $file['tmp_name']); finfo_close($finfo); if (!in_array($mimeType, $allowedMimeTypes)) { return array('valid' => false, 'error' => 'Niedozwolony typ pliku'); } return array('valid' => true); } if ($_SERVER['REQUEST_METHOD'] === 'POST') { $configData = json_decode($_POST['configData'], true); // Pobierz wszystkie załączniki $attachments = array(); $attachments_count = isset($_POST['attachments_count']) ? intval($_POST['attachments_count']) : 0; // Walidacja liczby załączników (max 10) if ($attachments_count > 10) { echo json_encode(['status' => 'error', 'message' => 'Maksymalnie 10 załączników']); exit(); } for ($i = 0; $i < $attachments_count; $i++) { $fileKey = 'attachment_' . $i; if (isset($_FILES[$fileKey])) { $file = $_FILES[$fileKey]; // Walidacja pliku $validation = validate_file($file); if (!$validation['valid']) { echo json_encode(['status' => 'error', 'message' => 'Błąd walidacji pliku: ' . $validation['error']]); exit(); } $attachments[] = $file; } } $to = 'kontakt@ostal.pl'; $subject = 'ostal.pl - Konfigurator'; $message = '
' . $configData['step_1'] . '
'; $message .= 'Wymiary
'; $message .= '' . $configData['step_3'] . '
'; if (isset($configData['step_3_extra']) && $configData['step_3_extra']) { $message .= '' . $configData['step_3_extra'] . '
'; } $message .= 'Dane kontaktowe
'; $message .= 'Potwierdzenia
'; $message .= 'Załączniki (' . count($attachments) . '):
'; $message .= '