-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsend.php
More file actions
67 lines (58 loc) · 2.13 KB
/
send.php
File metadata and controls
67 lines (58 loc) · 2.13 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<?php
// Файлы phpmailer
require 'templates/phpmailer/PHPMailer.php';
require 'templates/phpmailer/SMTP.php';
require 'templates/phpmailer/Exception.php';
// в зависимости от пришедшей формы формируем сообщение:
if(isset($_POST['email-subscribe'])) {
$email = $_POST['email-subscribe'];
$title = "Новая подписка на Ehya";
$body = "
<h2>Новая подписка</h2>
<b>Email:</b> $email
";
} else {
$name = $_POST['name-modal'];
$phone = $_POST['phone-modal'];
$email = $_POST['email-modal'];
$message = $_POST['message-modal'];
// Формирование самого письма
$title = "Новая подписка на Ehya";
$body = "
<h2>Новое обращение</h2>
<b>Имя:</b> $name<br>
<b>Телефон:</b> $phone<br>
<b>Email:</b> $email<br><br>
<b>Сообщение:</b><br>$message
";
}
// Настройки PHPMailer
$mail = new PHPMailer\PHPMailer\PHPMailer();
try {
$mail->isSMTP();
$mail->CharSet = "UTF-8";
$mail->SMTPAuth = true;
//$mail->SMTPDebug = 2;
$mail->Debugoutput = function($str, $level) {$GLOBALS['status'][] = $str;};
// Настройки вашей почты
$mail->Host = 'smtp.gmail.com'; // SMTP сервера вашей почты
$mail->Username = ''; // Логин на почте
$mail->Password = ''; // Пароль на почте
$mail->SMTPSecure = 'ssl';
$mail->Port = 465;
$mail->setFrom('', ''); // Адрес самой почты и имя отправителя
// Получатель письма
$mail->addAddress('');
// Отправка сообщения
$mail->isHTML(true);
$mail->Subject = $title;
$mail->Body = $body;
// Проверяем отравленность сообщения
if ($mail->send()) {$result = "success";}
else {$result = "error";}
} catch (Exception $e) {
$result = "error";
$status = "Сообщение не было отправлено. Причина ошибки: {$mail->ErrorInfo}";
}
// Отображение результата
header('location: thankyou.html');