<?php
$method = $_SERVER['REQUEST_METHOD'];
//Script Foreach
$c = true;
if ( $method === 'POST' ) {
$project_name = trim($_POST["project_name"]);
$admin_email = trim($_POST["admin_email"]);
$form_subject = trim($_POST["form_subject"]);
$headers .= "Content-Type: multipart/mixed; boundary=\"$boundary\"\r\n";
$message="
Content-Type: multipart/mixed; boundary=\"$boundary\"
--$boundary
Content-Type: text/plain; charset=\"utf-8\"
Content-Transfer-Encoding: 7bit
$message";
if(is_uploaded_file($_FILES['fileFF']['tmp_name'])) {
$attachment = chunk_split(base64_encode(file_get_contents($_FILES['fileFF']['tmp_name'])));
$filename = $_FILES['fileFF']['name'];
$filetype = $_FILES['fileFF']['type'];
$filesize = $_FILES['fileFF']['size'];
$message.="
--$boundary
Content-Type: \"$filetype\"; name=\"$filename\"
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename=\"$filename\"
$attachment";
}
$message.="
--$boundary--";
foreach ( $_POST as $key => $value ) {
if ( $value != "" && $key != "project_name" && $key != "admin_email" && $key != "form_subject" ) {
$message .= "
" . ( ($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>
";
}
}
} else if ( $method === 'GET' ) {
$project_name = trim($_GET["project_name"]);
$admin_email = trim($_GET["admin_email"]);
$form_subject = trim($_GET["form_subject"]);
foreach ( $_GET as $key => $value ) {
if ( $value != "" && $key != "project_name" && $key != "admin_email" && $key != "form_subject" ) {
$message .= "
" . ( ($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>
";
}
}
}
$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).' <'.$admin_email.'>' . PHP_EOL .
'Reply-To: '.$admin_email.'' . PHP_EOL;
mail($admin_email, adopt($form_subject), $message, $headers );
//E-mail Ajax Send
$("form").submit(function() { //Change
var th = $(this);
$.ajax({
type: "POST",
url: "mail.php", //Change
data: th.serialize()
}).done(function() {
document.location.href = "thx.html";
setTimeout(function() {
// Done Functions
th.trigger("reset");
}, 1000);
});
return false;
});
});
<form id="ajax-contact-form" enctype="multipart/form-data" method="post">
<div class="form">
<h1 class="">Мы ждем Вашего запроса</h1>
<div class="">
<textarea class="" id="projectFF" name="projectFF"></textarea>
<!-- Hidden Required Fields -->
<input type="hidden" name="project_name" value="Site Name">
<input type="hidden" name="admin_email" value="@.ru">
<input type="hidden" name="form_subject" value="Form Subject">
<!-- END Hidden Required Fields -->
<input type="text" class="" name="Name" placeholder="Ваше имя" required><br>
<input type="text" class="" name="E-mail" placeholder="Ваш E-mail" required><br>
<input type="text" class="" name="Phone" placeholder="Ваш телефон" required><br>
</div>
<div class="" >Прикрепить файл</div>
<input id="fileFF" name="fileFF" type="file" multiple accept="image/*,image/jpeg,application/pdf,application/msword,text/plain,application/vnd.ms-excel"/>
</div>
Почему форма не обрабатывает вложение?