-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontact.php
More file actions
46 lines (38 loc) · 1.91 KB
/
contact.php
File metadata and controls
46 lines (38 loc) · 1.91 KB
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
<?php
// contact.php – formularz kontaktowy devroman.pl
header('Content-Type: application/json; charset=UTF-8');
if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
http_response_code(405);
echo json_encode(['ok' => false, 'error' => 'Method Not Allowed']);
exit;
}
$name = isset($_POST['name']) ? trim($_POST['name']) : '';
$email = isset($_POST['email']) ? trim($_POST['email']) : '';
$message = isset($_POST['message']) ? trim($_POST['message']) : '';
$service = isset($_POST['service']) ? trim($_POST['service']) : '';
$budget = isset($_POST['budget']) ? trim($_POST['budget']) : '';
$source = isset($_POST['source']) ? trim($_POST['source']) : 'devroman.pl';
$errors = [];
if ($name === '') $errors[] = 'Proszę podać imię.';
if ($email === '' || !filter_var($email, FILTER_VALIDATE_EMAIL)) $errors[] = 'Nieprawidłowy adres e-mail.';
if ($message === '') $errors[] = 'Proszę wpisać wiadomość.';
if (!empty($errors)) {
http_response_code(422);
echo json_encode(['ok' => false, 'error' => implode(' ', $errors)]);
exit;
}
$to = 'info@matviy.pp.ua';
$subject = 'Nowe zapytanie z devroman.pl';
$body = "Imię: {$name}\nE-mail: {$email}\nUsługa: {$service}\nBudżet: {$budget}\nStrona: {$source}\n\nWiadomość:\n{$message}\n";
$headers = [];
$headers[] = 'MIME-Version: 1.0';
$headers[] = 'Content-Type: text/plain; charset=UTF-8';
$headers[] = 'From: devroman.pl <no-reply@devroman.pl>';
$headers[] = 'Reply-To: ' . $email;
$sent = @mail($to, '=?UTF-8?B?' . base64_encode($subject) . '?=', $body, implode("\r\n", $headers));
if ($sent) {
echo json_encode(['ok' => true, 'message' => 'Wiadomość wysłana! Odpiszę w ciągu 24 godzin.']);
} else {
http_response_code(500);
echo json_encode(['ok' => false, 'error' => 'Błąd wysyłki. Proszę napisać bezpośrednio na info@matviy.pp.ua']);
}