-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsend_message.php
More file actions
40 lines (31 loc) · 992 Bytes
/
send_message.php
File metadata and controls
40 lines (31 loc) · 992 Bytes
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
<?php
session_start();
include 'db_connect.php';
if (!isset($_POST['sender'], $_POST['subject'], $_POST['body'])) {
exit("Λείπουν δεδομένα: sender, subject, body.");
}
$sender = trim($_POST['sender']);
$subject = trim($_POST['subject']);
$body = trim($_POST['body']);
$stmt = $conn->prepare("SELECT loginame FROM users WHERE role = 'Tutor'");
$stmt->execute();
$result = $stmt->get_result();
if ($result->num_rows === 0) {
exit("Δεν βρέθηκαν χρήστες με ρόλο Tutor.");
}
$headers = "From: $sender\r\n";
$headers .= "Reply-To: $sender\r\n";
$successCount = 0;
while ($row = $result->fetch_assoc()) {
$tutorEmail = $row["loginame"];
if (@mail($tutorEmail, $subject, $body, $headers)) {
$successCount++;
}
}
$stmt->close();
$conn->close();
if ($successCount > 0) {
echo "Το μήνυμα εστάλη επιτυχώς σε $successCount Tutor(s).";
} else {
echo "Αποτυχία αποστολής.";
}