I'm having an interesting problem. Hopefully someone will be able to help me 'cause I'm at my wits end.
I've created a small program dealing with mail() in order to e-mail pdf attachments to clients. I have the pdf file on the server but seem to only be mailing a blank file (size 0). I'm using MIME and everything about my code looks correct but it's not working.
Here is my code where I attach the file:
function createAttach()
{
$this->boundary = md5(uniqid(time()));
$header = "MIME-Version: 1.0";
$header .= "\r\n";
$header .= "Content-type: multipart/mixed; boundary=\"$this->boundary\"";
$header .= "\r\n\r\n";
$header .= "Content-Transfer-Encoding: 7bit";
$header .= "\r\n";
$header .= "This is a multi-part message in MIME format.";
$header .= "\r\n\r\n";
$body = "--$this->boundary";
$body .= "\r\n";
$body .= "Content-type:text/plain; charset=us-ascii";
$body .= "\r\n";
$body .= "Content-transfer-encoding:7bit";
$body .= "\r\n\r\n";
$body .= $this->body;
$body .= "\r\n";
$body .= "--$this->boundary";
$body .= "\r\n";
// $report = createReport();
// $file = $this->BuildAttachment($report);
$file = "../report.pdf";
$fp = fopen($file,"r");
$file = fread($fp,filesize($file));
$file = chunk_split(base64_encode($file));
$body .= "Content-type:application/pdf; name=report.pdf";
$body .= "\r\n";
$body .= "Content-transfer-encoding:base64";
$body .= "\r\n";
$body .= "Content-Disposition: attachment; filename=report.pdf";
$body .= "\r\n";
$body .= $file;
$body .= "\r\n\r\n";
$body .= "--$this->boundary--";
$this->addHeader .= $header;
$this->body = $body;
} // function createBody()
The only thing I can guess why it's not working is that the e-mail is sent before the attachment builds - but I'm not an e-mail expert.
If anyone can help me out - or point me to someplace or someone that can help me .... please - I need help!