php imap save massage to sent folder after sending

Posted by user1108279 on Stack Overflow See other posts from Stack Overflow or by user1108279
Published on 2012-06-18T15:12:28Z Indexed on 2012/06/18 15:15 UTC
Read the original article Hit count: 250

Filed under:
|

I am stucked with this for two days. I am trying to use imap_append from PHP but no luck so far. I was able to to implement this code for single attachment but multiple attachments not working.

<?php 
$authhost="{000.000.000.000:993/validate-cert/ssl}Sent"; 

$user="sadasd"; 
$pass="sadasd"; 

if ($mbox=imap_open( $authhost, $user, $pass)) 
{ 
    $dmy=date("d-M-Y H:i:s"); 

    $filename="filename.pdf"; 
    $attachment = chunk_split(base64_encode($filestring)); 

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

    $msg = ("From: Somebody\r\n" 
        . "To: [email protected]\r\n" 
        . "Date: $dmy\r\n" 
        . "Subject: This is the subject\r\n" 
        . "MIME-Version: 1.0\r\n" 
        . "Content-Type: multipart/mixed; boundary=\"$boundary\"\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" 
        . "Hello this is a test\r\n" 
        . "\r\n\r\n" 
        . "--$boundary\r\n" 
        . "Content-Transfer-Encoding: base64\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"; 
} 

?> 

Now that raw code above is working but I am unable to add multiple attachments. In some cases I got message body base64 decoded and in message body lot of strange letters. Something like

R0lGODlhkAEfAOYAAPSeZPONtdSIu+u2vv/La+5Rj8AhYPvWhOjtkfvi7MRImcjYse5DM6O+dOnl .....

I search all the web i still got no luck.

Since I have dedicated server I also tried to implement some procmail+ postfix examples but also no luck.

Can someone help?

© Stack Overflow or respective owner

Related posts about php

Related posts about imap