| 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_live_LoCEd8u2DwbRHy', '9yamMaYbnDAx9uftlcH4MSaX');
// Function to send email
function sendEmail($userEmail, $userName, $paymentId, $amount, $adminEmail) {
$mail = new PHPMailer(true);
try {
// Email configuration
$mail->isSMTP();
$mail->Host = 'smtp.gmail.com';
$mail->SMTPAuth = true;
$mail->Username = 'gyaniguru.jmc@gmail.com';
$mail->Password = 'aaoawvpnscmlmkgx'; // Use App Password instead
$mail->SMTPSecure = 'tls';
$mail->Port = 587;
// Email to User
$mail->setFrom('gyaniguru.jmc@gmail.com', 'GyaniGuru');
$mail->addAddress($userEmail, $userName);
$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>
";
$mail->send();
// Email to Admin
$mail->clearAddresses();
$mail->addAddress($adminEmail, 'Admin');
$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>
";
$mail->send();
return true;
} catch (Exception $e) {
error_log("Mailer Error: {$mail->ErrorInfo}");
return false;
}
}
// Process Razorpay Response
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$data = json_decode(file_get_contents('php://input'), true);
$paymentId = $data['razorpay_payment_id'] ?? '';
$orderId = $data['razorpay_order_id'] ?? '';
$signature = $data['razorpay_signature'] ?? '';
$userName = $data['name'] ?? '';
$userEmail = $data['email'] ?? '';
$contact = $data['contact'] ?? '';
$amount = $data['amount'] ?? 29900; // Get amount from frontend
try {
// Verify Razorpay Signature
$attributes = [
'razorpay_payment_id' => $paymentId,
'razorpay_order_id' => $orderId,
'razorpay_signature' => $signature
];
$api->utility->verifyPaymentSignature($attributes);
// Send Email
$adminEmail = 'gyaniguru.jmc@gmail.com';
$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.']);
}
} catch (Exception $e) {
error_log("Razorpay Error: " . $e->getMessage());
echo json_encode(['error' => 'Payment verification failed.']);
}
}
?>