-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontact.php
77 lines (50 loc) · 1.74 KB
/
contact.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
<?php
/**
* configure here
*/
$from = 'IT WORKER <[email protected]>';
$sendTo = 'IT WORKER <[email protected]>';
$subject = 'New message from contact form';
$fields = array('name' => 'Name', 'surname' => 'Surname', 'phone' => 'Phone', 'email' => 'Email', 'message' => 'Message');
$htmlHeader = '';
$htmlFooter = '';
$okMessage = 'Contact form succesfully submitted. Thank you, I will get back to you soon!';
$htmlContent = '<h1>New message from contact form</h1>';
/* DO NOT EDIT BELOW */
/* use classes */
use Nette\Mail\Message,
Nette\Mail\SendmailMailer;
/* require framework */
require 'php/Nette/nette.phar';
/* configure neccessary */
$configurator = new Nette\Configurator;
$configurator->setTempDirectory(__DIR__ . '/php/temp');
$container = $configurator->createContainer();
/* get post */
$httpRequest = $container->getService('httpRequest');
$httpResponse = $container->getService('httpResponse');
$post = $httpRequest->getPost();
if ($httpRequest->isAjax()) {
/* compose htmlContent */
$htmlContent .= '<table>';
foreach ($post as $key => $value) {
if (isset($fields[$key])) {
$htmlContent .= "<tr><th>$fields[$key]</th><td>$value</td></tr>";
}
}
$htmlContent .= '</table>';
/* compose html body */
$htmlBody = $htmlHeader . $htmlContent . $htmlFooter;
/* send email */
$mail = new Message;
$mail->setFrom($from)
->addTo($sendTo)
->setSubject($subject)
->setHtmlBody($htmlBody, FALSE);
$mailer = new SendmailMailer;
$mailer->send($mail);
$responseArray = array('type' => 'success', 'message' => $okMessage);
$httpResponse->setCode(200);
$response = new \Nette\Application\Responses\JsonResponse($responseArray);
$response->send($httpRequest, $httpResponse);
}