[ Поиск ] - [ Пользователи ] - [ Календарь ]
Полная Версия: Помогите доработать скрипт обратной связи
vaf
Всем привет. Я новичок в PHP, нужна помощь.
Есть скрипт обратной связи со вложением, работает отлично, но если отправляешь сообщение без вложения, то выдает ошибку
Warning: file_get_contents() [function.file-get-contents]: Filename cannot be empty in feedback.php on line 15

вот эта строка.
$attachment = chunk_split(base64_encode(file_get_contents($_FILES['fileFF']['tmp_name'])));

Как я понимаю нужно где то поставить условие, что если ничего не прикреплено, то он отправлял без $attachment, подскажите где поставить условие, чтобы скрипт корректно работал без вложения.

Заранее спасибо.



<?php
if (isset ($_POST['contactFF'])) {

$output = '<p style="color: green">Ваше сообщение получено, спасибо!</p>';

$to = "vaf2010@yandex.ru"; // поменять на свой адрес
$from = $_POST['contactFF'];
$subject = "Заполнена контактная форма с ".$_SERVER['HTTP_REFERER'];
$message = "Имя: ".$_POST['nameFF']."\nEmail: ".$from."\nСообщение: ".$_POST['messageFF'];

$attachment = chunk_split(base64_encode(file_get_contents($_FILES['fileFF']['tmp_name'])));
$filename = $_FILES['fileFF']['name'];
$filetype = $_FILES['fileFF']['type'];

$boundary = md5(date('r', time()));

$headers = "From: " . $from . "\r\n";
$headers .= "Reply-To: " . $from . "\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: multipart/mixed; boundary=\"_1_$boundary\"";

$message="
--_1_
$boundary
Content-Type: multipart/alternative; boundary=\"_2_$boundary\"

--_2_$boundary
Content-Type: text/plain; charset=\"utf-8\"
Content-Transfer-Encoding: 7bit

$message

--_2_$boundary--
--_1_
$boundary
Content-Type: \"$filetype\"; name=\"$filename\"
Content-Transfer-Encoding: base64
Content-Disposition: attachment


$attachment
--_1_$boundary--";

mail($to, $subject, $message, $headers);

}
?>


<!DOCTYPE HTML>

<
meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<
title>Контактная форма</title>
<
style>
#feedback-form {
max-width: 550px;
padding: 2%;
border-radius: 3px;
background: #f1f1f1;
}
#feedback-form label {
float: left;
display: block;
clear: right;
}
#feedback-form .w100 {
float: right;
max-width: 400px;
width: 97%;
margin-bottom: 1em;
padding: 1.5%;
}
#feedback-form .border {
border-radius: 1px;
border-width: 1px;
border-style: solid;
border-color: #C0C0C0 #D9D9D9 #D9D9D9;
box-shadow: 0 1px 1px rgba(255,255,255,.5), 0 1px 1px rgba(0,0,0,.1) inset;
}
#feedback-form .border:focus {
outline: none;
border-color: #abd9f1 #bfe3f7 #bfe3f7;
}
#feedback-form .border:hover {
border-color: #7eb4ea #97cdea #97cdea;
}
#feedback-form .border:focus::-moz-placeholder {
color: transparent;
}
#feedback-form .border:focus::-webkit-input-placeholder {
color: transparent;
}
#feedback-form .border:not(:focus):not(:hover):valid {
opacity: .4;
}
#submitFF {
padding: 2%;
border: none;
border-radius: 3px;
box-shadow: 0 0 0 1px rgba(0,0,0,.2) inset;
background: #669acc;
color: #fff;
}
#feedback-form br {
height: 0;
clear: both;
}
#submitFF:hover {
background: #5c90c2;
}
#submitFF:focus {
box-shadow: 0 1px 1px #fff, inset 0 1px 2px rgba(0,0,0,.8), inset 0 -1px 0 rgba(0,0,0,.05);
}
</style>

<?php echo $output; ?>
<form enctype="multipart/form-data" method="post" id="feedback-form">
<
label for="nameFF">Имя:</label>
<
input type="text" name="nameFF" id="nameFF" required placeholder="например, Иван Иванович Иванов" x-autocompletetype="name" class="w100 border">
<
label for="contactFF">Email:</label>
<
input type="email" name="contactFF" id="contactFF" required placeholder="например, ivan@yandex.ru" x-autocompletetype="email" class="w100 border">
<
label for="fileFF">Прикрепить файл:</label>
<
input type="file" name="fileFF" id="fileFF" class="w100">
<
label for="messageFF">Сообщение:</label>
<
textarea name="messageFF" id="messageFF" required rows="5" placeholder="Детали заявки…" style="width: 398px; height: 185px;" class="w100 border"></textarea>
<
br>
<
input value="Отправить" type="submit" id="submitFF">
</
form>
Быстрый ответ:

 Графические смайлики |  Показывать подпись
Здесь расположена полная версия этой страницы.
Invision Power Board © 2001-2024 Invision Power Services, Inc.