-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
78 lines (67 loc) · 2.09 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
<?php
require 'vendor/autoload.php';
date_default_timezone_set('America/Los_Angeles');
$app = new \Slim\Slim(array(
'view' => new \Slim\Views\Twig(),
)
);
$app->add(new \Slim\Middleware\SessionCookie());
$view = $app->view();
$view->parserOptions = array(
'debug' => TRUE,
);
// https://github.com/slimphp/Slim-Views
$view->parserExtensions = array(
new \Slim\Views\TwigExtension(),
);
$app->get('/', function () use ($app) {
$app->render('about.twig'); // <-- SUCCESS
}
)->name('home');
$app->get('/contact', function () use ($app) {
$app->render('contact.twig'); // <-- SUCCESS
}
)->name('contact');
$app->post('/contact', function () use ($app) {
$sender = $app->request->post('sender');
$email = $app->request->post('email');
$message = $app->request->post('message');
// why does this condition never fail?
if (!empty('sender') && !empty('email') && !empty('message')) {
$cleanSender = filter_var($sender, FILTER_SANITIZE_STRING);
$cleanEmail = filter_var($email, FILTER_SANITIZE_EMAIL);
$cleanMessage = filter_var($message, FILTER_SANITIZE_STRING);
}
else {
// http://docs.slimframework.com/flash/overview/
$app->flash('error', 'All fields are required');
$app->redirect('/contact');
}
$transport = Swift_SendmailTransport::newInstance('/usr/sbin/sendmail -bs');
$mailer = \Swift_Mailer::newInstance($transport);
$theMessage = \Swift_Message::newInstance();
$theMessage->setSubject('Email from our website');
$theMessage->setFrom(
array(
$cleanEmail => $cleanSender,
)
);
$theMessage->setTo('[email protected]');
$theMessage->setBody($cleanMessage);
$result = $mailer->send($theMessage);
if ($result > 0) {
// feedback to user re: thank you
$app->flash(
'contact',
'Thank you for attempting to contact Waldo. He may be awhile responding seeing as he is dead.'
);
$app->redirect('/composer');
}
else {
// feedback to use re: failure
// log error
$app->redirect('/contact');
}
}
)->name('contact');
$app->run();