Final Class Yiisoft\Log\Target\Email\EmailTarget
| Inheritance | Yiisoft\ |
|---|
EmailTarget sends selected log messages to the specified email addresses.
{@see \
Public Methods
| Method | Description | Defined By |
|---|---|---|
| __construct() | Yiisoft\ |
Protected Methods
| Method | Description | Defined By |
|---|---|---|
| export() | Sends log messages to specified email addresses. | Yiisoft\ |
Method Details
| public mixed __construct ( \ | ||
| $mailer | \ |
The mailer instance. |
| $emailTo | string|string[] |
The receiver email address.
You may pass an array of addresses if multiple recipients should receive this message.
You may also specify receiver name in addition to email address using format: |
| $subjectEmail | string |
The email message subject. |
| $levels | string[] |
The {@see \ |
| throws | InvalidArgumentException |
If the "to" email message argument is invalid. |
|---|---|---|
public function __construct(
private readonly MailerInterface $mailer,
array|string $emailTo,
string $subjectEmail = '',
array $levels = [],
) {
if (empty($emailTo)) {
throw new InvalidArgumentException('The "to" argument must be an array or string and must not be empty.');
}
$this->emailTo = $emailTo;
$this->subjectEmail = $subjectEmail ?: 'Application Log';
parent::__construct($levels);
}
Sends log messages to specified email addresses.
| protected void export ( ) | ||
| throws | RuntimeException |
If the log cannot be exported. |
|---|---|---|
protected function export(): void
{
$message = new Message(
to: $this->emailTo,
subject: $this->subjectEmail,
textBody: wordwrap($this->formatMessages("\n" ), 70),
);
try {
$this->mailer->send($message);
} catch (Throwable $e) {
throw new RuntimeException('Unable to export log through email.', 0, $e);
}
}
User Contributed Notes
Leave a comment
Join the conversation to share a note.