/
index.php
61 lines (41 loc) · 1.46 KB
/
index.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
61
<?php
namespace Microsite;
include 'microsite.phar';
include 'postmark.php';
$app = new App();
Config::load(__DIR__ . '/config.php');
$app->template_dirs = [
__DIR__ . '/views',
];
$app->route('all', '/', function() { echo 'Greetings from IF.'; });
$app->route('invite_get', '/invite', function(Response $response) {
return $response->render('invite.php');
})->get();
$app->share('postmark', function(){
return new \PostMark(Config::get('postmark_key'), Config::get('from_address'));
});
$app->route('invite_post', '/invite', function(Response $response, App $app) {
$email = $_POST['email'];
$response['shipname'] = 'Nostromo';
$plain = $response->render('plain_invite.php');
$html = $response->render('html_invite.php');
$result = $app->postmark()->to($email)
->subject('Congratulations, Captain!')
->plain_message($plain)
->html_message($html)
->send();
echo '<p>The invitation was sent ' . ($result ? 'successfully' : 'unsuccessfully') . '.</p>';
})->post();
$app->route('inbound_email', '/inbound/mail', function(App $app) {
$data = json_decode(file_get_contents('php://input'));
$output = print_r($data, 1) . "\r\n----------\r\n";
file_put_contents(__DIR__ . '/inbound.log', $output, FILE_APPEND);
$from = $data->From;
$result = $app->postmark()->to($from)
->subject('Sample Mailback')
->plain_message('The response system is not yet complete, but notice that your message was received.')
->send();
echo 'inbound - ok';
});
$app->run();
?>