public function SendGridMail::getAttachmentStruct in SendGrid Integration 8.2
Return an array structure for a message attachment.
Parameters
string $path: Attachment path.
Return value
array Attachment structure.
Throws
\Exception
1 call to SendGridMail::getAttachmentStruct()
- SendGridMail::mail in src/
Plugin/ Mail/ SendGridMail.php
File
- src/
Plugin/ Mail/ SendGridMail.php, line 761 - Implements Drupal MailSystemInterface.
Class
- SendGridMail
- @file Implements Drupal MailSystemInterface.
Namespace
Drupal\sendgrid_integration\Plugin\MailCode
public function getAttachmentStruct(string $path) : array {
$struct = [];
if (!@is_file($path)) {
throw new \Exception($path . ' is not a valid file.');
}
$filename = basename($path);
$file_content = base64_encode(file_get_contents($path));
$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['filename'] = $filename;
$struct['content'] = $file_content;
return $struct;
}