Здравствуйте! Пытаюсь отправить изображение на почту, но что-то у меня не выходит
<form id="formF" enctype="multipart/form-data" method="post">
<p>
<input type="file" name="fileforsending" multiple accept="image/*,image/jpeg">
</p>
</form>
<?php
$the_file = '';
if (!empty($_FILES['fileforsending']['tmp_name'])) {
$path = "files/".$_FILES['fileforsending']['name'];
if (copy($_FILES['fileforsending']['tmp_name'], $path)) {
$the_file = $path;
}
}
$file = $the_file;
$file_size = filesize($file);
$handle = fopen($file, "r");
$content = fread($handle, $file_size);
fclose($handle);
$content = chunk_split(base64_encode($content));
$uid = md5(uniqid(time()));
$name = basename($file);
$message = "--" . $uid . "\r\n";
$message .= "Content-type:text/html; charset=utf-8 \r\n";
$message .= "Content-Transfer-Encoding: 7bit\r\n\r\n";
$message .= $message . "\r\n\r\n";
$message .= "--" . $uid . "\r\n";
$message .= "Content-Type: application/octet-stream; name=\"" . $the_file . "\"\r\n";
$message .= "Content-Transfer-Encoding: base64\r\n";
$message .= "Content-Disposition: attachment; filename=\"" . $the_file . "\"\r\n\r\n";
$message .= $content . "\r\n\r\n";
$message .= "--" . $uid . "--";
$spectext = '<!DOCTYPE HTML><html><head><title>Заказ</title></head><body>';
$headers = 'MIME-Version: 1.0' . "\r\n" .
"Content-Type: multipart/mixed; boundary=\"" . $uid . "\"\r\n\r\n" .
'From: noreply@mail.ru' . "\r\n" .
'Reply-To: mail.ru' . "\r\n";
$m = mail($to, 'Заказ в магазине', $spectext.$message.'</body></html>', $headers);
if ($m) {echo 1;} else {echo 0;}
?>