вот код
<?php
$boundary = md5(uniqid(time()));
$mail = "mail";
if(empty($_POST["subject"])
|| empty($_POST["user_mail"])) {
http_response_code(400);
}
$subject = htmlspecialchars($_POST["subject"]);
$backMail = htmlspecialchars($_POST["user_mail"]);
$html = "<html><head></head> <body>" ;
$html .= "Email пользователь:<a href='mailto:{$backMail}'> {$backMail}</a>";
if($_POST["message-text"]) {
$messageText = htmlspecialchars($_POST["message-text"]);
$html .= "<p>Сообщение пользоавателя: </p>" .$messageText;
}
$html .= "</body></html>";
$header = "FROM: 'Online book feeback' <{$mail}> \n";
$header .= "TO: {$mail} \n";
$header .= "Subject: {$subject} \n";
$header .= "Mime-Version: 1.0 \n";
$header .= "Content-Type: multipart/mixed; boundary='{$boundary}'";
$body = "\n--{$boundary}";
$body .= "Content-Type: text/plain; charset='windows-1251' \n";
$body .= "Content-Transfer-Encoding: quoted-printable \n";
$body .= $html;
if(count($_FILES) > 0) {
foreach ($_FILES as $name => $file) {
if(!$file["size"]) continue;
$file = fopen($file["tmp_name"], "rb");
$body .= "\n--{$boundary}";
$body .= "Content-Type: application/octet-stream;";
$body .= "name=".basename($name)."\n";
$body .= "Content-Transfer-Encoding:base64 \n";
$body .= "Content-Disposition:attachmentn \n";
$body .= base64_encode(fread($file, filesize($file["tmp_name"]))); // вот тут ошибка, пока не понял почему
//Warning: fread(): Length parameter must be greater than 0 in E:\OpenServer\domains\localhost\test\sendMail.php on line 48
}
}
$body .= "{$boundary}--";
if(mail($mail, $subject, $body, $header)){
echo "Письмо успешно отправлено";
}
else {
http_response_code(400);
}
?>