You are here

function MailBuilder::buildSubscribeMail in Simplenews 8

Same name and namespace in other branches
  1. 8.2 src/Mail/MailBuilder.php \Drupal\simplenews\Mail\MailBuilder::buildSubscribeMail()

Build subject and body of the subscribe confirmation email.

Parameters

array $message: Message array as used by hook_mail().

array $params: Parameter array as used by hook_mail().

Overrides MailBuilderInterface::buildSubscribeMail

File

src/Mail/MailBuilder.php, line 85

Class

MailBuilder
Default mail builder.

Namespace

Drupal\simplenews\Mail

Code

function buildSubscribeMail(array &$message, array $params) {
  $context = $params['context'];

  // Use formatted from address "name" <mail_address>
  $message['headers']['From'] = $params['from']['formatted'];
  $message['subject'] = $this->config
    ->get('subscription.confirm_subscribe_subject');
  $message['subject'] = $this->token
    ->replace($message['subject'], $context, array(
    'sanitize' => FALSE,
  ));
  if ($context['simplenews_subscriber']
    ->isSubscribed($context['newsletter']
    ->id())) {
    $body = $this->config
      ->get('subscription.confirm_subscribe_subscribed');
  }
  else {
    $body = $this->config
      ->get('subscription.confirm_subscribe_unsubscribed');
  }
  $message['body'][] = $this->token
    ->replace($body, $context, array(
    'sanitize' => FALSE,
  ));
}