Posta eki olarak PDF - posta () false, hata döndürüyor

0 Cevap php

Ben o işi kullanılan, iyi bir kod var. Ama şimdi iş yapamaz. Normal posta () çalışır, ancak bu kod yok:

 <?php
    ob_start();
    error_reporting(E_ALL|E_STRICT);
    ini_set('display_errors', 1);
    require_once('dompdf_config.inc.php');


    $tpl = '<html>
 <style type="text/css">
 .bg1 {background-color:#8FE6F9; font-weight:bold;}
 body {font-family: Arial; font-face: Arial;}
 </style>
 <body>

 <table width="98%" border="0" align="center">
 <tr><td colspan="3" align="center"></td></tr>
 <tr>
  <td width="35%">&nbsp;</td>
  <td align="center" width="28%" nowrap="nowrap" style="font-size: 18px;">    <b>TYTUL</b><BR></td>
  <td align="right" width="35%">Faktura nr: <b>S-1000 ąśżźć󳥌ŻŹĆŁÓ</b>    <br>Data: <b>data</b></td>
 </tr>
 </table>
    </body>';

    $tpl .= '</body></html>';

    $encoding = 'Windows-1250';

    $dompdf = new DOMPDF();
    $dompdf->load_html(iconv('UTF-8', $encoding.'//IGNORE', $tpl));
    $dompdf->render();


    $mode = 'send';

    if( $mode == 'send' )
    {
 $name = 'raport.pdf';
 $fullpath_invoice  = $name;

 if(file_put_contents($fullpath_invoice, $dompdf->output()))
 {
  $message = 'jakas tresc w HTML';

  $BOUNDARY_1 = '------------3020208030402090901'.rand(10000, 99999);
  $BOUNDARY_2 = '------------3020208030402090902'.rand(10000, 99999);

  $rand_1 = md5(rand(0, 99999).microtime());
  $rand_2 = md5(rand(0, 99999).microtime());

  $output = "This is a multi-part message in MIME format.\n";
  $output .= "--$BOUNDARY_1\n";
  $output .= "Content-Type: multipart/alternative;\n boundary=\"$BOUNDARY_2\"\n\n";

  $output .= "--$BOUNDARY_2\n";
  $output .= "Content-Type: text/plain; charset=UTF-8; format=flowed\n";
  $output .= "Content-Transfer-Encoding: 7bit\n\n";

  $message_unhtml = preg_replace('#<a href="(.*?)">(.*?)</a>#', '\\1', str_replace(array("\n", "\r"), '', $message));
  $message_unhtml = str_replace('<br>', "\n", $message_unhtml);
  $message_unhtml = strip_tags($message_unhtml);
  $message_HTML = $message;

  $message = $output;
  $message .= $message_unhtml."\n\n";

  $message .= "--$BOUNDARY_2\n";

  $message .= "Content-Type: text/html; charset=UTF-8\n";
  $message .= "Content-Transfer-Encoding: 7bit\n\n";
  $message .= "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">
  <html>
  <head>

  <meta http-equiv=\"content-type\" content=\"text/html; charset=UTF-8\">
  <style type=\"text/css\"> 
  body{
   background:#FFFFFFF;
   font-family: Tahoma, Helvetica, Verdana, Arial, sans-serif;
   font-size:13px;
   color:#2D3235;
  };
  </style>
  </head>
  <body>
  ".$message_HTML."
  </body>

  </html>\n\n";

  $message .= "--$BOUNDARY_2--\n\n";

  if(file_exists($fullpath_invoice))
  {
   $file = fopen( $fullpath_invoice, "rb" );
   $data = fread( $file, filesize( $fullpath_invoice ) );
   fclose( $file );
   $data = chunk_split( base64_encode( $data ) ); 

   $message .= "--$BOUNDARY_1\n";
   $message .= "Content-Type: application/pdf;\n name=\"$name.pdf\"\n";
   $message .= "Content-Disposition: attachment;\n filename=\"$name.pdf\"\n";
   $message .= "Content-Transfer-Encoding: base64\n\n";
   $message .= "$data\n\n";

   unset($data);
  }
  $message .= "--$BOUNDARY_1--\n";

  $headers = "Content-Type: multipart/mixed;\n boundary=\"$BOUNDARY_1\"\n\n";

  if(mail('misiur66@gmail.com', 'pdf', $message, $headers))
  {
   echo 'Wysłano';
  }
  else
  {
   echo 'Błąd';
  }
 }
    }
    else
    {
 $dompdf->stream('nazwa_pliku.pdf');
    }

    ob_end_flush();

    ?>

Bu kod, bir sunucu üzerinde çalışır, ancak diğer ilgili değil. Ne bunun nedeni olabilir? Gerekirse ben phpinfo falan ekleyebilirsiniz.

0 Cevap