You are here

public function MandrillMailSystem::getAttachmentStruct in Mandrill 7.2

Return an array structure for a message attachment.

Parameters

string $path: Attachment path.

Return value

array Attachment structure.

Throws

Exception

1 call to MandrillMailSystem::getAttachmentStruct()
MandrillMailSystem::mail in lib/mandrill.mail.inc
Send the email message.

File

lib/mandrill.mail.inc, line 243
Implements Mandrill as a Drupal MailSystemInterface

Class

MandrillMailSystem
Modify the drupal mail system to use Mandrill when sending emails.

Code

public function getAttachmentStruct($path) {
  $struct = array();
  if (!@is_file($path)) {
    throw new Exception($path . ' is not a valid file.');
  }
  $filename = basename($path);
  $file_buffer = file_get_contents($path);
  $file_buffer = chunk_split(base64_encode($file_buffer), 76, "\n");
  $mime_type = file_get_mimetype($path);
  if (!$this
    ->isValidContentType($mime_type)) {
    throw new Exception($mime_type . ' is not a valid content type.');
  }
  $struct['type'] = $mime_type;
  $struct['name'] = $filename;
  $struct['content'] = $file_buffer;
  return $struct;
}