-
Notifications
You must be signed in to change notification settings - Fork 0
/
contact.php
76 lines (70 loc) · 2.54 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
74
75
76
<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
require_once($_SERVER['DOCUMENT_ROOT'] . '/PHPMailer/src/PHPMailer.php');
require_once $_SERVER['DOCUMENT_ROOT'] . '/PHPMailer/src/Exception.php';
require_once($_SERVER['DOCUMENT_ROOT'] . '/PHPMailer/src/SMTP.php');
$sEmail = "";
$sName = "";
$sNumber = "";
$sMessage = "";
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$aMessageReturn = [];
$bErrorName = false;
if ($_POST['email'] == "") {
$aMessageReturn[] = "Podaj swój email lub numer telefonu";
$bErrorName = true;
}
if ($_POST['name'] == "") {
$bErrorName = true;
$aMessageReturn[] = "Podaj swoje imie";
}
if ($_POST['message'] == "" || strlen($_POST['message']) < 10) {
$bErrorName = true;
$aMessageReturn[] = "Wpisz przynajmniej 10 znaków w swojej wiadomości";
}
if ($_POST['email'] !== "") {
if (!filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)) {
$bErrorName = true;
$aMessageReturn[] = "Podaj prawidłowy adres email";
}
}
if (!$bErrorName) {
$mail = new PHPMailer;
$mail->isSMTP();
$mail->CharSet = 'UTF-8';
$mail->SMTPDebug = 0;
$mail->Host = 'mail.terraweb.pl';
$mail->SMTPOptions = array(
'ssl' => array(
'verify_peer' => false,
'verify_peer_name' => false,
'allow_self_signed' => true
)
);
//$mail->Port = 587;
$mail->SMTPSecure = 'tls';
$mail->SMTPAuth = true;
$mail->Username = '[email protected]';
$mail->Password = '<aA19?X!>';
$mail->setFrom('[email protected]', 'Kontakt Terraweb');
$mail->AddCC($_POST['email']);
$mail->AddBCC('[email protected]');
$mail->AddBCC('[email protected]');
$mail->addAddress('[email protected]');
$mail->Subject = "Wiadomość z formularza Terraweb.pl";
$mail->Body = "'" . $_POST['message'] . "' - Wiadomość od: '" . $_POST['email'] ."' - " . $_POST['phone'] ?? "";
if (!$mail->send()) {
$bErrorName = true;
$aMessageReturn[] = "Wystąpił błąd serwera, prosimy o ponowną próbę";
} else {
$bErrorName = false;
header("Location: http://".$_SERVER['HTTP_HOST']."/?send=true#kontakt");
}
} else {
$sEmail = $_POST['email'] ?? "";
$sName = $_POST['name'] ?? "";
$sNumber = $_POST['phone'] ?? "";
$sMessage = $_POST['message'] ?? "";
}
}