MMCT TEAM
Server IP : 103.191.208.50  /  Your IP : 216.73.216.53
Web Server : LiteSpeed
System : Linux orion.herosite.pro 4.18.0-553.53.1.lve.el8.x86_64 #1 SMP Wed May 28 17:01:02 UTC 2025 x86_64
User : celkcksm ( 1031)
PHP Version : 7.4.33
Disable Function : show_source, system, shell_exec, passthru, popen, exec
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : ON
Directory (0750) :  /home/celkcksm/acadevo.in/

[  Home  ][  C0mmand  ][  Upload File  ]

Current File : /home/celkcksm/acadevo.in/mail.php
<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;

require 'php_mailer/Exception.php';
require 'php_mailer/PHPMailer.php';
require 'php_mailer/SMTP.php';

$recipient_address = "manabkantibedcollege@gmail.com"; 
// $recipient_address = "apurbakhanra09@gmail.com"; 

if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    $mail_type = isset($_POST['mail_type']) ? trim($_POST['mail_type']) : '';

    if (!$mail_type) {
        echo json_encode(['status' => false, 'message' => 'Form type not provided.']);
        exit;
    }

    $mail = new PHPMailer(true);

    try {
        // SMTP settings
        $mail->isSMTP();
        $mail->Host = 'smtp.gmail.com';
        $mail->SMTPAuth = true;
        $mail->Username = 'waytoadmissions21@gmail.com'; // Your email
        $mail->Password = 'lgle pkre mzzy sebw'; // Use an app-specific password
        $mail->SMTPSecure = PHPMailer::ENCRYPTION_SMTPS;
        $mail->Port = 465;
        $mail->isHTML(true);

        // Retrieve form data
        $name = trim($_POST['name']);
        $email = trim($_POST['email']);
        $phone = trim($_POST['phone']);
        $class = isset($_POST['class']) ? trim($_POST['class']) : '';
        $dob = isset($_POST['dob']) ? trim($_POST['dob']) : '';
        $gender = isset($_POST['gender']) ? trim($_POST['gender']) : '';
        $address = isset($_POST['address']) ? trim($_POST['address']) : '';

        // Validate fields
        $errors = validateFields($name, $email, $phone, $class, $dob, $gender, $address);
        if (!empty($errors)) {
            echo json_encode(['status' => false, 'message' => implode(", ", $errors)]);
            exit;
        }

        // Define email subject based on form type
        if ($mail_type === 'admission_form') {
            $mail_subject = 'Admission Form Submission - ' . date('d-m-Y');
        } elseif ($mail_type === 'enquiry_form') {
            $mail_subject = 'Admission Enquiry - ' . date('d-m-Y');
        } else {
            echo json_encode(['status' => false, 'message' => 'Invalid form type.']);
            exit;
        }

        $mail_body = createMailBody($name, $phone, $email, $class, $dob, $gender, $address);

        // Set email parameters
        $mail->setFrom($email, $name);
        $mail->addAddress($recipient_address);
        $mail->Subject = $mail_subject;
        $mail->Body = $mail_body;

        // Send the email
        $mail->send();
        echo json_encode(['status' => true, 'message' => "Your message has been sent successfully!"]);
    } catch (Exception $e) {
        echo json_encode(['status' => false, 'message' => 'Message could not be sent. Error: ' . $mail->ErrorInfo]);
    }
} else {
    echo json_encode(['status' => false, 'message' => "Method not allowed"]);
}

// Helper function to validate form fields
function validateFields($name, $email, $phone, $class, $dob, $gender, $address) {
    $errors = [];

    if (empty($name) || strlen($name) < 2) {
        $errors[] = "Name is required (at least 2 characters).";
    }
    if (empty($email) || !filter_var($email, FILTER_VALIDATE_EMAIL)) {
        $errors[] = "Valid email is required.";
    }
    if (empty($phone) || !preg_match("/^[0-9]{10,15}$/", $phone)) {
        $errors[] = "Phone number must be between 10 and 15 digits.";
    }
    if ($mail_type === 'admission_form' && empty($class)) {
        $errors[] = "Class selection is required.";
    }
    if ($dob && !preg_match("/\d{4}-\d{2}-\d{2}/", $dob)) {
        $errors[] = "Invalid date of birth format (YYYY-MM-DD).";
    }
    if ($mail_type === 'admission_form' && empty($gender)) {
        $errors[] = "Gender selection is required.";
    }
   
    return $errors;
}

// Helper function to generate the email body
function createMailBody($name, $phone, $email, $class, $dob, $gender, $address) {
    return '<strong>Name:</strong> ' . htmlspecialchars($name) . '<br>' .
           '<strong>Phone:</strong> ' . htmlspecialchars($phone) . '<br>' .
           '<strong>Email:</strong> ' . htmlspecialchars($email) . '<br>' .
           '<strong>Class Applied For:</strong> ' . htmlspecialchars($class) . '<br>' .
           '<strong>Date of Birth:</strong> ' . htmlspecialchars($dob) . '<br>' .
           '<strong>Gender:</strong> ' . htmlspecialchars($gender) . '<br>' .
           '<strong>Address:</strong> ' . nl2br(htmlspecialchars($address));
}
?>

MMCT - 2023