35227-vm/manual_email.php
Flatlogic Bot c993331930 v1
2025-10-25 15:42:13 +00:00

112 lines
5.1 KiB
PHP

<?php
require_once 'db/config.php';
$page_title = 'Manual Email Entry';
$page_description = 'A page to manually enter email content.';
$from = '';
$subject = '';
$message = '';
$success_message = '';
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$from = isset($_POST['from']) ? $_POST['from'] : '';
$subject = isset($_POST['subject']) ? $_POST['subject'] : '';
$message = isset($_POST['message']) ? $_POST['message'] : '';
if ($from && $subject && $message) {
try {
$pdo = db();
$stmt = $pdo->prepare('INSERT INTO manual_emails (sender, subject, message) VALUES (?, ?, ?)');
$stmt->execute([$from, $subject, $message]);
$success_message = 'تم حفظ البريد الإلكتروني بنجاح!';
} catch (PDOException $e) {
// For development, it's useful to see the error. In production, you'd log this.
$success_message = 'خطأ في حفظ البريد: ' . $e->getMessage();
}
}
}
// Fetch all saved emails
$saved_emails = [];
try {
$pdo = db();
$stmt = $pdo->query('SELECT sender, subject, message, created_at FROM manual_emails ORDER BY created_at DESC');
$saved_emails = $stmt->fetchAll();
} catch (PDOException $e) {
// Handle error, e.g., by showing a message
$db_error = 'خطأ في استرجاع رسائل البريد الإلكتروني: ' . $e->getMessage();
}
?>
<!DOCTYPE html>
<html lang="ar" dir="rtl">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title><?php echo htmlspecialchars($page_title); ?></title>
<meta name="description" content="<?php echo htmlspecialchars($page_description); ?>">
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">
<style>
body { background-color: #f8f9fa; }
.container { max-width: 800px; }
.card { margin-top: 2rem; }
.card-header { background-color: #0d6efd; color: white; }
.result-box { margin-top: 2rem; padding: 1.5rem; border: 1px solid #dee2e6; border-radius: .25rem; background-color: #fff; }
.email-item { border-bottom: 1px solid #eee; padding-bottom: 1rem; margin-bottom: 1rem; }
.email-item:last-child { border-bottom: none; }
</style>
</head>
<body>
<div class="container">
<header class="d-flex justify-content-between align-items-center py-3 mb-4 border-bottom">
<h1 class="h4">إدخال البريد الإلكتروني يدوياً</h1>
<a href="index.php" class="btn btn-sm btn-outline-secondary">العودة للرئيسية</a>
</header>
<?php if ($success_message): ?>
<div class="alert alert-success"><?php echo $success_message; ?></div>
<?php endif; ?>
<div class="card">
<div class="card-header">نموذج إدخال البريد</div>
<div class="card-body">
<form action="manual_email.php" method="POST">
<div class="mb-3">
<label for="from" class="form-label">من:</label>
<input type="email" class="form-control" id="from" name="from" required>
</div>
<div class="mb-3">
<label for="subject" class="form-label">الموضوع:</label>
<input type="text" class="form-control" id="subject" name="subject" required>
</div>
<div class="mb-3">
<label for="message" class="form-label">نص الرسالة:</label>
<textarea class.form-control" id="message" name="message" rows="8" required></textarea>
</div>
<button type="submit" class="btn btn-primary">حفظ البريد</button>
</form>
</div>
</div>
<div class="result-box">
<h2 class="h5 mb-4">الرسائل المحفوظة</h2>
<?php if (isset($db_error)): ?>
<div class="alert alert-danger"><?php echo $db_error; ?></div>
<?php elseif (empty($saved_emails)): ?>
<p>لا توجد رسائل محفوظة حتى الآن.</p>
<?php else: ?>
<?php foreach ($saved_emails as $email): ?>
<div class="email-item">
<p><strong>من:</strong> <?php echo htmlspecialchars($email['sender']); ?></p>
<p><strong>الموضوع:</strong> <?php echo htmlspecialchars($email['subject']); ?></p>
<p><strong>الرسالة:</strong></p>
<pre style="white-space: pre-wrap; background-color: #f1f1f1; padding: 1rem; border-radius: .25rem;"><?php echo htmlspecialchars($email['message']); ?></pre>
<small class="text-muted">تم الاستلام في: <?php echo $email['created_at']; ?></small>
</div>
<?php endforeach; ?>
<?php endif; ?>
</div>
</div>
</body>
</html>