You are here

class WebformPhpMail in Webform 6.x

Same name and namespace in other branches
  1. 8.5 src/Plugin/Mail/WebformPhpMail.php \Drupal\webform\Plugin\Mail\WebformPhpMail

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

Plugin annotation


@Mail(
  id = "webform_php_mail",
  label = @Translation("Webform PHP mailer"),
  description = @Translation("Sends the message as plain text or HTML, using PHP's native mail() function.")
)

Hierarchy

Expanded class hierarchy of WebformPhpMail

File

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

Namespace

Drupal\webform\Plugin\Mail
View source
class WebformPhpMail extends PhpMail {

  /**
   * {@inheritdoc}
   */
  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;
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
PhpMail::$configFactory protected property The configuration factory.
PhpMail::mail public function Sends an email message. Overrides MailInterface::mail 2
PhpMail::MAILBOX_LIST_HEADERS private constant A list of headers that can contain multiple email addresses.
PhpMail::_isShellSafe protected static function Disallows potentially unsafe shell characters.
PhpMail::__construct public function PhpMail constructor.
WebformPhpMail::format public function Concatenates and wraps the email body for plain-text mails. Overrides PhpMail::format