-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsubmit_mailing.php
More file actions
51 lines (41 loc) · 1.41 KB
/
Copy pathsubmit_mailing.php
File metadata and controls
51 lines (41 loc) · 1.41 KB
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
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
echo json_encode([
'status' => 'error',
'message' => 'Invalid request method: ' . $_SERVER['REQUEST_METHOD']
]);
exit;
}
if (!isset($_POST['mailingEmail']) || empty($_POST['mailingEmail'])) {
echo json_encode([
'status' => 'error',
'message' => 'Email is required.'
]);
exit;
}
$mysqli = new mysqli("localhost", "root", "", "shieldmaidens_db", 3308);
if ($mysqli->connect_error) {
die("Connection failed: " . $mysqli->connect_error);
}
$email = $_POST['mailingEmail'];
// Insert into database
$stmt = $mysqli->prepare("INSERT IGNORE INTO mailing_list (email) VALUES (?)");
$stmt->bind_param("s", $email);
$stmt->execute();
// Comment out mail() lines for now (XAMPP mail doesn't work by default)
// $admin_email = "shi3ldmaidens@gmail.com";
// $subject = "New Mailing List Subscription";
// $body = "A new user has subscribed to your mailing list:\n\nEmail: $email";
// mail($admin_email, $subject, $body);
// $user_subject = "Thank you for subscribing to Shieldmaidens News!";
// $user_body = "Thank you for subscribing to our news! Let's get updated! 📰\n\nWith love, 💖\nShieldmaidens Team";
// mail($email, $user_subject, $user_body);
$stmt->close();
$mysqli->close();
echo json_encode([
'status' => 'success',
'message' => 'Subscription successful!'
]);
?>