/** * Add attachment to send with an email. * * Sample Code: * $attachment = $mailHelper->addAttachment($fileObject); * $attachment->filename = "CustomFilename"; * $mailHelper->send(); * * @param File $fob File to attach * @return StdClass Pointer to the attachment */ public function addAttachment(\Concrete\Core\File\File $fob) { // @TODO make this work with the File Storage Locations $fv = $fob->getVersion(); $path = $fob->getPath(); $name = $fv->getFileName(); $type = false; if (!function_exists('mime_content_type')) { function mime_content_type($path) { return false; } } $type = @mime_content_type($path); // This is deprecated. Should be stable until php5.6 if (!$type) { $mt = Loader::helper('mime'); $ext = preg_replace('/^.+\\.([^\\.]+)$/', '\\1', $path); $type = $mt->mimeFromExtension($ext); } $contents = @file_get_contents($path); if (!$contents) { throw new Exception(t('Unable to get the file contents for attachment.')); } $file = new StdClass(); $file->object = $fob; $file->type = $type; $file->path = $path; $file->filename = $name; $file->contents = $contents; unset($contents); $this->attachments[] = $file; return $file; // Returns a pointer }