TestMailCollector.php

Same filename in other branches
  1. 9 core/lib/Drupal/Core/Mail/Plugin/Mail/TestMailCollector.php
  2. 8.9.x core/lib/Drupal/Core/Mail/Plugin/Mail/TestMailCollector.php
  3. 10 core/lib/Drupal/Core/Mail/Plugin/Mail/TestMailCollector.php

Namespace

Drupal\Core\Mail\Plugin\Mail

File

core/lib/Drupal/Core/Mail/Plugin/Mail/TestMailCollector.php

View source
<?php

namespace Drupal\Core\Mail\Plugin\Mail;

use Drupal\Core\Mail\Attribute\Mail;
use Drupal\Core\Mail\MailInterface;
use Drupal\Core\StringTranslation\TranslatableMarkup;

/**
 * Defines a mail backend that captures sent messages in the state system.
 *
 * This class is for running tests or for development.
 */
class TestMailCollector extends PhpMail implements MailInterface {
    
    /**
     * {@inheritdoc}
     */
    public function mail(array $message) {
        $captured_emails = \Drupal::state()->get('system.test_mail_collector', []);
        $captured_emails[] = $message;
        \Drupal::state()->set('system.test_mail_collector', $captured_emails);
        return TRUE;
    }

}

Classes

Title Deprecated Summary
TestMailCollector Defines a mail backend that captures sent messages in the state system.

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.