Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 917657
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T18:14:43+00:00 2026-05-15T18:14:43+00:00

I’ve got good code, it used do work. But now I can’t make it

  • 0

I’ve got good code, it used do work. But now I can’t make it work. Normal mail() works, but this code doesn’t:

 <?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();

    ?>

This code works on one server, but doesn’t on other. What can be cause of it? If needed I can attach phpinfo or something.

  • 1 1 Answer
  • 1 View
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T18:14:44+00:00Added an answer on May 15, 2026 at 6:14 pm

    Any reason you’re building the MIME message yourself? Using something like PHPMailer does it all for you with much less hassle, and will also give much better feedback if an error occurs in the mail end of things.

    I take it nothing’s showing up in the PHP and/or Apache error logs? Server suddenly has a reduced memory limit, new version of the PDF library installed, etc…?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
Does anyone know how can I replace this 2 symbol below from the string
I want to count how many characters a certain string has in PHP, but
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.