|
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\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;
}
// Collect and validate POST data
$email = isset($_POST['email']) ? trim($_POST['email']) : '';
// Validate email
if (empty($email) || !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;
// Set timeout
$mail->Timeout = 30;
// Send to Admin
$mail->setFrom('admin@rasicoachinginstitute.com', 'Rasi International School');
$mail->addAddress('admin@rasicoachinginstitute.com'); // Admin email
$mail->isHTML(true);
$mail->Subject = 'New Website Enquiry';
$mail->Body = "<p>You have a new enquiry from: <strong>$email</strong></p>";
if (!$mail->send()) {
throw new Exception("Admin email failed: " . $mail->ErrorInfo);
}
// Send Confirmation to User
$mail->clearAddresses();
$mail->addAddress($email);
$mail->Subject = 'Thank You for Your Enquiry';
$mail->Body = "<p>Dear User,</p><p>Thank you for reaching out. We will get back to you soon.</p>";
if (!$mail->send()) {
throw new Exception("User email failed: " . $mail->ErrorInfo);
}
echo json_encode(["status" => "success", "message" => "Thank you! Your message has been sent successfully."]);
} catch (Exception $e) {
echo json_encode(["status" => "error", "message" => "An error occurred while sending your message. Please try again later."]);
}
?>