This repository was archived by the owner on Mar 12, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathparseListener.php
More file actions
72 lines (53 loc) · 1.82 KB
/
parseListener.php
File metadata and controls
72 lines (53 loc) · 1.82 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
<?php
require_once "lib/swift_required.php";
$file = 'parselog.txt';
$contents = print_r($_POST, true);
file_put_contents($file, $contents, FILE_APPEND);
$num_dice = (int)$_REQUEST["text"];
$img = array();
$img[] = '<img src="dice1.png" />';
$img[] = '<img src="dice2.png" />';
$img[] = '<img src="dice3.png" />';
$img[] = '<img src="dice4.png" />';
$img[] = '<img src="dice5.png" />';
$img[] = '<img src="dice6.png" />';
$text = "Rolled " . $num_dice . " dice.";
$html = "<h1>" . $text . "</h1>";
for($i=0; $i<$num_dice; $i++){
//Generate a random number between 1 & 6
$count = rand(0,5);
//Assign $dice with the image chosen in the array
$image = $img[$count];
$text = $text . "\n" . ($count+1);
$html = $html . "<br/>" . $image . " " . ($count+1);
}
// Login credentials
// Set these to match your SendGrid.com account
$username = 'sendgrid_username';
$password = 'sendgrid_password';
// Setup Swift mailer parameters
$transport = Swift_SmtpTransport::newInstance('smtp.sendgrid.net', 587);
$transport->setUsername($username);
$transport->setPassword($password);
$swift = Swift_Mailer::newInstance($transport);
// Create a message (subject)
$message = new Swift_Message($subject);
$sender = $_REQUEST["from"];
$sender = substr($sender, strpos($sender, '<')+1, -1);
// This is your From email address
$from = array('demo@sendgrid.com' => 'SendGrid Demo');
// attach the body of the email
$message->setFrom($from);
$message->setBody($html, 'text/html');
$message->setTo($sender);
$message->setSubject("Your dice have been rolled!");
$message->addPart($text, 'text/plain');
// send message
if ($recipients = $swift->send($message, $failures)) {
$contents = 'Message sent out to ' . $recipients . ' users';
}
else {
$contents = "Something went wrong - " . $failures;
}
file_put_contents($file, $contents, FILE_APPEND);
?>