php imap_append script not working

mistub mistub at gmx.net
Thu Oct 17 16:13:39 CEST 2013


Hi all

wanted to send an contact directly to imap via php but got the following 
error (sending without attachment works):

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

For other Cyrus-Imap-Servers the script works. Here's the script (thx to 
http://php.net/manual/en/function.imap-append.php )

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

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

if ($mbox=imap_open( $authhost, $user, $pass))
{
     $dmy=date("d-M-Y H:i:s");
     $file="./kolab.xml";
     $filename="kolab.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: kolab-28hjwer0923409wuer09w34\r\n"
         . "MIME-Version: 1.0\r\n"
         . "Content-Type: multipart/mixed; boundary=\"$boundary\"\r\n"
         . "X-Kolab-Type: application/x-vnd.kolab.contact\r\n"
         . "X-Kolab-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 Kolab Groupware 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";
}

?>

Two questions:
Not sure whether appending a contact in this way works as I expected.
What about the php-error?

Thx Michael


More information about the users mailing list