public function MandrillMail::getAttachmentStruct in Mandrill 8
Return an array structure for a message attachment.
Parameters
string $path: Attachment path.
Return value
array Attachment structure.
Throws
\Exception
1 call to MandrillMail::getAttachmentStruct()
- MandrillMail::mail in src/
Plugin/ Mail/ MandrillMail.php - Send the email message.
File
- src/
Plugin/ Mail/ MandrillMail.php, line 269
Class
- MandrillMail
- Modify the Drupal mail system to use Mandrill when sending emails.
Namespace
Drupal\mandrill\Plugin\MailCode
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 = $this->mimeTypeGuesser
->guess($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;
}