class TestMailCollector extends PhpMail implements MailInterface (View source)

Defines a mail backend that captures sent messages in the state system.

This class is for running tests or for development.

Constants

private MAILBOX_LIST_HEADERS

A list of headers that can contain multiple email addresses.

Properties

protected ConfigFactoryInterface $configFactory

The configuration factory.

from  PhpMail

Methods

__construct()

PhpMail constructor.

from  PhpMail
array
format(array $message)

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

from  PhpMail
bool
mail(array $message)

Sends an email message.

static bool
_isShellSafe(string $string)

Disallows potentially unsafe shell characters.

from  PhpMail

Details

__construct()

PhpMail constructor.

array format(array $message)

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.

bool mail(array $message)

Sends an email message.

Parameters

array $message

Message array with at least the following elements:

  • id: A unique identifier of the email type. Examples: 'contact_user_copy', 'user_password_reset'.
  • to: The mail address or addresses where the message will be sent to. The formatting of this string will be validated with the @link http://php.net/manual/filter.filters.validate.php PHP email validation filter. @endlink Some examples:
  • subject: Subject of the email to be sent. This must not contain any newline characters, or the mail may not be sent properly. The subject is converted to plain text by the mail plugin manager.
  • body: Message to be sent. Accepts both CRLF and LF line-endings. Email bodies must be wrapped. For smart plain text wrapping you can use \Drupal\Core\Mail\MailFormatHelper::wrapMail() .
  • headers: Associative array containing all additional mail headers not defined by one of the other parameters. PHP's mail() looks for Cc and Bcc headers and sends the mail to addresses in these headers too.

Return Value

bool

TRUE if the mail was successfully accepted for delivery, otherwise FALSE.

static protected bool _isShellSafe(string $string)

Disallows potentially unsafe shell characters.

Functionally similar to PHPMailer::isShellSafe() which resulted from CVE-2016-10045. Note that escapeshellarg and escapeshellcmd are inadequate for this purpose.

Rename to ::isShellSafe() and/or discuss whether this is the correct location for this helper.

Parameters

string $string

The string to be validated.

Return Value

bool

True if the string is shell-safe.

See also

https://github.com/PHPMailer/PHPMailer/issues/924
https://github.com/PHPMailer/PHPMailer/blob/v5.2.21/class.phpmailer.php#L1430