| Server IP : 3.111.61.48 / Your IP : 216.73.216.67 Web Server : Apache System : Linux ip-10-0-5-176 6.8.0-1057-aws #60~22.04.1-Ubuntu SMP Wed May 27 08:16:59 UTC 2026 x86_64 User : ubuntu ( 1000) PHP Version : 8.2.31 Disable Function : exec,passthru,shell_exec,system MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : ON Directory : /var/www/vhost/gyaniguru.org/ |
Upload File : |
<?php
require('vendor/autoload.php'); // Composer autoload for Razorpay and PHPMailer
use Razorpay\Api\Api;
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
// Razorpay API credentials
// $api = new Api('rzp_test_idUUc7YfZtYbaZ', 'hkobqqyspaqbpJlgOuEkQg9O');
$api = new Api('rzp_live_LoCEd8u2DwbRHy', '9yamMaYbnDAx9uftlcH4MSaX');
// Create an order
try {
$orderData = [
'receipt' => 'rcptid_11',
'amount' => 9900, // Amount in paise (₹299)
'currency' => 'INR',
'payment_capture' => 1 // Auto-capture
];
$order = $api->order->create($orderData);
// Return order details as JSON
echo json_encode([
'order_id' => $order['id'],
'amount' => $order['amount'],
'currency' => $order['currency']
]);
} catch (Exception $e) {
echo json_encode(['error' => 'Error fetching order from backend!']);
}
// Function to send email to user and admin
function sendEmail($userEmail, $userName, $paymentId, $amount, $adminEmail) {
$mail = new PHPMailer(true);
try {
// Email configuration for User Confirmation
$mail->isSMTP();
$mail->Host = 'smtp.gmail.com'; // Change this to your mail server
$mail->SMTPAuth = true;
$mail->Username = 'gyaniguru.jmc@gmail.com'; // Your email
$mail->Password = 'aaoawvpnscmlmkgx'; // Your email password
$mail->SMTPSecure = 'tls';
$mail->Port = 587;
// Email content for the user
$mail->setFrom('gyaniguru.jmc@gmail.com', 'GyaniGuru'); // Sender email
$mail->addAddress($userEmail, $userName); // Recipient email and name
$mail->isHTML(true);
$mail->Subject = 'Payment Confirmation - GyaniGuru';
$mail->Body = "
<h2>Payment Confirmation</h2>
<p>Thank you for your payment!</p>
<p><strong>Payment ID:</strong> $paymentId</p>
<p><strong>Amount Paid:</strong> ₹" . ($amount / 100) . "</p>
<p>We have received your payment and your registration is confirmed.</p>
";
// Send email to user
$mail->send();
// Now, send email to the admin with user details
$mail->clearAddresses(); // Clear recipient list for user email
$mail->addAddress($adminEmail, 'Admin'); // Admin email
$mail->Subject = 'New Payment Received - User Details';
$mail->Body = "
<h2>New Payment Received</h2>
<p><strong>User Name:</strong> $userName</p>
<p><strong>User Email:</strong> $userEmail</p>
<p><strong>Payment ID:</strong> $paymentId</p>
<p><strong>Amount Paid:</strong> ₹" . ($amount / 100) . "</p>
<p>This is to inform you that a payment has been successfully received.</p>
";
// Send email to admin
$mail->send();
return true;
} catch (Exception $e) {
error_log("Mailer Error: {$mail->ErrorInfo}");
return false;
}
}
// Check payment status (this should be handled via webhook or after payment success)
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['payment_id'])) {
$userEmail = $_POST['email'];
$userName = $_POST['name'];
$paymentId = $_POST['payment_id'];
$amount = $_POST['amount']; // Amount in paise
$adminEmail = 'admin@example.com'; // Admin email
// Send confirmation email to user and admin
$emailSent = sendEmail($userEmail, $userName, $paymentId, $amount, $adminEmail);
if ($emailSent) {
echo json_encode(['success' => 'Email sent successfully!']);
} else {
echo json_encode(['error' => 'Failed to send email.']);
}
}
?>