<?php
require 'admin-panal/includes/db.php';
header('Content-Type: application/json');
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$email = filter_var($_POST['email'] ?? '', FILTER_VALIDATE_EMAIL);
if ($email) {
try {
$stmt = $pdo->prepare('INSERT IGNORE INTO subscribers (email) VALUES (?)');
$stmt->execute([$email]);
if ($stmt->rowCount() > 0) {
// Prepare Welcome Email
$subject = "Welcome to Elegance of India!";
// Professional HTML Email Template
$htmlMessage = '
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Welcome to Elegance of India</title>
</head>
<body style="margin: 0; padding: 0; font-family: \'Helvetica Neue\', Helvetica, Arial, sans-serif; background-color: #f4f4f4;">
<table width="100%" border="0" cellspacing="0" cellpadding="0" style="background-color: #f4f4f4; padding: 40px 20px;">
<tr>
<td align="center">
<table width="600" border="0" cellspacing="0" cellpadding="0" style="background-color: #ffffff; border-radius: 8px; overflow: hidden; box-shadow: 0 4px 15px rgba(0,0,0,0.05);">
<!-- Header -->
<tr>
<td align="center" style="background-color: #111111; padding: 40px 20px;">
<h1 style="color: #c9a96e; margin: 0; font-size: 28px; font-weight: normal; letter-spacing: 3px; text-transform: uppercase;">Elegance of India</h1>
</td>
</tr>
<!-- Body -->
<tr>
<td style="padding: 40px 40px 30px; color: #333333; line-height: 1.6;">
<h2 style="margin-top: 0; font-size: 22px; color: #111111; font-weight: 400; text-align: center;">Welcome to our community!</h2>
<p style="font-size: 15px; color: #555;">Thank you for subscribing to the <strong>Elegance of India</strong> newsletter.</p>
<p style="font-size: 15px; color: #555;">You are now on our exclusive list. Get ready to receive early access to our latest collections, special offers, and styling inspiration delivered straight to your inbox.</p>
<div style="text-align: center; margin-top: 35px; margin-bottom: 25px;">
<a href="papayawhip-cod-251399.hostingersite.com" style="background-color: #c9a96e; color: #ffffff; text-decoration: none; padding: 14px 32px; font-size: 13px; font-weight: bold; border-radius: 4px; text-transform: uppercase; letter-spacing: 2px; display: inline-block;">Shop New Arrivals</a>
</div>
</td>
</tr>
<!-- Footer -->
<tr>
<td align="center" style="background-color: #f9f9f9; padding: 25px 20px; font-size: 12px; color: #999999; border-top: 1px solid #eeeeee;">
<p style="margin: 0; letter-spacing: 0.5px;">© ' . date('Y') . ' Elegance of India. All rights reserved.</p>
<p style="margin: 8px 0 0; line-height: 1.5;">If you have any questions, simply reply to this email to contact our support team.</p>
</td>
</tr>
</table>
</td>
</tr>
</table>
</body>
</html>
';
// Send Email using SMTP Mailer
require_once 'inc/mailer.php';
sendOrderEmail($email, $subject, $htmlMessage, true);
echo json_encode(['status' => 'success', 'message' => 'Thank you! Please check your inbox.']);
} else {
echo json_encode(['status' => 'info', 'message' => 'You are already subscribed.']);
}
} catch (Exception $e) {
echo json_encode(['status' => 'error', 'message' => 'An error occurred. Please try again later.']);
}
} else {
echo json_encode(['status' => 'error', 'message' => 'Invalid email address.']);
}
} else {
echo json_encode(['status' => 'error', 'message' => 'Invalid request.']);
}