You are here

public function SparkpostMailSystem::getAttachmentStruct in Sparkpost email 7.2

Same name and namespace in other branches
  1. 7 includes/sparkpost.mail.inc \SparkpostMailSystem::getAttachmentStruct()

Return an array structure for a message attachment.

Parameters

string $path: Attachment path.

Return value

array Attachment structure.

Throws

Exception

1 call to SparkpostMailSystem::getAttachmentStruct()
SparkpostMailSystem::mail in includes/sparkpost.mail.inc
Send the email message.

File

includes/sparkpost.mail.inc, line 177
Implements Sparkpost as a Drupal MailSystemInterface

Class

SparkpostMailSystem
Modify the drupal mail system to use Sparkpost 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['data'] = $file_buffer;
  return $struct;
}