You are here

public function MailEntity::getHeaders in Simplenews 3.x

Same name and namespace in other branches
  1. 8.2 src/Mail/MailEntity.php \Drupal\simplenews\Mail\MailEntity::getHeaders()
  2. 8 src/Mail/MailEntity.php \Drupal\simplenews\Mail\MailEntity::getHeaders()

Returns the mail headers.

Parameters

array $headers: The default mail headers.

Return value

array Mail headers as an array.

Overrides MailInterface::getHeaders

File

src/Mail/MailEntity.php, line 94

Class

MailEntity
Default mail class for entities.

Namespace

Drupal\simplenews\Mail

Code

public function getHeaders(array $headers) {

  // If receipt is requested, add headers.
  if ($this->newsletter->receipt) {
    $headers['Disposition-Notification-To'] = $this
      ->getFromAddress();
    $headers['X-Confirm-Reading-To'] = $this
      ->getFromAddress();
  }

  // Add priority if set.
  switch ($this->newsletter->priority) {
    case SIMPLENEWS_PRIORITY_HIGHEST:
      $headers['Priority'] = 'High';
      $headers['X-Priority'] = '1';
      $headers['X-MSMail-Priority'] = 'Highest';
      break;
    case SIMPLENEWS_PRIORITY_HIGH:
      $headers['Priority'] = 'urgent';
      $headers['X-Priority'] = '2';
      $headers['X-MSMail-Priority'] = 'High';
      break;
    case SIMPLENEWS_PRIORITY_NORMAL:
      $headers['Priority'] = 'normal';
      $headers['X-Priority'] = '3';
      $headers['X-MSMail-Priority'] = 'Normal';
      break;
    case SIMPLENEWS_PRIORITY_LOW:
      $headers['Priority'] = 'non-urgent';
      $headers['X-Priority'] = '4';
      $headers['X-MSMail-Priority'] = 'Low';
      break;
    case SIMPLENEWS_PRIORITY_LOWEST:
      $headers['Priority'] = 'non-urgent';
      $headers['X-Priority'] = '5';
      $headers['X-MSMail-Priority'] = 'Lowest';
      break;
  }

  // Add user specific header data.
  $headers['From'] = $this
    ->getFromFormatted();
  $headers['List-Unsubscribe'] = '<' . \Drupal::token()
    ->replace('[simplenews-subscriber:unsubscribe-url]', $this
    ->getTokenContext()) . '>';

  // Add general headers.
  $headers['Precedence'] = 'bulk';
  return $headers;
}