-
Notifications
You must be signed in to change notification settings - Fork 0
/
10dayleft.php
44 lines (35 loc) · 1.42 KB
/
10dayleft.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
<?php
require 'mailer.php';
require '../api/db.php';
function microtime2(){
list($usec, $sec) = explode(" ", microtime());
return ((int)$usec + (int)$sec);
}
$time = microtime2()*1000;
$day = 1000*60*60*24;
$sql = "SELECT bookreader FROM bookhistory WHERE (20-(CEILING(({$time} - time) / 86400000)))=10 AND active=1";
$stmt = $pdo->prepare($sql);
$stmt->execute();
$readerSql = $stmt->fetchAll(PDO::FETCH_ASSOC);
$stmt = null;
$pdo = null;
$mail = new PHPMailer();
try {
$mail->isSMTP();
$mail->SMTPAuth = true;
$mail->Host = 'mail.schoollibrarybook.com';
$mail->Port = 587;
$mail->SMTPSecure = 'tls';
$mail->Username = '[email protected]';
$mail->Password = 'd^hx-e,w9B@6';
$mail->SetFrom('[email protected]', 'Library Alert');
for($i = 0; $i<count($readerSql);$i++) $mail->addAddress($readerSql[$i]["bookreader"]);
$mail->Subject = 'Library Alert - 10 Days';
$mail->MsgHTML('you have 10 days to <b>return the book!</b>');
$mail->AltBody = 'you have 10 days to return the book!';
$mail->send();
echo 'Message has been sent';
} catch (Exception $e) {
echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}";
}
?>