function MailBuilder::buildNewsletterMail in Simplenews 8
Same name and namespace in other branches
- 8.2 src/Mail/MailBuilder.php \Drupal\simplenews\Mail\MailBuilder::buildNewsletterMail()
- 3.x src/Mail/MailBuilder.php \Drupal\simplenews\Mail\MailBuilder::buildNewsletterMail()
Build subject and body of the test and normal newsletter email.
Parameters
array $message: Message array as used by hook_mail().
\Drupal\simplenews\Mail\MailInterface $mail: The mail object.
Overrides MailBuilderInterface::buildNewsletterMail
File
- src/
Mail/ MailBuilder.php, line 49
Class
- MailBuilder
- Default mail builder.
Namespace
Drupal\simplenews\MailCode
function buildNewsletterMail(array &$message, MailInterface $mail) {
// Get message data from the mail.
$message['headers'] = $mail
->getHeaders($message['headers']);
$message['subject'] = $mail
->getSubject();
$message['body']['body'] = $mail
->getBody();
if ($mail
->getFormat() == 'html') {
// Set the necessary headers to detect this as an HTML mail. Set both the
// Content-Type header, and the format (Swiftmailer) and plain (Mime Mail)
// params.
$message['headers']['Content-Type'] = 'text/html; charset=UTF-8';
$message['params']['format'] = 'text/html';
$message['params']['plain'] = NULL;
// Provide a plain text version, both in params][plaintext (Mime Mail) and
// plain (Swiftmailer).
$message['params']['plaintext'] = $mail
->getPlainBody();
$message['plain'] = $message['params']['plaintext'];
// Add attachments, again, both for the attachments key (Mime Mail) and
// files (Swiftmailer).
$message['params']['attachments'] = $mail
->getAttachments();
$message['params']['files'] = $message['params']['attachments'];
}
else {
// This is a plain text email, explicitly mark it as such, the default
// Content-Type header already defaults to that.
$message['params']['plain'] = TRUE;
$message['params']['format'] = 'text/plain';
}
}