N
N
neti_solo2018-06-26 06:04:49
PHP
neti_solo, 2018-06-26 06:04:49

The mail php text is not shown, but the attachment is coming, what should I do?

Here is my code, the attached file is coming, but the text is not coming(

if ( isset($_POST["upload"]) ) {

        $filename = $_FILES["file"]["name"];
        $filepath = $_FILES["file"]["tmp_name"];

        $subject = "Заявка с вложением"; 

        $message ="						
            <p>Телефон: ". $_POST["number"] ."</p>
            <p>Имя: ". $_POST["names"] ."</p>

            <p>Текст: ". $_POST["textMessage"] ."</p>
            \r\n"; 


        $boundary = "--".md5(uniqid(time())); 

        $mailheaders = "MIME-Version: 1.0;\r\n"; 
        $mailheaders .="Content-Type: multipart/mixed; boundary=\"$boundary\"\r\n"; 

        $mailheaders .= "From: [email protected] <[email protected]>\r\n"; 
        $mailheaders .= "Reply-To: [email protected]\r\n"; 

        $multipart = "--$boundary\r\n"; 
        $multipart .= "Content-Type: text/html; charset=windows-1251\r\n";
        $multipart .= "Content-Transfer-Encoding: base64\r\n";   
        $multipart .= chunk_split(base64_encode(iconv("utf8", "windows-1251", $message)));
        $multipart .= "\r\n";
        // первая часть само сообщение
         
        // Закачиваем файл 
          $fp = fopen($filepath,"r"); 
            if (!$fp) 
            { 
              print "Не удается открыть файл :("; 
              exit(); 
            } 
        $file = fread($fp, filesize($filepath)); 
        fclose($fp); 
        // чтение файла


        $message_part = "\r\n--$boundary\r\n"; 
        $message_part .= "Content-Type: application/octet-stream; name=\"$filename\"\r\n";  
        $message_part .= "Content-Transfer-Encoding: base64\r\n"; 
        $message_part .= "Content-Disposition: attachment; filename=\"$filename\"\r\n"; 
        $message_part .= "\r\n";
        $message_part .= chunk_split(base64_encode($file));
        $message_part .= "\r\n--$boundary--\r\n";
        // второй частью прикрепляем файл, можно прикрепить два и более файла

        $multipart .= $message_part;

        mail($to,$subject,$multipart,$mailheaders);
        // отправляем письмо 

        //удаляем файлы через 60 сек.
        if (time_nanosleep(5, 0)) {
            unlink($filepath);
        }
        // удаление файла

      }

<input type="file" name="file" id="file" class="inputfile"/>
          <label for="file" id="label"><p><span class="above">Выберете файл со списком,</span><br /><span class="below">кликнув по данному тексту</span></p></label>	
<input type="text" name="names" placeholder="Ваше имя*" id="name">
        <input type="text" name="number" placeholder="Телефон*" id="number">
        <input type="text" name="textMessage" placeholder="Сообщение" id="message">
        <input type="submit" name="upload" value="Отправить" id="submit">

With hmtl, I vouch, everything is in order, but on php I'm stupid, well, I just can't find it - what's the reason. I tried to shove \r\n everywhere, it doesn't work either... Please help!!!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
alekssamos, 2018-06-30
@alekssamos

1) Better use the PHPMailer library .
2) You already answered on the forum:
5b3728ba13d39504650585.png

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question