-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
executable file
·70 lines (58 loc) · 1.96 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
<?php
require 'vendor/autoload.php';
date_default_timezone_set("America/Mexico_City");
//use Monolog\Logger;
//use Monolo\Handler\StreamHandler;
//$log = new Logger('name');
//$log->pushHandler(new StreamHandler('app.txt', Logger::WARNING));
//$log->addWarning('Oh Noes.');
$app = new \Slim\Slim( array(
'view' => new \Slim\Views\Twig()
));
$app->add(new \Slim\Middleware\SessionCookie());
$view = $app->view();
$view->parserOptions = array(
'debug' => true
);
$view->parserExtensions = array(
new \Slim\Views\TwigExtension(),
);
$app->get('/', function() use($app){
$app->render('about.twig');
})->name('home');
$app->get('/contact', function() use($app) {
$app->render('contact.twig');
})->name('contact');
$app->post('/contact', function() use($app) {
$name = $app->request->post('name');
$email = $app->request->post('email');
$msg = $app->request->post('msg');
if (!empty($name) && !empty($email) && !empty($msg)) {
$cleanName = filter_var($name, FILTER_SANITIZE_STRING);
$cleanEmail = filter_var($email, FILTER_SANITIZE_EMAIL);
$cleanMsg = filter_var($msg, FILTER_SANITIZE_STRING);
} else {
$app->flash('fail', 'All Fields Are Required.');
$app->redirect('/contact');
}
$transport = Swift_SendmailTransport::newInstance('/usr/sbin/sendmail -bs');
$mailer = \Swift_Mailer::newInstance($transport);
$message = \Swift_Message::newInstance();
$message->setSubject('Email From Our Website');
$message->setFrom(array(
$cleanEmail => $cleanName
));
$message->setTo(array('[email protected]'));
$message->setBody($cleanMsg);
$result = $mailer->send($message);
if($result > 0 ) {
// send a message that says thank you.
$app->flash('success', 'Thanks So Much! You are AWESOME!!!');
$app->redirect('/');
} else {
$app->flash('fail', 'Something went wrong, please try again later.');
// log that there was an error
$app->redirect('/contact');
}
});
$app->run();