PHP:邮件多个附件标头

时间:2013-05-01 14:45:00

标签: php email header attachment

我正在尝试使用邮件中的多个附件发送电子邮件。到目前为止,我成功邮寄了一个附件,但我无法弄清楚如何在一封电子邮件中发送多个文件。

$uid = md5(uniqid(time()));
$bericht = $this -> _message;
$this -> _headers .= 'MIME-Version: 1.0' . PHP_EOL;
$this -> _headers .= 'Content-Type: multipart/mixed; boundary="'. $uid .'"' . PHP_EOL;
$this -> _message = '--' . $uid . PHP_EOL;
$this -> _message .= 'Content-Transfer-Encoding: 7bit' . PHP_EOL . PHP_EOL;
$this -> _message .= '--' . $uid . PHP_EOL;
$this -> _message .= 'Content-Type: text/html; charset="iso-8859-1' . PHP_EOL;
$this -> _message .= 'Content-Transfer-Encoding: 8bit' . PHP_EOL . PHP_EOL;
$this -> _message .= $bericht . PHP_EOL;
$this -> _message .= '--' . $uid . PHP_EOL;

foreach($attachments as $attachment) {
    if(is_file($attachment) && is_readable($attachment)) {
        $handle = fopen($attachment, 'r');
        $content = fread($handle, filesize($attachment));
        fclose($handle);
        $this -> _message .= 'Content-Type: text/plain; name="' .
                              basename($attachment) . '"' . PHP_EOL;
        $this -> _message .= 'Content-Transfer-Encoding: base64' . PHP_EOL;
        $this -> _message .= 'Content-Disposition: attachment' . PHP_EOL . PHP_EOL;
        $this -> _message .= chunk_split(base64_encode($content)) . PHP_EOL;
        $this -> _message .= '--' . $uid . '--' . PHP_EOL;
    }    
}

有人知道我做错了什么吗? :)

它确实只发送一个附件的邮件。如果我选择两个,那么只会发送一个。由于网站的规模,我不想使用图书馆。

0 个答案:

没有答案