При проверке в firebug предупреждение: GSAP target .link not found. Хотя Gsap подключен, пробовал и локально, как в версии ниже, и через CDN с greensock.
И при просмотре результатов: все в теле письма есть, кроме текста сообщения. Заранее благодарен.
<!DOCTYPE html>
<html lang="ru">
<head>
<meta charset="UTF-8">
<title>PHPMAILER</title>
<link rel="stylesheet" href="styles/style.css">
<script src="js/gsap.min.js"></script>
<meta id="viewport" name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<div class="msg" onclick="gsapMsg.reverse()">Сообщение
</div>
<div class="wrap">
<form enctype="multipart/form-data" method="post" id="form" onsubmit="send(event, 'send.php')">
<div class="group-input">
<div class="group-text-input">
<div class="input-wrap">
<input name="name" id="name" type="text" class="form-input aInput" autocomplete="off">
<label for="name" class="input-label">Представьтесь</label>
</div>
<div class="input-wrap">
<input name="email" id="email" type="text" class="form-input aInput" autocomplete="off">
<label for="email" class="input-label">Укажите почту</label>
</div>
</div>
<div class="input-wrap">
<textarea name="texta" id="texta" class="aInput"></textarea>
<label for="texta" class="area-label">Сообщение</label>
</div>
</div>
<div class="file-wrap">
<label for="myfile" class="labelFile">
<img src="https://img.icons8.com/ios/50/000000/upload-to-cloud.png" alt="img"/>
<p class="count">Прикрепить файлы</p>
</label>
<input type="file" multiple class="inputFile" id="myfile" name="file[]" onchange="inputFile(event)"/>
</div>
<button type="submit" class="button right">Отправить</button>
</form>
</div>
<script src="js/script.js"></script>
</body>
</html>
body {
margin: 0;
background: #f4f7fb;
font-family: 'Roboto', sans-serif;
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-webkit-box-pack: center;
-ms-flex-pack: center;
justify-content: center;
-webkit-box-align: center;
-ms-flex-align: center;
align-items: center;
-ms-flex-wrap: wrap;
flex-wrap: wrap;
min-height: 100%;
position: absolute;
min-width: 100%;
font-size: 16px;
height: 99%;
}
#form, .link, .input-wrap, .file-wrap, .button {
visibility: hidden;
}
.file-wrap {
transform: translateX(-10px);
}
.button {
transform: translateX(10px);
}
#form, .input-wrap {
transform: translateY(-15px);
}
.link {
transform: translateY(15px);
}
.msg {
max-width: 320px;
width: 80%;
position: fixed;
padding: 25px 15px;
left: 0;
right: 0;
margin: auto;
bottom: 0;
color: #ffffff;
text-align: center;
border-radius: 7px;
font-weight: 500;
opacity: 0;
cursor: pointer;
z-index: 555;
}
.showmsg {
visibility: visible !important;
opacity: 1 !important;
-webkit-transform: translateY(-5vh);
-ms-transform: translateY(-5vh);
transform: translateY(-5vh);
-webkit-animation: shadow 0.3s 2.5s forwards ease-in-out;
animation: shadow 0.3s 2.5s forwards ease-in-out;
}
@-webkit-keyframes view {
from {opacity: 0;}
to {opacity: 1;-webkit-transform: translateY(-5vh);transform: translateY(-5vh);}
}
@keyframes view {
from {opacity: 0;}
to {opacity: 1;-webkit-transform: translateY(-5vh);transform: translateY(-5vh);}
}
@-webkit-keyframes hide {
to {opacity: 0;-webkit-transform: translateY(0);transform: translateY(0);}
}
@keyframes hide {
to {opacity: 0;-webkit-transform: translateY(0);transform: translateY(0);}
}
.inputerror {
border-color: #DC352F !important;
animation: shake 0.15s 3 forwards ease-in-out;
}
@keyframes shake {
from {transform: translateX(0px);}
50% {transform: translateX(3px);}
to {transform: translateX(-3px);}
}
.link {
max-width: 325px;
display: -webkit-box;
display: -ms-flexbox;
display: flex;
text-decoration: none;
padding: 20px 30px;
background: #ffffff;
color: #333;
-webkit-box-align: center;
-ms-flex-align: center;
align-items: center;
margin: 50px auto;
}
.link img {
height: 35px;
margin-right: 25px;
}
.link p {
margin: 0;
font-size: 15px;
}
.wrap {
max-width: 650px;
width: 90%;
}
#form {
width: 100%;
padding: 50px;
-webkit-box-sizing: border-box;
box-sizing: border-box;
background: #ffffff;
-webkit-box-shadow: 0 15px 25px -22px rgba(25, 41, 62, 0.3);
box-shadow: 0 15px 25px -22px rgba(25, 41, 62, 0.3);
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-ms-flex-wrap: wrap;
flex-wrap: wrap;
-webkit-box-pack: justify;
-ms-flex-pack: justify;
justify-content: space-between;
}
.group-input {
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-webkit-box-pack: justify;
-ms-flex-pack: justify;
justify-content: space-between;
width: 100%;
-ms-flex-wrap: wrap;
flex-wrap: wrap;
}
.input-wrap {
position: relative;
margin-bottom: 25px;
width: 260px;
}
/* input */
.input-wrap label {
pointer-events: none;
position: absolute;
left: 20px;
-webkit-transition: all 0.2s ease-in-out;
-o-transition: all 0.2s ease-in-out;
transition: all 0.2s ease-in-out;
color: #848e99;
}
.form-input {
height: 60px;
width: 100%;
padding: 20px 20px 0px;
background: none;
outline: none;
-webkit-box-sizing: border-box;
box-sizing: border-box;
font: 500 17px 'Roboto';
border: solid 1px #dde1e6;
border-radius: 4px;
}
.input-label {
line-height: 60px;
}
.area-label {
-webkit-transition: all 0.2s ease-in-out;
-o-transition: all 0.2s ease-in-out;
transition: all 0.2s ease-in-out;
background: #ffffff;
padding: 8px 0 10px;
width: calc(100% - 34px);
left: 20px;
position: absolute;
top: 11px;
color: #848e99;
}
.active {
font-size: 14px;
-webkit-transform: translateY(-10px);
-ms-transform: translateY(-10px);
transform: translateY(-10px);
}
/* inputfile */
.labelFile {
width: 210px;
height: 52px;
border-radius: 4px;
cursor: pointer;
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-webkit-box-align: center;
-ms-flex-align: center;
align-items: center;
font-size: 14px;
font-weight: 500;
-webkit-transition: all 0.2s ease-in-out;
-o-transition: all 0.2s ease-in-out;
transition: all 0.2s ease-in-out;
border: 1px solid #c7ced7;
color: #2c3949;
background: #f4f7fb;
}
.labelFile:hover {
background: #E2E9F4
}
.labelFile:active {
background: #dae1ec;
}
.inputFile {
width: 0.1px;
height: 0.1px;
opacity: 0;
overflow: hidden;
position: absolute;
z-index: -1;
}
.labelFile img {
height: 55%;
margin: 5% 4% 5% 8%;
}
#texta {
resize: none;
width: 100%;
height: 100%;
padding: 34px 20px;
font: 16px 'Roboto';
outline: none;
-webkit-box-sizing: border-box;
box-sizing: border-box;
border: solid 1px #dde1e6;
border-radius: 4px;
-webkit-transition: border 0.2s ease-in-out;
-o-transition: border 0.2s ease-in-out;
transition: border 0.2s ease-in-out;
}
#texta::-webkit-scrollbar {
width: 14px;
}
#texta::-webkit-scrollbar-thumb {
background-clip: content-box;
border: 4px solid transparent;
border-radius: 7px;
-webkit-box-shadow: inset 0 0 0 10px;
box-shadow: inset 0 0 0 10px;
color: #bdbdbd;
}
#texta::-webkit-scrollbar-button {
width: 0;
height: 0;
display: none;
}
#texta::-webkit-scrollbar-corner {
background-color: transparent;
}
.aInput {
transition: border 0.2s ease-in-out;
}
.aInput:hover {
border: solid 1px #B4BBC3
}
.aInput:focus {
border: solid 1px #6EAFFE;
}
.button {
width: 150px;
height: 52px;
background: #2045cb;
border: none;
outline: none;
color: #ffffff;
border-radius: 5px;
cursor: pointer;
-webkit-transition: background 0.1s ease-in-out;
-o-transition: background 0.1s ease-in-out;
transition: background 0.1s ease-in-out;
font: 500 16px 'Roboto';
}
.button:hover {
background: #1E41BD;
}
.button:active {
background: #18359C;
}
.button:disabled {
cursor: not-allowed;
background: #b1b1b1;
}
@media (min-width:320px) and (max-width: 729px) {
.group-text-input,
.input-wrap {
width: 100%;
}
}
@media (max-width: 570px) {
#form {
-webkit-box-orient: vertical;
-webkit-box-direction: normal;
-ms-flex-direction: column;
flex-direction: column;
padding: 30px 7vw;
}
.labelFile img {
margin-left: 0;
}
.labelFile {
width: 100%;
-webkit-box-pack: center;
-ms-flex-pack: center;
justify-content: center;
margin-bottom: 25px;
}
.button {
margin: 10px auto;
width: 70%;
min-width: 150px;
}
}
var msg = document.querySelector(".msg");
var gsapMsg = gsap.to(".msg", 0.25, {autoAlpha: 1,y: -40,ease: Expo.inOut, paused: true});
var arrInput = document.querySelectorAll('.aInput');
// Функция отправки сообщения
function send(event, php){
event.preventDefault ? event.preventDefault() : event.returnValue = false;
for (var i = 0,count=arrInput.length; i<count; i++) {arrInput[i].classList.remove("errorInput");}
event.target.querySelector("button").disabled = true;
showMsg("Подождите. Идёт отправка сообщения", "#b1b1b1");
var req = new XMLHttpRequest();
req.open('POST', php, true);
req.onload = function() {
event.target.querySelector("button").disabled = false;
if (req.status >= 200 && req.status < 400) {
json = JSON.parse(this.response); // internet explorer 11
console.log(json);
// ЗДЕСЬ УКАЗЫВАЕМ ДЕЙСТВИЯ В СЛУЧАЕ УСПЕХА ИЛИ НЕУДАЧИ
if (json.result == "success") {
// если сообщение отправлено
showMsg("Сообщение успешно отправлено", "#36AE46");
console.log("Сообщение отправлено");
event.target.reset();
} else if(json.result == "email") {
// Если указан неверный email
showMsg("Ошибка. Неверно указан Email", "#DC352F");
console.log("Ошибка. Неверно указан Email");
document.querySelector("#email").classList.add("inputerror");
} else {
// Если произошла ошибка
showMsg("Ошибка. Сообщение не отправлено", "#DC352F");
console.log("Ошибка. Сообщение не отправлено");
}
// Если не удалось связаться с php файлом
} else {showMsg("Ошибка сервера. Номер: "+req.status, "#DC352F");}};
// Если не удалось отправить запрос. Стоит блок на хостинге
req.onerror = function() {showMsg("Ошибка отправки запроса", "#DC352F");};
req.send(new FormData(event.target));
}
// Функция появления статуса отправки сообщения
function showMsg(message, color) {
msg.innerText = message;
msg.style.background = color;
gsapMsg.restart();
}
// Оформление input file
function inputFile(e) {
el = e.target.parentNode.querySelector(".count");
if (e.target.value != '') el.innerHTML = "Выбрано файлов: " + e.target.files.length;
else el.innerHTML = 'Прикрепить файлы';
}
// Анимация input text
for (var i = 0, count = arrInput.length; i < count; i++) {
arrInput[i].addEventListener("focus", function() {
this.nextElementSibling.classList.add("active");
});
arrInput[i].addEventListener("blur", function() {
if (this.value == false)
this.nextElementSibling.classList.remove("active");
});
}
// Анимация появления блоков
window.onload = function() {
var loadPage = gsap.timeline();
loadPage.to("#form", 0.7, {autoAlpha: 1,y: 0, ease: Expo.inOut});
loadPage.to(".link", 0.7, {autoAlpha: 1,y: 0, ease: Expo.inOut}, 0);
loadPage.to(".input-wrap", 0.5, {stagger: 0.15, autoAlpha: 1,y: 0, ease: Expo.inOut}, 0.35);
loadPage.to(".file-wrap, .button", 0.5, {stagger: 0.15, autoAlpha: 1,x: 0, ease: Expo.inOut}, 0.6);
}
<?php
// Файлы phpmailer
require 'phpmailer/PHPMailer.php';
require 'phpmailer/SMTP.php';
require 'phpmailer/Exception.php';
// Переменные, которые отправляет пользователь
$name = $_POST['name'];
$email = $_POST['email'];
$text = $_POST['text'];
$file = $_FILES['file'];
// Формирование самого письма
$title = "Заголовок письма";
$body = "
<h2>Новое письмо</h2>
<b>Имя:</b> $name<br>
<b>Почта:</b> $email<br><br>
<b>Сообщение:</b><br>$text
";
// Валидация почты
if (filter_var($email, FILTER_VALIDATE_EMAIL)) {
// Настройки 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.yandex.ru';
$mail->Username = 'login';
$mail->Password = 'password';
$mail->SMTPSecure = 'ssl';
$mail->Port = 465;
$mail->setFrom('mymail@yandex.ru', 'имя');
$mail->addAddress('mymail@mail.ru');
// Прикрепление файлов к письму
if (!empty($file['name'][0])) {
for ($ct = 0; $ct < count($file['tmp_name']); $ct++) {
$uploadfile = tempnam(sys_get_temp_dir(), sha1($file['name'][$ct]));
$filename = $file['name'][$ct];
if (move_uploaded_file($file['tmp_name'][$ct], $uploadfile)) {
$mail->addAttachment($uploadfile, $filename);
$rfile[] = "Файл $filename прикреплён";
} else {
$rfile[] = "Не удалось прикрепить файл $filename";
}
}
}
// Отправка сообщения
$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}";
}
} else {
$result = "email";
}
// Отображение результата
echo json_encode(["result" => $result, "resultfile" => $rfile, "status" => $status]);
?>