-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsubmit_subscription.php
89 lines (78 loc) · 2.96 KB
/
submit_subscription.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
<?php
session_start();
require 'db.php';
require 'vendor/autoload.php';
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
// Check request method
if ($_SERVER["REQUEST_METHOD"] == "POST") {
// Sanitize and validate form data
$tariff = htmlspecialchars($_POST['tariff']);
$email = filter_var($_POST['email'], FILTER_SANITIZE_EMAIL);
$nickname = htmlspecialchars($_POST['nickname']);
$telegram = htmlspecialchars($_POST['telegram']);
// Check for empty fields
if (empty($tariff) || empty($email) || empty($nickname) || empty($telegram)) {
echo "Please fill out all fields.";
exit();
}
// Prepare SQL query to insert data into database
$sql = "INSERT INTO subscriptions (tariff, email, nickname, telegram) VALUES (?, ?, ?, ?)";
$stmt = $pdo->prepare($sql);
try {
// Execute SQL query to insert data into database
$stmt->execute([$tariff, $email, $nickname, $telegram]);
// Send subscription notification using PHPMailer
$mail = new PHPMailer(true);
try {
// SMTP settings
$mail->isSMTP();
$mail->Host = 'smtp.helgablue.xyz'; // Replace with your SMTP server
$mail->SMTPAuth = true;
$mail->Username = '[email protected]'; // Replace with your SMTP username
$mail->Password = 'your_email_password'; // Replace with your SMTP password
$mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS;
$mail->Port = 587;
// Sender and recipient
$mail->setFrom('[email protected]', 'No Reply');
$mail->addAddress('[email protected]'); // Replace with your recipient address
// Email content
$mail->isHTML(true);
$mail->Subject = 'New NFT Course Subscription';
$mail->Body = "Tariff: $tariff<br>Email: $email<br>Nickname: $nickname<br>Telegram: $telegram";
// Send email
$mail->send();
// Redirect to success page
header("Location: success.html");
exit();
} catch (Exception $e) {
// Redirect to error page with message
header("Location: error.html?message=" . urlencode('Error sending email: ' . $mail->ErrorInfo));
exit();
}
} catch (\PDOException $e) {
// Redirect to error page with message
header("Location: error.html?message=" . urlencode('Error saving data: ' . $e->getMessage()));
exit();
}
} else {
echo "Invalid request method.";
}
// Check user session for course access
if (!isset($_SESSION['user_email'])) {
header("Location: payment.php");
exit();
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Module 1: History of NFTs</title>
</head>
<body>
<h1>Module 1: History of NFTs</h1>
<p>Module content...</p>
</body>
</html>