-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsend-email.php
72 lines (63 loc) · 2.58 KB
/
send-email.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
<?php
require_once('./vendor/autoload.php');
use Postmark\Models\PostmarkException;
use Postmark\PostmarkClient;
session_start();
$name = $email = $description = '';
if (isset($_POST['submit'])) {
if (empty($_POST['name']) || strlen($_POST['name']) < 1) {
$_SESSION['nameError'] = 'Por favor introduzca su nombre.';
} else {
$name = htmlspecialchars(trim($_POST['name']));
}
if (empty($_POST['email']) || strlen($_POST['email']) < 1) {
$_SESSION['emailError'] = 'Por favor introduzca su email.';
} else {
$email = htmlspecialchars(trim($_POST['email']));
}
if (empty($_POST['description']) || strlen($_POST['description']) < 1) {
$_SESSION['descriptionError'] = 'Por favor introduzca una descripcion para su proyecto.';
} else {
$description = htmlspecialchars(trim($_POST['description']));
}
try {
$data = array(
'secret' => $_ENV['HCAPTCHA_SECRET_KEY'],
'response' => $_POST['h-captcha-response']
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://hcaptcha.com/siteverify");
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
$responseData = json_decode($response);
if (!($responseData->success)) {
$_SESSION['captchaError'] = 'No pudimos verificar que no eres un robot. Intenta otra vez.';
}
} catch (Exception $e) {
$_SESSION['captchaError'] = 'No pudimos verificar que no eres un robot. Intenta otra vez.';
}
$errors =
isset($_SESSION['nameError']) ||
isset($_SESSION['emailError']) ||
isset($_SESSION['descriptionError']) ||
isset($_SESSION['captchaError']) ||
isset($_SESSION['postmarkError']);
if ($errors == true) {
header("location:index.php#contact-us-section");
} else {
try {
$client = new PostmarkClient($_ENV['POSTMARK_KEY']);
$sendResult = $client->sendEmail(
"desarrollo@ozudev.com",
"desarrollo@ozudev.com",
"Nueva solicitud de proyecto por parte de ${name}",
"Nombre: ${name}\n Correo del solicitante: ${email}\n Descripcion: ${description}"
);
header("Location:contact-success.php");
} catch (PostmarkException $ex) {
$_SESSION['postmarkError'] = 'Ocurrio un error y no se pudo enviar el correo. Escribenos a desarrollo@ozudev.com';
}
}
}