insanebear Developer Od Poland Člen od okt 2014 insanebear 27 dec 2014 13:31 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?
litecart Main Crew Od Sweden Člen od feb 2013 litecart 27 dec 2014 13:36 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' ) );
insanebear Developer Od Poland Člen od okt 2014 insanebear 27 dec 2014 14:02 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
litecart Main Crew Od Sweden Člen od feb 2013 litecart 27 dec 2014 14:15 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""; } }
insanebear Developer Od Poland Člen od okt 2014 insanebear 27 dec 2014 15:35 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 :/
litecart Main Crew Od Sweden Člen od feb 2013 litecart 1 jan 2015 16:08 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""; }
litecart Main Crew Od Sweden Člen od feb 2013 litecart 3 jan 2015 22:07 Will be updated in the next release.