-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsendmail.php
More file actions
50 lines (41 loc) · 1.31 KB
/
Copy pathsendmail.php
File metadata and controls
50 lines (41 loc) · 1.31 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
47
48
49
50
<?php
require 'PHPMailer/src/Exception.php';
require 'PHPMailer/src/PHPMailer.php';
require 'PHPMailer/src/SMTP.php';
use PHPMailer\PHPMailer\PHPMailer;
$mail = new PHPMailer(true);
$mail->isSMTP();
$mail->SMTPAuth = true;
$mail->SMTPSecure = "tls";
$mail->Host = "smtp.gmail.com";
$mail->Port = "587";
$mail->Username = "";
$mail->Password = "";
$mail->IsHTML(true);
$mail->CharSet = 'UTF-8';
$mail->setLanguage('ru', 'PHPMailer/language/');
$mail->setFrom('', 'Alexander');
$mail->addAddress('');
$mail->Subject = 'Обратная связь';
$body = '<h1>Вот ваше письмо!</h1>';
if (trim(!empty($_POST['name']))) {
$body .= '<p><strong>Имя: </strong>' . $_POST['name'] . '</p>';
}
if (trim(!empty($_POST['formTheme']))) {
$body .= '<p><strong>Тема обращения: </strong>' . $_POST['formTheme'] . '</p>';
}
if (trim(!empty($_POST['email']))) {
$body .= '<p><strong>E-mail: </strong>' . $_POST['email'] . '</p>';
}
if (trim(!empty($_POST['message']))) {
$body .= '<p><strong>Сообщение: </strong>' . $_POST['message'] . '</p>';
}
$mail->Body = $body;
if (!$mail->send()) {
$message = 'Ошибка';
} else {
$message = 'Данные отправлены!';
}
$response = ['message' => $message];
header('Content-type: application/json');
echo json_encode($response);