public function PostmarkMail::mail in Postmark 8
Send the e-mail message.
Parameters
array $message: A message array, as described in hook_mail_alter(). $message['params'] may contain additional parameters.
Return value
bool TRUE if the mail was successfully accepted or queued, FALSE otherwise.
Overrides MailInterface::mail
See also
drupal_mail()
File
- src/
Plugin/ Mail/ PostmarkMail.php, line 109
Class
- PostmarkMail
- Modify the Drupal mail system to use Postmark when sending emails.
Namespace
Drupal\postmark\Plugin\MailCode
public function mail(array $message) {
// Build the Postmark message array.
$postmark_message = [
'from' => $message['from'],
'to' => $message['to'],
'subject' => $message['subject'],
'html' => $message['body'],
];
if (isset($message['plain'])) {
$postmark_message['text'] = $message['plain'];
}
else {
$converter = new Html2Text($message['body']);
$postmark_message['text'] = $converter
->getText();
}
// Add Cc / Bcc headers.
if (!empty($message['headers']['Cc'])) {
$postmark_message['cc'] = $message['headers']['Cc'];
}
if (!empty($message['headers']['Bcc'])) {
$postmark_message['bcc'] = $message['headers']['Bcc'];
}
// Add Reply-To as header according to Postmark API.
if (!empty($message['reply-to'])) {
$postmark_message['reply-to'] = $message['reply-to'];
}
// Make sure the files provided in the attachments array exist.
if (!empty($message['params']['attachments'])) {
$attachments = [];
foreach ($message['params']['attachments'] as $attachment) {
if (file_exists($attachment)) {
$attachments[] = [
'filePath' => $attachment,
];
}
}
if (count($attachments) > 0) {
$postmark_message['attachment'] = $attachments;
}
}
return $this->postmarkHandler
->sendMail($postmark_message);
}