2012-06-18 49 views
0

我被这两天扼杀。我试图从PHP使用imap_append,但目前还没有运气。我能够为单个附件实现此代码,但多个附件无法正常工作。php imap发送后保存按摩到发送文件夹

<?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"; 
} 

?> 

既然上面的原始代码正在工作,但我无法添加多个附件。在某些情况下,我得到了消息体base64解码,并在消息体中出现了很多奇怪的字母。像

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

我搜索所有的网络,我仍然没有运气。

由于我有专用的服务器,我也尝试实施一些procmail + postfix的例子,但也没有运气。

有人可以帮忙吗?

回答

1

摆脱的 - 从你的边界线

. "--$boundary--\r\n\r\n" 

应该

. "$boundary\r\n\r\n" 

你不需要的 - 在你的头。

+0

最后,两天后。谢谢。那些愚蠢的标题是一切的问题!我正在$ mail-> body后面调用$ mail-> headers。多么愚蠢!!!!!! – pregmatch

+0

大声笑,很高兴你得到它的工作。 – SuperMykEl

+0

如果这个答案对你有帮助,你能接受吗? – SuperMykEl

相关问题