-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathQAC_Send_Notification.php
60 lines (54 loc) · 2.46 KB
/
QAC_Send_Notification.php
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
<?php
include("connection.php");
session_start(); // Start the session
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
require 'PHPMailer/src/PHPMailer.php';
require 'PHPMailer/src/SMTP.php';
require 'PHPMailer/src/Exception.php';
if (isset($_GET['topic'])) {
$topic = $_GET['topic'];
//get topic name
$sql = "SELECT TopicName FROM Topic WHERE TopicID = '$topic'";
$result = mysqli_query($conn, $sql);
$row = mysqli_fetch_assoc($result);
$topicname = $row['TopicName'];
$department_id = $_SESSION['department_id'];
// Get all staff email addresses of my department
$sql = "SELECT Email FROM Staff WHERE DepartmentID = '$department_id'";
$result = mysqli_query($conn, $sql);
if (mysqli_num_rows($result) > 0) {
$mail = new PHPMailer(true);
try {
// Server settings
$mail->SMTPDebug = 0;
$mail->isSMTP();
$mail->Host = 'smtp.gmail.com';
$mail->SMTPAuth = true;
$mail->Username = '[email protected]';
$mail->Password = 'rwdibyoqadzmaxbw';
$mail->SMTPSecure = 'tls';
$mail->Port = 587;
$mail->setFrom('[email protected]', 'Greenwich QA');
// Loop through all staff email addresses and add them as recipients
while ($row = mysqli_fetch_assoc($result)) {
$mail->addAddress($row['Email']);
}
// Content
$mail->isHTML(true);
$mail->Subject = 'New idea has been submitted';
$mail->Body = "Dear staff,<br><br>There is a new idea has been submitted for $topicname at https://greenwichideas.cleverapps.io/. Please add more ideas to this topic to improve the quality of the topic.<br><br>Thank you.<br><br>Greenwich QA<br><br>";
$mail->send();
echo "<script>alert('Email sent successfully.')</script>";
// Reload current page after sending email
echo "<script>window.location.href = 'QAC_Topic_Detail.php?topic=$topic'</script>";
} catch (Exception $e) {
echo "<script>alert('Message could not be sent. Mailer Error: {$mail->ErrorInfo}')</script>";
echo "<script>window.location.href = 'QAC_Topic_Detail.php?topic=$topic'</script>";
}
} else {
echo "<script>alert('No staff found in your department.')</script>";
echo "<script>window.location.href = 'QAC_Topic_Detail.php?topic=$topic'</script>";
}
}
?>