MMCT TEAM
Server IP : 103.191.208.50  /  Your IP : 216.73.216.226
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 : 5.6.40
Disable Function : show_source, system, shell_exec, passthru, exec
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : ON
Directory (0750) :  /home/celkcksm/bmtrust.org.in/../rmpharma.in/

[  Home  ][  C0mmand  ][  Upload File  ]

Current File : /home/celkcksm/bmtrust.org.in/../rmpharma.in/mail.php
<?php



error_reporting(E_ALL);

ini_set('display_errors', 1);



require 'php_mailer/Exception.php';

require 'php_mailer/PHPMailer.php';

require 'php_mailer/SMTP.php';



use PHPMailer\PHPMailer\PHPMailer;

use PHPMailer\PHPMailer\Exception;



$recipient_address = "office.rangamaticp@gmail.com";



if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    if (isset($_POST['g-recaptcha-response']) && !empty($_POST['g-recaptcha-response'])) {
        $mail = new PHPMailer(true);
        try {

            // SMTP Configuration

            $mail->isSMTP();

            $mail->Host = 'mail.rmpharma.in';

            $mail->SMTPAuth = true;

            $mail->Username = 'admin@rmpharma.in'; // SMTP username

            $mail->Password = '&NJH.@Xlu?F9Fb(&';     // SMTP password

            $mail->SMTPSecure = PHPMailer::ENCRYPTION_SMTPS;

            $mail->Port = 465;

            $mail->isHTML(true);



            // Get form type

            $mail_type = isset($_POST['mail_type']) ? trim($_POST['mail_type']) : '';



            if (!$mail_type) {

                echo json_encode(['status' => false, 'message' => 'Form type not provided.']);

                exit;
            }



            // Common Fields

            $name = filter_var($_POST['name'] ?? '', FILTER_SANITIZE_FULL_SPECIAL_CHARS);

            $email = filter_var($_POST['email'] ?? '', FILTER_VALIDATE_EMAIL);

            $phone = preg_replace('/\D/', '', $_POST['phone'] ?? '');

            $message = filter_var($_POST['message'] ?? '', FILTER_SANITIZE_FULL_SPECIAL_CHARS);

            $course = filter_var($_POST['course'] ?? '', FILTER_SANITIZE_FULL_SPECIAL_CHARS);



            // Validate common fields

            if (!$name || strlen($name) < 2) {

                throw new Exception("Name must be at least 2 characters.");
            }

            if (!$email) {

                throw new Exception("Valid email is required.");
            }

            if (!preg_match("/^[0-9]{10,15}$/", $phone)) {

                throw new Exception("Phone number must be between 10 and 15 digits.");
            }

            if (!$course) {

                throw new Exception("Course selection is required.");
            }



            // Additional Fields

            $extra_fields = "";

            if ($mail_type === 'admission_form') {

                $dob = filter_var($_POST['dob'] ?? '', FILTER_SANITIZE_STRING);

                $gender = filter_var($_POST['gender'] ?? '', FILTER_SANITIZE_STRING);

                $qualification = filter_var($_POST['qualification'] ?? '', FILTER_SANITIZE_STRING);

                $address = filter_var($_POST['address'] ?? '', FILTER_SANITIZE_STRING);



                $extra_fields = "

                    <p><strong>Date of Birth:</strong> $dob</p>

                    <p><strong>Gender:</strong> $gender</p>

                    <p><strong>Qualification:</strong> $qualification</p>

                    <p><strong>Address:</strong> $address</p>";
            } elseif ($mail_type === 'enquiry_form') {

                $subject = filter_var($_POST['subject'] ?? '', FILTER_SANITIZE_STRING);

                $extra_fields = "<p><strong>Subject:</strong> $subject</p>";
            } elseif ($mail_type === 'career_form') {

                $position = filter_var($_POST['position'] ?? '', FILTER_SANITIZE_STRING);

                $resume = $_FILES['resume'] ?? null;



                $extra_fields = "<p><strong>Position Applied For:</strong> $position</p>";



                // Attach resume if uploaded

                if ($resume && $resume['error'] === UPLOAD_ERR_OK) {

                    $mail->addAttachment($resume['tmp_name'], $resume['name']);
                } elseif ($resume && $resume['error'] !== UPLOAD_ERR_NO_FILE) {

                    throw new Exception("Resume upload error.");
                }
            }



            // Set subject using match

            $mail_subjects = [

                'admission_form' => 'New Admission Form Submission',

                'enquiry_form'   => 'New Enquiry Form Submission',

                'career_form'    => 'New Career Application',

            ];



            $mail_subject = $mail_subjects[$mail_type] ?? 'New Form Submission';





            // Email content

            $mail_body = "<h2>New Submission</h2>

                          <p><strong>Name:</strong> $name</p>

                          <p><strong>Email:</strong> $email</p>

                          <p><strong>Phone:</strong> $phone</p>

                          <p><strong>Course:</strong> $course</p>

                          $extra_fields

                          <p><strong>Message:</strong> $message</p>";



            // Set sender and recipient

            $mail->setFrom('admin@gitanjalicn.in', 'Admission Portal');

            $mail->addAddress($recipient_address);

            $mail->Subject = $mail_subject;

            $mail->Body = $mail_body;



            // Send the mail

            $mail->send();

            echo json_encode(['status' => true, 'message' => "Your message has been sent successfully!"]);
        } catch (Exception $e) {

            echo json_encode(['status' => false, 'message' => 'Mail Error: ' . $mail->ErrorInfo]);
        }
    } else {

        echo json_encode(['status' => false, 'message' => "Please verify you are not a robot"]);
    }
} else {

    echo json_encode(['status' => false, 'message' => "Invalid request method"]);
}

MMCT - 2023