I try to send a letter to the mail, everything comes and the file itself comes, but for some reason it is empty and 0KB in size.

<?php $toowner = 'an.semeryanova@yandex.ru'; $toclient = $_POST['email']; if ( isset( $_POST['sendMail'] ) ) { $name = substr( $_POST['name'], 0, 64 ); $tel = substr( $_POST['tel'], 0, 64 ); $email = substr( $_POST['email'], 0, 64 ); // $message = substr( $_POST['message'], 0, 250 ); $pathabs = __DIR__ ; $filemy = 'blank.xls'; if ( !empty( $_FILES['file']['tmp_name'] ) and $_FILES['file']['error'] == 0 ) { $filepath = $_FILES['file']['tmp_name']; $filename = $_FILES['file']['name']; } else { $filepath = $pathabs; $filename = $filemy; } $body = "Имя:\r\n".$name."\r\n\r\n"; $body .= "Контактный номер:\r\n".$tel."\r\n\r\n"; $body .= "E-mail:\r\n".$email."\r\n\r\n"; //$body .= "Описание заказа:\r\n".$message; $filepath2 = ''; $filename2 = ''; send_mail($toclient, $body, $email, $filepath, $filename); send_mail($toowner, $body, $email, $filepath2, $filename2); } // Вспомогательная функция для отправки почтового сообщения с вложением function send_mail($toclient, $body, $email, $filepath, $filename) { $subject = 'Оптовый прайс'; $boundary = "--".md5(uniqid(time())); // генерируем разделитель $headers = "From: ".$email."\r\n"; $headers .= "MIME-Version: 1.0\r\n"; $headers .="Content-Type: multipart/mixed; boundary=\"".$boundary."\"\r\n"; $multipart = "--".$boundary."\r\n"; $multipart .= "Content-type: text/plain; charset=\"utf-8\"\r\n"; $multipart .= "Content-Transfer-Encoding: quoted-printable\r\n\r\n"; $body = $body."\r\n\r\n"; $multipart .= $body; $file = ''; if ( !empty( $filepath ) ) { $fp = fopen($filepath, "r"); if ( $fp ) { $content = fread($fp, filesize($filepath)); fclose($fp); $file .= "--".$boundary."\r\n"; $file .= "Content-Type: application/octet-stream\r\n"; $file .= "Content-Transfer-Encoding: base64\r\n"; $file .= "Content-Disposition: attachment; filename=\"".$filename."\"\r\n\r\n"; $file .= chunk_split(base64_encode($content))."\r\n"; } } $multipart .= $file."--".$boundary."--\r\n"; mail($toclient, $subject, $multipart, $headers); } ?> 
  • so filepath without a file name, but only the path contains? fopen ($ filepath. filename, "r"); probably, well, a slash is probably necessary between them - koks_rs
  • and where to put the slash exactly? did not quite understand - Egor Krotenko
  • I just do not know if there is a slash in the filepath at the end, if not, add $ filepath. "/". $ filename to get the correct file path - koks_rs
  • $ fp = fopen ($ filepath. $ filename, "r"); so the file does not come at all - Egor Krotenko
  • $ filepath. "/". $ filename didn't help either - Yegor Krotenko

0