You are here

class HTMLTestingMailSystem in Simplenews 8

Same name and namespace in other branches
  1. 8.2 src/Plugin/Mail/HTMLTestingMailSystem.php \Drupal\simplenews\Plugin\Mail\HTMLTestingMailSystem
  2. 3.x src/Plugin/Mail/HTMLTestingMailSystem.php \Drupal\simplenews\Plugin\Mail\HTMLTestingMailSystem

A mail sending implementation that captures sent messages to a variable.

This class is for running tests or for development and does not convert HTML to plaintext.

Plugin annotation


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

Hierarchy

Expanded class hierarchy of HTMLTestingMailSystem

File

src/Plugin/Mail/HTMLTestingMailSystem.php, line 20

Namespace

Drupal\simplenews\Plugin\Mail
View source
class HTMLTestingMailSystem implements MailInterface {

  /**
   * Implements MailSystemInterface::format().
   */
  public function format(array $message) {

    // Join the body array into one string.
    $message['body'] = implode("\n\n", $message['body']);

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

  /**
   * Implements MailSystemInterface::mail().
   */
  public function mail(array $message) {
    $captured_emails = \Drupal::state()
      ->get('system.test_mail_collector') ?: array();
    $captured_emails[] = $message;
    \Drupal::state()
      ->set('system.test_mail_collector', $captured_emails);
    return TRUE;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
HTMLTestingMailSystem::format public function Implements MailSystemInterface::format(). Overrides MailInterface::format
HTMLTestingMailSystem::mail public function Implements MailSystemInterface::mail(). Overrides MailInterface::mail