Add file attachment to the message

I'm trying to add attachment to email order copy but no success (i'm getting ""noname.txt"" as attachment).

My code (file: includes/controllers/ctrl_order.inc.php):

public function email_order_copy($email) {

if (empty($email)) return;

functions::email_send(
        null,
        $email,
        language::translate('title_order_copy', 'Order Copy') .' #'. $this->data['id'],
        self::draw_printable_copy(),
        true,

    $attachments = array(
    FS_DIR_HTTP_ROOT.'/first.pdf',
    FS_DIR_HTTP_ROOT.'/second.pdf'
    )

    );
}

What is wrong with this code?

functions::email_send(
null,
$email,
language::translate('title_order_copy', 'Order Copy') .' #'. $this->data['id'],
self::draw_printable_copy(),
true,
array(
FS_DIR_HTTP_ROOT . WS_DIR_HTTP_HOME .'first.pdf',
FS_DIR_HTTP_ROOT . WS_DIR_HTTP_HOME .'second.pdf'
)

);

Still doesn't work :/ I checked it with various types of files (pdf, txt, zip).

I think links are ok:
/home/atp/domains/domain.com/public_html/first.pdf

Try debugging func_email.inc.php and see what is generated by:

// Are there are attachments?
    if (!empty($attachments)) {

      foreach ($attachments as $file) {
        $file = fopen($file, 'rb');
        $data = fread($file, filesize($file));
        fclose($file);

      // Add file attachment to the message
        $message .= '--'. $mime_boundary . ""\r\n""
                 . 'Content-Type: '. @mime_content_type($file) .'; name=""'. basename($file) .'""' . ""\r\n""
                 . 'Content-Disposition: attachment; filename=""'. basename($file) . '""' . ""\r\n""
                 . 'Content-Transfer-Encoding: base64' . ""\r\n\r\n""
                 . chunk_split(base64_encode($data)) . ""\r\n\r\n""
                 . '--'. $mime_boundary .'--' . ""\r\n"";
      }
    }

There is a bug in this function - fread() need resource id and filesize() need path to file. My code looks like this now:

// Are there are attachments?
    if (!empty($attachments)) {

      foreach ($attachments as $file) {
        $file_data = fopen($file, 'rb');
        $data = fread($file_data, filesize($file));
        fclose($file_data);
(...)

...but still i have a problem - only first file from array is attached to mail :/

How about this instead:

foreach ($attachments as $file) {
        $data = file_get_contents($file);

        $message .= '--'. $mime_boundary. ""\r\n""
                 . 'Content-Type: application/octet-stream; name=""'. basename($file) .'""' . ""\r\n""
                 . 'Content-Disposition: attachment; filename=""'. basename($file) . '""' . ""\r\n""
                 . 'Content-Transfer-Encoding: base64' . ""\r\n\r\n""
                 . chunk_split(base64_encode($data)) . ""\r\n\r\n"";
      }

Will be updated in the next release.

This thread has been closed due to long inactivity. Posting to it is not possible.
View code on GitHub