php imap_append script not working

mistub mistub at gmx.net
Thu Oct 17 16:50:59 EDT 2013


Hi all

wanted to append an attachment directly to imap⁻mailbox via php but got 
the following error (sending the upper part without attachment works):

PHP Notice:  Unknown: Message contains bare newlines (errflg=2) in 
Unknown on line 0

For courier-imap-Server the script works with attachment. Here's the 
script (thx to http://php.net/manual/en/function.imap-append.php )

<?php
$authhost="{mail.example.org:143/novalidate-cert}INBOX";

$user="foo";
$pass="bar";

if ($mbox=imap_open( $authhost, $user, $pass))
{
     $dmy=date("d-M-Y H:i:s");
     $file="./example.xml";
     $filename="example.xml";
     $ouv=fopen ("$file", "rb");$attachment=fread ($ouv, filesize 
("$file"));fclose
     ($ouv);

     $boundary = "------=".md5(uniqid(rand()));

     $msg = ("From: foo at example.org\r\n"
         . "To: foo at example.org\r\n"
         . "Date: $dmy\r\n"
         . "Subject: app-28hjwer0923409wuer09w34\r\n"
         . "MIME-Version: 1.0\r\n"
         . "Content-Type: multipart/mixed; boundary=\"$boundary\"\r\n"
         . "X-App-Type: application/x-vnd.app.contact\r\n"
         . "X-App-Mime-Version: 3\r\n"
         . "\r\n\r\n"
         . "--$boundary\r\n"
         . "Content-Type: text/html;\r\n\tcharset=\"ISO-8859-1\"\r\n"
         . "Content-Transfer-Encoding: 8bit \r\n"
         . "\r\n\r\n"
         . "This is a App object.\r\n"
         . "\r\n\r\n"
         . "--$boundary\r\n"
         . "Content-Transfer-Encoding: 8bit\r\n"
         . "Content-Type: application/vcard+xml; charset=UTF-8; 
name=\"$filename\"\r\n"
         . "Content-Disposition: attachment; filename=\"$filename\";\r\n"
         . "\r\n" . $attachment . "\r\n"
         . "\r\n\r\n\r\n"
         . "--$boundary--\r\n\r\n");

     imap_append($mbox,$authhost,$msg);

     imap_close($mbox);
}
else
{
     echo "<h1>FAIL!</h1>\n";
}

?>

I already played around with the CRLF's but no luck. Can anybody tell me 
about the error?

Thx Michael


More information about the Info-cyrus mailing list