MMCT TEAM
Server IP : 217.21.85.138  /  Your IP : 216.73.216.103
Web Server : LiteSpeed
System : Linux in-mum-web906.main-hosting.eu 4.18.0-553.37.1.lve.el8.x86_64 #1 SMP Mon Feb 10 22:45:17 UTC 2025 x86_64
User : u915722082 ( 915722082)
PHP Version : 7.4.33
Disable Function : system, exec, shell_exec, passthru, mysql_list_dbs, ini_alter, dl, symlink, link, chgrp, leak, popen, apache_child_terminate, virtual, mb_send_mail
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : OFF  |  Python : OFF
Directory (0755) :  /home/u915722082/.nvm/../public_html/rasi/

[  Home  ][  C0mmand  ][  Upload File  ]

Current File : /home/u915722082/.nvm/../public_html/rasi/mailto.php
<?php
	use PHPMailer\PHPMailer\PHPMailer;
	use PHPMailer\PHPMailer\SMTP;
	use PHPMailer\PHPMailer\Exception;

// Enable error reporting for debugging
error_reporting(E_ALL);
ini_set('display_errors', 1);

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

// Set header for JSON response
header('Content-Type: application/json');

// Check if it's a POST request
if ($_SERVER["REQUEST_METHOD"] !== "POST") {
    echo json_encode(["status" => "error", "message" => "Invalid request method"]);
    exit;
}

// Debug: Log POST data
error_log("POST data received: " . print_r($_POST, true));

// Collect and validate POST data
$name = isset($_POST['FirstName']) ? trim($_POST['FirstName']) : '';
$lname = isset($_POST['LastName']) ? trim($_POST['LastName']) : '';
$email = isset($_POST['emailInput']) ? trim($_POST['emailInput']) : '';
$phone = isset($_POST['Phone_Number']) ? trim($_POST['Phone_Number']) : '';
$program = isset($_POST['program']) ? trim($_POST['program']) : '';
$message = isset($_POST['message']) ? trim($_POST['message']) : '';

// Validate required fields
if (empty($name) || empty($email)) {
    echo json_encode(["status" => "error", "message" => "Please fill in all required fields"]);
    exit;
}

// Validate email format
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
    echo json_encode(["status" => "error", "message" => "Please enter a valid email address"]);
    exit;
}

try {
    $mail = new PHPMailer(true);

    // Debug SMTP
    $mail->SMTPDebug = 3; // Enable verbose debug output
    $mail->Debugoutput = function($str, $level) {
        error_log("PHPMailer debug: $str");
    };

    // Server settings
    $mail->isSMTP();
    $mail->Host = 'smtp.gmail.com';
    $mail->SMTPAuth = true;
    $mail->Username = 'admin@rasicoachinginstitute.com';
    $mail->Password = 'khfi kyei pjxv uwae';
    $mail->SMTPSecure = PHPMailer::ENCRYPTION_SMTPS;
    $mail->Port = 465;
    
    // SSL/TLS Settings
    $mail->SMTPOptions = array(
        'ssl' => array(
            'verify_peer' => false,
            'verify_peer_name' => false,
            'allow_self_signed' => true
        )
    );

    // Set timeout
    $mail->Timeout = 30;

    // Sender
    $mail->setFrom('admin@rasicoachinginstitute.com', 'Rasi International School');
    
    // Admin email
    $mail->addAddress('admin@rasicoachinginstitute.com');
    $mail->isHTML(true);
    $mail->Subject = 'New Website Enquiry';
    
    // Admin email content
    $adminBody = "
    <html>
    <body style='font-family: Arial, sans-serif;'>
        <h2>New Enquiry Details</h2>
        <table style='border-collapse: collapse; width: 100%;'>
            <tr><td><strong>Name:</strong></td><td>$name $lname</td></tr>
            <tr><td><strong>Email:</strong></td><td>$email</td></tr>
            <tr><td><strong>Phone:</strong></td><td>$phone</td></tr>
            <tr><td><strong>Program:</strong></td><td>$program</td></tr>
            <tr><td><strong>Message:</strong></td><td>$message</td></tr>
        </table>
    </body>
    </html>";

    $mail->Body = $adminBody;

    // Send admin email
    if (!$mail->send()) {
        throw new Exception("Admin email failed: " . $mail->ErrorInfo);
    }

    // Reset for customer email
    $mail->clearAddresses();
    $mail->clearReplyTos();

    // Customer email
    $mail->addAddress($email, $name);
    $mail->Subject = 'Thank You for Your Enquiry - Rasi International School';
    
    // Customer email content
    $customerBody = "
    <html>
    <body style='font-family: Arial, sans-serif;'>
    <img src='https://rasi.thedotstudios.com/assets/images/rasilogo.png' style='height:50px;width:auto;object-fit:cover;'>
        <h2>Dear $name $lname,</h2>
        <p>Thank you for your enquiry. We have received your message and will contact you shortly.</p>
        <p>Your enquiry details:</p>
        <ul>
            <li>Program: $program</li>
            <li>Phone: $phone</li>
        </ul>
        <p>If you have any questions, please contact us at:</p>
        <p>Phone: +91 63820 57075<br>
        Email: admin@rasicoachinginstitute.com</p>
        <br>
        <p>Best regards,<br>Rasi International School</p>
    </body>
    </html>";

    $mail->Body = $customerBody;

    // Send customer email
    if (!$mail->send()) {
        throw new Exception("Customer email failed: " . $mail->ErrorInfo);
    }

    echo json_encode([
        "status" => "success",
        "message" => "Thank you! Your message has been sent successfully."
    ]);

} catch (Exception $e) {
    error_log("Mailer Error: " . $e->getMessage());
    echo json_encode([
        "status" => "error",
        "message" => "An error occurred while sending your message. Please try again later.",
        "debug" => $e->getMessage()
    ]);
}
?>

MMCT - 2023