note 105303 modified in function.imap-append by danbrown

From: Date: Mon, 08 Aug 2011 16:35:20 +0000
Subject: note 105303 modified in function.imap-append by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-182335@lists.php.net to get a copy of this message
I encountered 3 problems when attempting to get my server to copy messages to the sent folder. 1. Wouldn't login until I added /novalidate-cert 2. No code example of getting the date sent 3. Including an attachment Hope this code helps others <?php $dmy=date("d-M-Y H:i:s"); $dmy.= " +0100"; // Had to do this bit manually as server and me are in different timezones $stream=@imap_open("{mail.example.com/novalidate-cert}INBOX.Sent", "username", "password"); $boundary = "------=".md5(uniqid(rand())); $header = "MIME-Version: 1.0\r\n"; $header .= "Content-Type: multipart/mixed; boundary=\"$boundary\"\r\n"; $header .= "\r\n"; $file="../path_to/filename.pdf"; $filename="filename.pdf"; $ouv=fopen ("$file", "rb");$lir=fread ($ouv, filesize ("$file"));fclose ($ouv); $attachment = chunk_split(base64_encode($lir)); $msg2 .= "--$boundary\r\n"; $msg2 .= "Content-Transfer-Encoding: base64\r\n"; $msg2 .= "Content-Disposition: attachment; filename=\"$filename\"\r\n"; $msg2 .= "\r\n"; $msg2 .= $attachment . "\r\n"; $msg2 .= "\r\n\r\n"; $msg3 .= "--$boundary--\r\n"; imap_append($stream,"{mail.example.com/novalidate-cert}INBOX.Sent","From: Somebody\r\n"."To: test@example.co.uk\r\n"."Date: $dmy\r\n"."Subject: This is the subject\r\n"."$header\r\n"."$msg2\r\n"."$msg3\r\n"); imap_close ($stream); ?> --was-- I encountered 3 problems when attempting to get my server to copy messages to the sent folder. 1. Wouldn't login until I added /novalidate-cert 2. No code example of getting the date sent 3. Including an attachment Hope this code helps others <? $dmy=date("d-M-Y H:i:s"); $dmy.= " +0100"; // Had to do this bit manually as server and me are in different timezones $stream=@imap_open("{mailserver.co.uk/novalidate-cert}INBOX.Sent", "username", "password"); $boundary = "------=".md5(uniqid(rand())); $header = "MIME-Version: 1.0\r\n"; $header .= "Content-Type: multipart/mixed; boundary=\"$boundary\"\r\n"; $header .= "\r\n"; $file="../path_to/filename.pdf"; $filename="filename.pdf"; $ouv=fopen ("$file", "rb");$lir=fread ($ouv, filesize ("$file"));fclose ($ouv); $attachment = chunk_split(base64_encode($lir)); $msg2 .= "--$boundary\r\n"; $msg2 .= "Content-Transfer-Encoding: base64\r\n"; $msg2 .= "Content-Disposition: attachment; filename=\"$filename\"\r\n"; $msg2 .= "\r\n"; $msg2 .= $attachment . "\r\n"; $msg2 .= "\r\n\r\n"; $msg3 .= "--$boundary--\r\n"; imap_append($stream,"{mailserver.co.uk/novalidate-cert}INBOX.Sent","From: Somebody\r\n"."To: test@somewhere.co.uk\r\n"."Date: $dmy\r\n"."Subject: This is the subject\r\n"."$header\r\n"."$msg2\r\n"."$msg3\r\n"); imap_close ($stream); ?> http://php.net/manual/en/function.imap-append.php

« previous php.notes (#182335) next »