-
Notifications
You must be signed in to change notification settings - Fork 0
/
mail.php
54 lines (43 loc) · 1.76 KB
/
mail.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
<?php
// Файлы phpmailer
require 'phpmailer/PHPMailer.php';
require 'phpmailer/SMTP.php';
require 'phpmailer/Exception.php';
$title = "Тема письма";
$c = true;
// Формирование самого письма
$title = "Заголовок письма";
foreach ($_POST as $key => $value) {
if ($value != "" && $key != "project_name" && $key != "admin_email" && $key != "form_subject") {
$body .= "
" . (($c = !$c) ? '<tr>' : '<tr style="background-color: #f8f8f8;">') . "
<td style='padding: 10px; border: #e9e9e9 1px solid;'><b>$key</b></td>
<td style='padding: 10px; border: #e9e9e9 1px solid;'>$value</td>
</tr>
";
}
}
$body = "<table style='width: 100%;'>$body</table>";
// Настройки PHPMailer
$mail = new PHPMailer\PHPMailer\PHPMailer();
try {
$mail->isSMTP();
$mail->CharSet = "UTF-8";
$mail->SMTPAuth = true;
// Настройки вашей почты
$mail->Host = 'smtp.gmail.com'; // SMTP сервера вашей почты
$mail->Username = 'randomemail@gmail.com'; // Логин на почте
$mail->Password = ''; // Пароль на почте, через создание пароля
$mail->SMTPSecure = 'ssl';
$mail->Port = 465;
$mail->setFrom('randomemail@gmail.com', 'Заявка с вашего сайта'); // Адрес самой почты и имя отправителя
// Получатель письма
$mail->addAddress('randomemail@gmail.com'); // Адрес почты получателя
// Отправка сообщения
$mail->isHTML(true);
$mail->Subject = $title;
$mail->Body = $body;
$mail->send();
} catch (Exception $e) {
$status = "Сообщение не было отправлено. Причина ошибки: { $mail->ErrorInfo }";
}