|
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 ] |
|---|
<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\SMTP;
use PHPMailer\PHPMailer\Exception;
// Enable error reporting for debugging (remove in production)
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;
}
// Collect and validate POST data from popup form
$name = isset($_POST['name']) ? trim($_POST['name']) : '';
$phone = isset($_POST['phone']) ? trim($_POST['phone']) : '';
// Validate required fields
if (empty($name) || empty($phone)) {
echo json_encode(["status" => "error", "message" => "Please fill in all required fields"]);
exit;
}
// Validate phone format (basic validation)
if (!preg_match("/^[0-9]{10}$/", $phone)) {
echo json_encode(["status" => "error", "message" => "Please enter a valid 10-digit phone number"]);
exit;
}
try {
$mail = new PHPMailer(true);
// 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'); // Replace with admin email
$mail->isHTML(true);
$mail->Subject = 'New NEET & JEE Crash Course Enquiry';
// Admin email content
$adminBody = "
<html>
<body style='font-family: Arial, sans-serif;'>
<h2>New Crash Course Enquiry Details</h2>
<table style='border-collapse: collapse; width: 100%;'>
<tr><td style='padding: 8px; border: 1px solid #ddd;'><strong>Name:</strong></td><td style='padding: 8px; border: 1px solid #ddd;'>$name</td></tr>
<tr><td style='padding: 8px; border: 1px solid #ddd;'><strong>Phone:</strong></td><td style='padding: 8px; border: 1px solid #ddd;'>$phone</td></tr>
<tr><td style='padding: 8px; border: 1px solid #ddd;'><strong>Course:</strong></td><td style='padding: 8px; border: 1px solid #ddd;'>NEET & JEE 2025 Crash Course</td></tr>
<tr><td style='padding: 8px; border: 1px solid #ddd;'><strong>Source:</strong></td><td style='padding: 8px; border: 1px solid #ddd;'>Website Popup Form</td></tr>
</table>
</body>
</html>";
$mail->Body = $adminBody;
// Send admin email
if (!$mail->send()) {
throw new Exception("Admin email failed: " . $mail->ErrorInfo);
}
// Reset for SMS/notification to student
// Here you could add code to send SMS to the student using a service like Twilio
echo json_encode([
"status" => "success",
"message" => "Thank you! We've received your details and will contact you shortly."
]);
} 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()
]);
}
?>