-
Notifications
You must be signed in to change notification settings - Fork 0
/
mail.php
71 lines (59 loc) · 1.59 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<?
require_once 'PHPMailer/PHPMailerAutoload.php';
$admin_email = array();
foreach ( $_POST["admin_email"] as $key => $value ) {
array_push($admin_email, $value);
}
$form_subject = trim($_POST["form_subject"]);
$mail = new PHPMailer;
$mail->CharSet = 'UTF-8';
// Настройки SMTP
// $mail->isSMTP();
// $mail->SMTPAuth = true;
// $mail->SMTPDebug = 0;
// $mail->Host = 'ssl://smtp.gmail.com';
// $mail->Port = 465;
// $mail->Username = 'Логин';
// $mail->Password = 'Пароль';
$c = true;
$message = '';
foreach ( $_POST as $key => $value ) {
if ( $value != "" && $key != "admin_email" && $key != "form_subject" ) {
if (is_array($value)) {
$val_text = '';
foreach ($value as $val) {
if ($val && $val != '') {
$val_text .= ($val_text==''?'':', ').$val;
}
}
$value = $val_text;
}
$message .= "
" . ( ($c = !$c) ? '<tr>':'<tr>' ) . "
<td style='padding: 10px; width: auto;'><b>$key:</b></td>
<td style='padding: 10px;width: 100%;'>$value</td>
</tr>
";
}
}
$message = "<table style='width: 50%;'>$message</table>";
// От кого
$mail->setFrom('adm@' . $_SERVER['HTTP_HOST'], 'Your best site');
// Кому
foreach ( $admin_email as $key => $value ) {
$mail->addAddress($value);
}
// Тема письма
$mail->Subject = $form_subject;
// Тело письма
$body = $message;
// $mail->isHTML(true); это если прям верстка
$mail->msgHTML($body);
// Приложения
if ($_FILES){
foreach ( $_FILES['file']['tmp_name'] as $key => $value ) {
$mail->addAttachment($value, $_FILES['file']['name'][$key]);
}
}
$mail->send();
?>