Package home | Report new bug | New search | Development Roadmap Status: Open | Feedback | All | Closed Since Version 1.2.7

Bug #16033 PDF attachments not getting through
Submitted: 2009-03-13 18:50 UTC
From: kguest Assigned: till
Status: Bogus Package: Mail_Queue (version 1.2.2)
PHP Version: 5.2.5 OS: Ubuntu 8.10
Roadmaps: (Not assigned)    
Subscription  


 [2009-03-13 18:50 UTC] kguest (Ken Guest)
Description: ------------ Emails stored with PDF attachments are not received properly. gifs and jpegs are. Attached gifs & jpegs are received and displayed fine by the email client - but no indication of PDF being included in the email received. This is using the same schema as given in the tutorial - but changing the body field to a blob. Test PDF is approx 591K in size. I amended the code to not use Mail_Queue but the Mail package instead to determine where the problem lies - and those tests worked fine with the result of attached PDFs being received without error. Test code is as below. A 'cleansed' version of the debug output (simple search & replaces to protect the innocent re host & address details), from the conversation with the mail server, is as follows: DEBUG: Recv: 220 mail.example.com ESMTP Postfix (Debian/GNU) DEBUG: Send: EHLO localhost DEBUG: Recv: 250-mail.example.com DEBUG: Recv: 250-PIPELINING DEBUG: Recv: 250-SIZE 10240000 DEBUG: Recv: 250-VRFY DEBUG: Recv: 250-ETRN DEBUG: Recv: 250-STARTTLS DEBUG: Recv: 250-ENHANCEDSTATUSCODES DEBUG: Recv: 250-8BITMIME DEBUG: Recv: 250 DSN DEBUG: Send: MAIL FROM:<joe@example.com> DEBUG: Recv: 250 2.1.0 Ok DEBUG: Send: RCPT TO:<joe@example.com> DEBUG: Recv: 250 2.1.5 Ok DEBUG: Send: DATA DEBUG: Recv: 354 End data with <CR><LF>.<CR><LF> DEBUG: Send: MIME-Version: 1.0 From: joe@example.com To: joe@example.com Subject: test subject Content-Type: multipart/mixed; boundary="=_317984f24d0a675ae6b7bc4fb850008f" . DEBUG: Recv: 250 2.0.0 Ok: queued as 9913633C30B DEBUG: Send: QUIT DEBUG: Recv: 221 2.0.0 Bye Test script: --------------- in insert.php: include 'Mail/Queue/Container/mdb2.php'; include 'Mail/Queue/Container.php'; include 'Mail/Queue.php'; define('DB_HOST', 'localhost'); define('DB_NAME', 'testdb'); define('DB_PASS', ''); define('DB_USER', 'root'); $db_options['dsn'] = 'mysqli://'.DB_USER.':'.DB_PASS.'@'.DB_HOST.'/'.DB_NAME; $db_options['mail_table'] = 'mail_queue'; $db_options['type'] = 'mdb2'; $mail_options['driver'] = 'smtp'; $mail_options['host'] = 'mail.example.com'; $mail_options['port'] = 25; $mail_options['localhost'] = 'localhost'; $mail_options['auth'] = false; $mail_options['debug'] = false; $mail_queue =& new Mail_Queue($db_options, $mail_options); $file= '/home/ken/Desktop/PHPWhitePaper.pdf'; $mimetype = mime_content_type($file); $from = 'joe@example.com'; $to = "joe@example.com"; $message = "Hi! This is test message!! :)\n{$mimetype}"; $hdrs = array( 'From' => $from, 'To' => $to, 'Subject' => "test subject" ); /* we use Mail_mime() to construct a valid mail */ $mime = new Mail_mime(); $mime->setTXTBody($message); $mime->setHTMLBody("<html><body><b>$message</b></body></html>"); $mime->addAttachment($file, $mimetype); $body = $mime->get(); $hdrs = $mime->headers($hdrs); /* Put message to queue */ $mail_queue->put($from, $to, $hdrs, $body); in flush.php: include 'Mail/Queue.php'; include 'Mail/Queue/Container.php'; include 'Mail/Queue/Container/mdb2.php'; define('DB_HOST', 'localhost'); define('DB_USER', 'root'); define('DB_PASS', ''); define('DB_NAME', 'testdb'); $db_options['type'] = 'mdb2'; $db_options['dsn'] = 'mysqli://'.DB_USER.':'.DB_PASS.'@'.DB_HOST.'/'.DB_NAME; $db_options['mail_table'] = 'mail_queue'; $mail_options['driver'] = 'smtp'; $mail_options['host'] = 'mail.example.com'; $mail_options['port'] = 25; $mail_options['localhost'] = 'localhost'; //optional Mail_smtp parameter $mail_options['auth'] = false; $mail_options['debug'] = true; /* How many mails could we send each time the script is called */ $max_amount_mails = 50; /* we use the db_options and mail_options from the config again */ $mail_queue =& new Mail_Queue($db_options, $mail_options, 0 , false); /* really sending the messages */ $dn = $mail_queue->sendMailsInQueue($max_amount_mails); if (!$dn === true) { var_dump($dn); } Expected result: ---------------- Email to which PDF is attached should be received with the attachment intact. Actual result: -------------- Viewing source of the email shows no reference to intended attachment.

Comments

 [2009-03-20 19:35 UTC] till (Till Klampaeckel)
-Status: Open +Status: Feedback
Dear Ken, :D can you verify that the content-type returned for the PDF is correct? Also, just to double-check -- did attaching PDFs work with PEAR::Mail on your system? Best regards, Till
 [2009-03-20 20:30 UTC] kguest (Ken Guest)
Dear Till, The mimetype determined for the PDF was determined to be "application/pdf" and I can confirm the equivalent mails sent with PDF attachments via PEAR::Mail did work perfectly fine. They were retrieved by both Thunderbird and Evolution email clients and those attachments were saved to the local filesystem and displayed without a glitch. x Ken
 [2009-03-31 21:09 UTC] kguest (Ken Guest)
I eventually traced this to a "Notice: unserialize(): Error at offset 2 of 65535 bytes in /usr/share/php/Mail/Queue/Container/mdb2.php on line 191" message. The blob datatype I had set for the body field was not big enough - I needed to change it to longblob: mysql> alter table mail_queue change body body longblob; hazarding a guess; the mime encoding of the file plus ancillary data pushed the size over the limits of the blob datatype. So, remember folks, always make sure the fields in your database are [more than] large enough for the data going in. d'oh!
 [2009-03-31 22:41 UTC] till (Till Klampaeckel)
-Status: Feedback +Status: Bogus -Assigned To: +Assigned To: till
Thanks for the heads up!