-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadmin_email_test.php
More file actions
131 lines (113 loc) · 3.99 KB
/
Copy pathadmin_email_test.php
File metadata and controls
131 lines (113 loc) · 3.99 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
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
<?php
require_once __DIR__ . '/init.php';
require_once __DIR__ . '/auth.php';
require_once __DIR__ . '/includes/functions.php';
// Admin gate
if (!is_admin()) {
http_response_code(403);
echo 'Forbidden';
exit;
}
// Load email config for display
if (file_exists(__DIR__ . '/config/email_config.php')) {
require_once __DIR__ . '/config/email_config.php';
}
$resultMsg = null;
$sent = null;
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$to = trim($_POST['to'] ?? '');
$provider = trim($_POST['provider'] ?? '');
$subject = 'TechForum test email';
$body = '<p>This is a test email from TechForum admin test page.</p>';
if ($provider) {
// Temporarily override provider just for this request
$GLOBALS['EMAIL_PROVIDER_OVERRIDE'] = $provider;
}
if (!$to) {
$resultMsg = 'Please provide a destination email address.';
$sent = false;
} else {
//$sent = send_email($to, $subject, $body);
$resultMsg = $sent ? 'Email sent successfully.' : 'Failed to send email. Check configuration and error logs.';
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Admin Email Test</title>
<link rel="stylesheet" href="assets/css/style.css">
<style>
.container {
max-width: 800px;
margin: 2rem auto;
padding: 1rem;
background: #fff;
border: 1px solid #ddd;
border-radius: 6px
}
.row {
display: flex;
gap: 1rem;
align-items: center
}
label {
min-width: 120px
}
input,
select {
padding: .5rem;
width: 100%
}
.btn {
padding: .5rem 1rem
}
.ok {
color: green
}
.err {
color: #c00
}
code {
background: #f6f8fa;
padding: 2px 4px;
border-radius: 4px
}
</style>
</head>
<body>
<div class="container">
<h2>Email Configuration Test</h2>
<form method="post" class="form">
<div class="row">
<label for="to">To</label>
<input type="email" name="to" id="to" placeholder="you@example.com" required>
</div>
<div class="row">
<label for="provider">Provider</label>
<select name="provider" id="provider">
<option value="">Auto</option>
<option value="sendgrid">SendGrid</option>
<option value="mailgun">Mailgun</option>
<option value="mail">PHP mail()</option>
</select>
</div>
<button class="btn" type="submit">Send Test Email</button>
</form>
<?php if ($resultMsg !== null): ?>
<p class="<?= $sent ? 'ok' : 'err' ?>"><?= htmlspecialchars($resultMsg) ?></p>
<?php endif; ?>
<h3>Current Settings</h3>
<ul>
<li>EMAIL_PROVIDER: <code><?= defined('EMAIL_PROVIDER') ? htmlspecialchars(constant('EMAIL_PROVIDER')) : '' ?></code></li>
<li>EMAIL_FROM: <code><?= defined('EMAIL_FROM') ? htmlspecialchars(constant('EMAIL_FROM')) : '' ?></code></li>
<li>EMAIL_FROM_NAME: <code><?= defined('EMAIL_FROM_NAME') ? htmlspecialchars(constant('EMAIL_FROM_NAME')) : '' ?></code></li>
<li>SENDGRID_API_KEY set: <code><?= (defined('SENDGRID_API_KEY') && constant('SENDGRID_API_KEY')) ? 'yes' : 'no' ?></code></li>
<li>MAILGUN_API_KEY set: <code><?= (defined('MAILGUN_API_KEY') && constant('MAILGUN_API_KEY')) ? 'yes' : 'no' ?></code></li>
<li>MAILGUN_DOMAIN: <code><?= defined('MAILGUN_DOMAIN') ? htmlspecialchars(constant('MAILGUN_DOMAIN')) : '' ?></code></li>
</ul>
<p>Tip: Edit <code>config/email_config.php</code> to add API keys. You can set <code>EMAIL_DEBUG</code> to <code>true</code> to log failures to error_log.</p>
</div>
</body>
</html>