I've been working on attaching pdf to e-mail with no luck.
The purpose for this code is to take results from a form, dynamicly create a "good looking" report (in pdf), and give the user the ability to e-mail this to themselves or others.
I found a nifty pdf creator, R&OS, at www.ros.co.nz/pdf which I'm using. I've fooled around with it and can create some wonderful reports.
I don't want to save each report to my server and use that file to attach to the MIME. For security reasons and size issues, I'd much rather just pump the data directly into the attachment.
I've done some tests where I can create and attach other file types (html, txt, etc) but can't get good results with pdf. I'm not a MIME expert (I only recently started looking into it) so the problem might be there. It also could be my output() function in R&OS that is causing my error.
What is happening is I'm sending a pdf but it just give me errors and loads blank. The errors includes:
1) There was an error in reading this page. There was a problem reading this document (14).
2) Could not find font in the Resource directory - using Helvetica instead
3) There was a problem reading this document (14).
I'm not sure what problem it is, MIME or R&OS. If it's R&OS, I'm not sure where to turn to for questions. I've included a few files if someone wants to look around.
To summary code:
// R&OS section
$author = "some guy";
$pdf = new Cpdf();
$pdf->addPngFromFile('images/logo.png',75,165,125,59);
$pdf->addText(210,420,14,"<b>By:</b> <i>".$author."</i>");
//$pdf->stream(); // I don't want to output the data to the screen - just to a variable
$report = $pdf->output();
// MIME section
$mail_charset = "us-ascii";
$mail_encoding = "8bit";
$userfile = "report.pdf";
$userfile_size = 0;
$userfile_type = "application/pdf";
$userfile_name = "report.pdf";
$mail_boundary = md5(uniqid(time()));
$mail_header .= "MIME-Version: 1.0\r\n";
$mail_header .= "Content-type: multipart/mixed;boundary=\"$mail_boundary\"\r\n\r\n";
$mail_header .= "This is a multi-part message in MIME format.\r\n\r\n";
$file = BuildAttachment($report);
$mail_body = "--$mail_boundary\r\n";
$mail_body .= "Content-type: text/plain;charset=$mail_charset\r\n";
$mail_body .= "Content-transfer-encoding:$mail_encoding\r\n\r\n";
$mail_body .= "$mail_body\r\n";
$mail_body .= "--$mail_boundary\r\n";
if(!empty($userfile_type)) $mime_type = $userfile_type;
else $mime_type = "application/octet-stream";
$mail_body .= "Content-type:$mime_type; name=$userfile_name\r\n";
$mail_body .= "Content-transfer-encoding:base64\r\n\r\n";
$mail_body .= $file."\r\n\r\n";
$mail_body .= "--$mail_boundary--";
function BuildAttachment($string)
{
set_magic_quotes_runtime(0);
$FileContent = chunk_split(base64_encode($string));
$attachment = $FileContent;
$attachment .="\n\n";
set_magic_quotes_runtime(get_magic_quotes_gpc());
return $attachment;
} // end function BuildAttachment($string)
If someone can help me it would be greatly appreciated. So far I'm pulling out my hair 'cause I know (somehow) this is possible.