You are here

public function WebformPhpMail::format in Webform 8.5

Same name and namespace in other branches
  1. 6.x src/Plugin/Mail/WebformPhpMail.php \Drupal\webform\Plugin\Mail\WebformPhpMail::format()

Concatenates and wraps the email body for plain-text mails.

Parameters

array $message: A message array, as described in hook_mail_alter().

Return value

array The formatted $message.

Overrides PhpMail::format

File

src/Plugin/Mail/WebformPhpMail.php, line 22

Class

WebformPhpMail
Extend's the default Drupal mail backend to support HTML email.

Namespace

Drupal\webform\Plugin\Mail

Code

public function format(array $message) {

  // Join the body array into one string.
  $message['body'] = implode("\n\n", $message['body']);
  if (!empty($message['params']['html'])) {

    // Wrap body in HTML template if the <html> tag is missing.
    if (strpos($message['body'], '<html') === FALSE) {

      // Make sure parameters exist.
      $message['params'] += [
        'webform_submission' => NULL,
        'handler' => NULL,
      ];
      $build = [
        '#theme' => 'webform_email_html',
        '#body' => $message['body'],
        '#subject' => $message['subject'],
        '#webform_submission' => $message['params']['webform_submission'],
        '#handler' => $message['params']['handler'],
      ];
      $message['body'] = \Drupal::service('renderer')
        ->renderPlain($build);
    }
    return $message;
  }
  else {

    // Wrap the mail body for sending.
    $message['body'] = MailFormatHelper::wrapMail($message['body']);
    return $message;
  }
}