Y
Y
yooky2016-04-14 10:26:36
PHP
yooky, 2016-04-14 10:26:36

Attachment and mail.ru?

Good afternoon, there was such a problem.
I generate xls file using PHPexel and send it to the user's mail.
On gmail, the file comes whole and readable, but on mail.ru
in the xls file, I see the following:
[email protected]ЂA`[email protected]@`ЂCADrC*@APARAЂBC*AaA AA°APARA*[email protected]Ђ0CаDCа[email protected]*`а[email protected]@°@CaDD CC C*CC*ђCCАCАC D°C [email protected]а[email protected]*[email protected]РCCЂCАCPCРCаC CCPCЂCPB CaC [email protected]`*CaC°BP [email protected]`C*CЂ[email protected]*[email protected]@`[email protected]`CPCPCBCaBC*CЂ[email protected]*CaCђ@PD0CACACAD0CACACBCaBC*CЂ[email protected]*CаCђ@PpЂpЂ0DB CaCACDCPDCaB `[email protected]ЂЂ Bђ APA ° A * AaAAB `rCDCaDpCPC * B ° * D0C ° CPC * EP RCCCaDBrCaC0DCPCAD0DЂCPC * * Bp PЂЂђ ЂD B BCPD C * CPB ° CPD C * CEP * rCaC0DCPCAD0DЂC CBBЂ0Ђ0`ђrDCaDCPCpD ° C CD CPC ° DABA CЂC @ CBAACЂDЂC * CBAC ° CaCRCЂC *BAPCB°CЂDD CPB°PCB°CЂDD CPEPP`ђ@`` 0`` ђ DCPC0CаBRCaBpCC*CCpD0C**ђЃa°bА}`@* ° Ђ [email protected] @ `ЂfffffnctpЂfffffnctЂѓtђЂѓъ @ Ђ%ЂЂѓъ @ Ђ%ЂЂ33333=33333=33333=33333=33333=33333=33333=33333 `pPA [email protected]@ppPAPP`pPA`` pPApp`pPAЂp a°*P*@P*P ` P `0P `@P `PP ``P `pP `ЂP* @ P* P0 ` P ` 0P ` @P ` PP ` `P ` pP ` ЂPP*[email protected]@P*0PP `0 P `00P `[email protected] `0PP `0`P `0pP `0ЂPP*P`P*PpP*P ЂP*P0ђP*[email protected]* Р*PP°Р*P`АР*PpРР*PЂа0 а`яР*`рР*` 0 а`0р0 а`@D0 а`Pф0 а``ffffncґ0 а`pф0а`Ђffffncґ0 ap0 ap.4Р*p 0 ap0p0 [email protected] apP?R…IF#”0 ap`±Jd~Јd0 app?R…IF#”0 apЂ±Jd~Јd0 аЂ„0 аЂ
On the server, if you open the generated xls file, it's fine there too.
Here are my headers:

$path = '../tmp';
      $filename = "$random_hash.xls";
      $mailto = [email protected];
      $message = "example";
      $subject = "subject text";
      
 
      $file = $path . "/" . $filename;
      $file_size = filesize($file);
      $handle = fopen($file, "r");
      $content = fread($handle, $file_size);
      fclose($handle);
      $content = chunk_split(base64_encode($content));
 
      $separator = md5(time());
 
      // конец строки, константа
      $eol = PHP_EOL;
 
      $headers = "MIME-Version: 1.0" . $eol;
      $headers .= "From: Example <[email protected]>" . $eol;
      $headers .= "Content-Type: multipart/mixed; boundary=\"" . $separator . "\"" . $eol;
      $headers .= "Content-Transfer-Encoding: 7bit" . $eol;
      $headers .= "This is a MIME encoded message." . $eol;
 
      // письмо
      $headers .= "--" . $separator . $eol;
      $headers .= "Content-Type: text/plain;  charset=\"utf-8\"" . $eol;
      $headers .= "Content-Transfer-Encoding: 8bit" . $eol;
      $headers .= $message . $eol;
 
      // прикрепление 
      $headers .= "--" . $separator . $eol;
      $headers .= "Content-Type: application/vnd.ms-excel; name=\"" . $filename . "\"" . $eol;
      $headers .= "Content-Transfer-Encoding: base64" . $eol;
      $headers .= "Content-Disposition: attachment; filename=\"" . $filename . "\"" . $eol;
      $headers .= $content . $eol;
      $headers .= "--" . $separator . "--";
 
      //отправка письма
      if (mail($mailto, $subject, "", $headers, "[email protected]")) {
         echo "ok!";
      } else {
          echo "mail send ... ERROR!";
      }

Please tell me what could be the reason, and how to deal with it?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vladimir Dubrovin, 2016-04-15
@z3apa3a

multipart/mixed cannot have a Content-Transfer-Encoding.
Each header must be followed by a blank line - before
$headers .= "This is a MIME encoded message." . $eol;
before
$headers .= $message . $eol;
and before
$headers .= $content . $eol;
After the final separator - too.
Lines must be separated by CRLF, PHP_EOL on Linux is just LF.
If that doesn't help - post the final eml.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question