-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmail.php
42 lines (36 loc) · 1.31 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
<?php
$method = $_SERVER['REQUEST_METHOD'];
$c = true;
$project_name = trim($_POST["project_name"]);
$email_sender = trim($_POST["email_sender"]);
$admin_email = trim($_POST["admin_email"]);
$form_subject = trim($_POST["form_subject"]);
foreach ( $_POST as $key => $value ) {
if ( is_array($value) ) {
$value = implode(", ", $value);
}
if ( $value != "" && $key != "project_name" && $key != "email_sender" && $key != "admin_email" && $key != "form_subject" ) {
$message .= "
" . ( ($c = !$c) ? '<tr>':'<tr style="background-color: #f8f8f8;">' ) . "
<td style='padding: 10px; border: #e2dddd 1px solid;'><b>$key</b></td>
<td style='padding: 10px; border: #e2dddd 1px solid;'>$value</td>
</tr>
";
}
}
$message = "<table style='width: 100%;'>$message</table>";
function adopt($text) {
return '=?UTF-8?B?'.Base64_encode($text).'?=';
}
$headers = "MIME-Version: 1.0" . PHP_EOL .
"Content-Type: text/html; charset=utf-8" . PHP_EOL .
'From: '.adopt($project_name).' <'.$email_sender.'>' . PHP_EOL .
'Reply-To: '.$admin_email.'' . PHP_EOL;
if (mail($admin_email, adopt($form_subject), $message, $headers )) {
http_response_code(200);
echo "Данные отправлены.";
} else {
http_response_code(400);
echo "Ошибка. Данные не отправлены.";
};
?>