-
Notifications
You must be signed in to change notification settings - Fork 0
/
comic_mailer.php
46 lines (43 loc) · 1.56 KB
/
comic_mailer.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
<?php
require_once './utils/functions.php';
require_once './includes/db.php';
$secret = '';
if ( ! isset( $_POST['secret'] )) {
die( 'Token Not FOund' );
} else {
$secret = $_POST['secret'];
}
if (strlen( $secret ) !== getenv( 'HTTP_SECRET_LEN' ) && $secret !== getenv( 'HTTP_CRON_SECRET' )) {
die( 'Invalid TOken' );
}
$SERVER_NAME = isset( $_SERVER['SERVER_NAME'] ) ? $_SERVER['SERVER_NAME'] : '';
$stmt = $con->prepare( 'SELECT email FROM `subscribers` WHERE is_activated = 1' );
$stmt->execute();
$mailtoarr = array();
$stmt->store_result();
$stmt->bind_result( $mail );
if ($stmt->num_rows > 0) {
$comic = getComicFromXKCD();
$title = 'Your New Comic' . $comic['safe_title'];
$file = file_get_contents( $comic['img'] );
$encoded_file = chunk_split( base64_encode( $file ) ); //Embed image in base64 to send with email
$attachments[] = array(
'name' => $comic['title'] . '.jpg',
'data' => $encoded_file,
'type' => 'application/pdf',
'encoding' => 'base64',
);
while ($stmt->fetch()) {
$Body = '
<p >Hello Subscriber</p>
Here is your Comic for the day
<h3>' . $comic['safe_title'] . "</h3>
<img src='" . $comic['img'] . "' alt='some comic hehe'/>
<br />
To read the comic head to <a target='_blank' href='https://xkcd.com/" . $comic['num'] . "'>Here</a><br />
To unsubscribe kindly visit <a href='http://" . $SERVER_NAME . '/unsubscribe.php?email=' . $mail . '&id=' . md5( $mail ) . "'>here.</a>
";
sendComic( $mail, $title, $Body, $attachments );
}
echo 'Sent Successfully';
}