whoami7 - Manager
:
/
home
/
n170823s
/
public_html
/
forms
/
Upload File:
files >> //home/n170823s/public_html/forms/send.php
<?php if ($_SERVER["REQUEST_METHOD"] === "POST") { // ====== Config ====== $to = "steservicesltd@gmail.com, satyam.it016@gmail.com"; $subject = "New Application Form Submission"; $from = "contact@nvqandcourses.co.uk"; $replyTo = "contact@nvqandcourses.co.uk"; $maxFiles = 3; $maxFileSize = 5 * 1024 * 1024; // 5MB $allowedExt = ['pdf','jpg','jpeg','png']; // ====== Build HTML message from POST ====== $messageHtml = "<h2>New Application Received</h2>"; $messageHtml .= "<table style='border-collapse: collapse; border: 1px solid #000; width: 100%;'>"; foreach ($_POST as $key => $value) { // Skip empty values to keep email tidy if (is_array($value)) { $value = implode(", ", array_map('htmlspecialchars', $value)); } else { $value = htmlspecialchars($value); } $label = htmlspecialchars(ucfirst(str_replace("_", " ", $key))); $messageHtml .= "<tr><td style='border: 1px solid #000; padding: 6px;'><strong>{$label}:</strong></td><td style='border: 1px solid #000; padding: 6px;'>{$value}</td></tr>"; } $messageHtml .= "</table>"; // ====== Handle file uploads (attachments) ====== $attachments = []; if (!empty($_FILES['documents']) && is_array($_FILES['documents']['name'])) { $fileCount = count($_FILES['documents']['name']); if ($fileCount > $maxFiles) { $fileCount = $maxFiles; // hard cap } for ($i = 0; $i < $fileCount; $i++) { if ($_FILES['documents']['error'][$i] === UPLOAD_ERR_NO_FILE) { continue; } if ($_FILES['documents']['error'][$i] !== UPLOAD_ERR_OK) { continue; // skip problematic file silently } if ($_FILES['documents']['size'][$i] > $maxFileSize) { continue; // skip too large } $originalName = $_FILES['documents']['name'][$i]; $tmpPath = $_FILES['documents']['tmp_name'][$i]; $ext = strtolower(pathinfo($originalName, PATHINFO_EXTENSION)); if (!in_array($ext, $allowedExt)) { continue; // skip not-allowed } $fileData = file_get_contents($tmpPath); if ($fileData === false) { continue; // skip if unreadable } // Best-effort mime type $mime = mime_content_type($tmpPath); if ($mime === false) { // fallback common types $mime = ($ext === 'pdf') ? 'application/pdf' : 'application/octet-stream'; } $attachments[] = [ 'name' => $originalName, 'mime' => $mime, 'data' => chunk_split(base64_encode($fileData)), ]; } } // ====== Build multipart email with attachments (native mail) ====== $boundaryMain = "==Multipart_Boundary_x" . md5(uniqid(time())) . "x"; $boundaryAlt = "==Alt_Boundary_x" . md5(uniqid(time())) . "x"; $headers = "From: {$from}\r\n"; $headers .= "Reply-To: {$replyTo}\r\n"; $headers .= "MIME-Version: 1.0\r\n"; $headers .= "Content-Type: multipart/mixed; boundary=\"{$boundaryMain}\"\r\n"; $body = "This is a multi-part message in MIME format.\r\n\r\n"; $body .= "--{$boundaryMain}\r\n"; $body .= "Content-Type: multipart/alternative; boundary=\"{$boundaryAlt}\"\r\n\r\n"; // HTML part $body .= "--{$boundaryAlt}\r\n"; $body .= "Content-Type: text/html; charset=UTF-8\r\n"; $body .= "Content-Transfer-Encoding: 7bit\r\n\r\n"; $body .= $messageHtml . "\r\n\r\n"; // (Optional) Plain text part (fallback) $plain = strip_tags(str_replace(["</td><td>", "</tr>"], [" : ", "\n"], $messageHtml)); $body .= "--{$boundaryAlt}\r\n"; $body .= "Content-Type: text/plain; charset=UTF-8\r\n"; $body .= "Content-Transfer-Encoding: 7bit\r\n\r\n"; $body .= $plain . "\r\n\r\n"; $body .= "--{$boundaryAlt}--\r\n"; // Attachments foreach ($attachments as $att) { $safeName = preg_replace('/[^A-Za-z0-9._-]/', '_', $att['name']); $body .= "--{$boundaryMain}\r\n"; $body .= "Content-Type: {$att['mime']}; name=\"{$safeName}\"\r\n"; $body .= "Content-Transfer-Encoding: base64\r\n"; $body .= "Content-Disposition: attachment; filename=\"{$safeName}\"\r\n\r\n"; $body .= $att['data'] . "\r\n\r\n"; } $body .= "--{$boundaryMain}--"; // ====== Send ====== if (mail($to, $subject, $body, $headers)) { echo "<h2>✅ Thank you! Your application has been submitted successfully.</h2>"; } else { echo "<h2>❌ Sorry, something went wrong. Please try again.</h2>"; } } ?>
Copyright ©2021 || Defacer Indonesia