static function getAttachmentStruct($path) { $struct = array(); try { if (!@is_file($path)) { throw new Exception($path . ' is not a valid file.'); } $filename = basename($path); if (!function_exists('get_magic_quotes')) { function get_magic_quotes() { return false; } } if (!function_exists('set_magic_quotes')) { function set_magic_quotes($value) { return true; } } if (strnatcmp(phpversion(), '6') >= 0) { $magic_quotes = get_magic_quotes_runtime(); set_magic_quotes_runtime(0); } $file_buffer = file_get_contents($path); $file_buffer = chunk_split(base64_encode($file_buffer), 76, "\n"); if (strnatcmp(phpversion(), '6') >= 0) { set_magic_quotes_runtime($magic_quotes); } if (strnatcmp(phpversion(), '5.3') >= 0) { $finfo = finfo_open(FILEINFO_MIME_TYPE); $mime_type = finfo_file($finfo, $path); } else { $mime_type = mime_content_type($path); } if (!Mandrill::isValidContentType($mime_type)) { throw new Exception($mime_type . ' is not a valid content type (it should be ' . implode('*,', self::getValidContentTypes()) . ').'); } $struct['type'] = $mime_type; $struct['name'] = $filename; $struct['content'] = $file_buffer; } catch (Exception $e) { throw new Mandrill_Exception('Error creating the attachment structure: ' . $e->getMessage()); } return $struct; }