segy / Mpdf

CakePHP 2.x Component for creating PDF files from HTML using mPDF class
30 stars 19 forks source link

Pdf mail attachment 0Kb #3

Closed alessandro-riz closed 10 years ago

alessandro-riz commented 12 years ago

Hi, I am trying to send an email with attached a PDF file created with MpdfComponent but I get an empty file. I use the following code in the controller file:

$this->Mpdf = $this->Components->load('Mpdf');
$this->Mpdf->init();
$this->Mpdf->WriteHTML('Test');

$content = $this->Mpdf->Output('', 'S');
$content = chunk_split(base64_encode($content));

$mailto = 'to@mail.com';
$from_name = 'Test Test';
$from_mail = 'from@mail.com';
$replyto = 'from@mail.com';
$uid = md5(uniqid(time())); 
$subject = 'Test mail';
$message = 'Message in the mail';

$header = "From: " . $from_name . " <" . $from_mail. ">\r\n";
$header .= "Reply-To: " . $replyto . "\r\n";
$header .= "MIME-Version: 1.0\r\n";
$header .= "Content-Type: multipart/mixed; boundary=\"" . $uid . "\"\r\n\r\n";
$header .= "This is a multi-part message in MIME format.\r\n";
$header .= "--" . $uid . "\r\n";
$header .= "Content-type:text/plain; charset=iso-8859-1\r\n";
$header .= "Content-Transfer-Encoding: 7bit\r\n\r\n";
$header .= $message . "\r\n\r\n";
$header .= "--" . $uid . "\r\n";
$header .= "Content-Type: application/pdf; name=\"" . $fileName . "\"\r\n";
$header .= "Content-Transfer-Encoding: base64\r\n";
$header .= "Content-Disposition: attachment; filename=\"" . $fileName . "\"\r\n\r\n";
$header .= $content."\r\n\r\n";
$header .= "--" . $uid . "--";
$is_sent = @mail($mailto, $subject, "", $header);

The problem is that the variable $content is empty. If I use the same code in another file with directly the mpdf library all works fine... Is this a known issue or is only an error in my code?

Thanks very much Alessandro

lenichols commented 10 years ago

Were you ever able to figure this out? I too get empty pdf in email.

segy commented 10 years ago

Hello. Not sure if it is a same issue than this one: http://stackoverflow.com/questions/12829832/mpdf-no-pdf-generated-when-called-from-within-another-function

Please let me know if you find out.

segy commented 10 years ago

Hello. Please see updated readme