Server : LiteSpeed System : Linux in-mum-web1949.main-hosting.eu 5.14.0-503.40.1.el9_5.x86_64 #1 SMP PREEMPT_DYNAMIC Mon May 5 06:06:04 EDT 2025 x86_64 User : u595547767 ( 595547767) PHP Version : 7.4.33 Disable Function : NONE Directory : /home/u595547767/domains/nilasevasamithi.com/public_html/ |
<?php
// Check if the form is submitted
if ($_SERVER["REQUEST_METHOD"] == "POST") {
// Capture form data
$name = htmlspecialchars($_POST['name']);
$email = htmlspecialchars($_POST['email']);
$phone = htmlspecialchars($_POST['mob']);
$education = htmlspecialchars($_POST['education']);
$interest = htmlspecialchars($_POST['interest']);
$message = htmlspecialchars($_POST['message']);
$message1 = htmlspecialchars($_POST['message1']);
// Handle file upload (resume)
$resume = $_FILES['resume'];
$resumeTmp = $resume['tmp_name'];
$resumeName = $resume['name'];
$resumeSize = $resume['size'];
$resumeError = $resume['error'];
// File upload validation
if ($resumeError !== UPLOAD_ERR_OK) {
echo "Error uploading the resume file!";
exit;
}
// Validate file type (PDF or DOCX)
$allowedTypes = ['application/pdf', 'application/vnd.openxmlformats-officedocument.wordprocessingml.document'];
$fileType = mime_content_type($resumeTmp);
if (!in_array($fileType, $allowedTypes)) {
echo "Invalid file type. Only PDF and DOCX files are allowed.";
exit;
}
// Optionally: Move the uploaded resume to a directory on the server
$uploadDir = 'uploads/';
if (!is_dir($uploadDir)) {
mkdir($uploadDir, 0777, true);
}
$uploadPath = $uploadDir . basename($resumeName);
if (!move_uploaded_file($resumeTmp, $uploadPath)) {
echo "Error saving the resume file!";
exit;
}
// Prepare email
$to = 'testing@360degreekerala.com'; // The recipient email address (Hiring Manager)
$subject = "Job Application from $name";
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-Type: multipart/mixed; boundary=\"boundary12345\"" . "\r\n";
$headers .= "From: $email" . "\r\n";
$body = "--boundary12345\r\n";
$body .= "Content-Type: text/plain; charset=UTF-8\r\n\r\n";
$body .= "Name: $name\r\n";
$body .= "Email: $email\r\n";
$body .= "Phone: $phone\r\n";
$body .= "Educational Qualification: $education\r\n";
$body .= "Area of Interest: $interest\r\n";
$body .= "Why do you want to join Nila Sevasamithi?
: $message\r\n";
$body .= "Message:\r\n$message1\r\n\r\n";
// Attach resume to the email
$resumeContent = chunk_split(base64_encode(file_get_contents($uploadPath)));
$body .= "--boundary12345\r\n";
$body .= "Content-Type: application/octet-stream; name=\"$resumeName\"\r\n";
$body .= "Content-Transfer-Encoding: base64\r\n";
$body .= "Content-Disposition: attachment; filename=\"$resumeName\"\r\n\r\n";
$body .= $resumeContent . "\r\n";
$body .= "--boundary12345--\r\n";
// Send the email
if (mail($to, $subject, $body, $headers)) {
echo "<script>alert('Your application has been submitted successfully!');</script>";
echo "<script>window.location = 'Internship.php';</script>";
} else {
echo "Failed to send the application. Please try again later.";
}
// Optionally: Delete the uploaded resume from the server after sending the email
unlink($uploadPath);
} else {
echo "Invalid request!";
}
?>