I am having a difficult time attaching a .pdf file to an email. I am using the mail class mentioned in several posts on this forum which has an add_attachment() method. This method requires three parameters; 1) the actual content which is created by an fread(), 2) a file name for the attachment and 3) the MIME type for the file.
My code reads a 3853 byte .pdf but it appears to be only reading 185 bytes and then stops. I am wondering what the correct MIME Type is for a .pdf document. I have tried both:
document/pdf and
acrobat/pdf
Anyway, why would fread() stop reading after 185 bytes?
Here is the code:$fName = 'test.pdf';
$fSize = filesize( $fName );
$fp = fopen( $fName, 'r' );
$attachment = fread( $fp, $fSize );
fclose( $fp );
$mail = new mime_mail();
$mail->from = "The WebReports System <my_email@mydomain.com>";
$mail->headers = "Errors-To: The WebReports System <my_email@mydomain.com>";
$mail->to = "my_email@mydomain.com";
$mail->subject = "Testing PDF Attachment";
$mail->body = $Message;
$mail->add_attachment("$attachment", "report.pdf", "document/pdf" );
$mail->send();
Thank you!
Chris Streeter
Bethlehem, PA, USA
chris@thestreeters.net