-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpost.php
73 lines (61 loc) · 1.68 KB
/
post.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
require_once 'vendor/autoload.php';
$msg_box = array(); // form messages
$errors = array(); // error container
//bot checker
function is_not_bot() {
if ($_POST['key'] == '') {
return false;
}
else {
$loadPage = $_POST['key'];
$submit = time();
if (($loadPage > $submit) && ($submit - $loadPage < 3) && ($submit - $loadPage > 86400)) {
return false;
}
else {
return true;
}
}
}
// check the fields
if($_POST['email'] == '') {
$errors['email'] = 'Email field is required';
}
else if (!filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)) {
$errors['email'] = "The email address is incorrect";
}
if(empty($errors) && is_not_bot()) {
// collect data from the form
$message = 'Email: ' . $_POST['email'];
send_mail($message); // send a mail
// success error
$msg_box = array('success' => 'Thank you. Your info has been successfully sent');
}
else {
// post errors
$msg_box = $errors;
}
// response JSON
echo json_encode(array(
'result' => $msg_box
));
// email sending function
function send_mail($message) {
// Create the Transport
$transport = (new Swift_SmtpTransport('smtp.postmarkapp.com', 587, 'tls'))
->setUsername('2ee3871f-9e1a-442d-a1e5-2a824250104e')
->setPassword('2ee3871f-9e1a-442d-a1e5-2a824250104e')
;
// Create the Mailer using your created Transport
$mailer = new Swift_Mailer($transport);
// Create a message
$settings = (new Swift_Message('ReconnectingLabs'))
->setFrom(['[email protected]' => 'ReconnectingLabs ORG'])
->setTo(['[email protected]'])
->setBody($message)
->setContentType("text/html")
;
// Send the message
$result = $mailer->send($settings);
}