CEmailLogRoute
CEmailLogRoute sends selected log messages to email addresses.
The target email addresses may be specified via
emails property. Optionally, you may set the email
subject, the
sentFrom address and any additional
headers.
Public Properties
Property |
Type |
Description |
Defined By |
categories | mixed | array of categories, or string list separated by comma or space. | CLogRoute |
emails | array | list of destination email addresses | CEmailLogRoute |
enabled | boolean | whether to enable this log route. | CLogRoute |
except | mixed | array of categories, or string list separated by comma or space, to EXCLUDE from logs. | CLogRoute |
filter | mixed | the additional filter (eg CLogFilter) that can be applied to the log messages. | CLogRoute |
levels | string | list of levels separated by comma or space. | CLogRoute |
logs | array | the logs that are collected so far by this log route. | CLogRoute |
sentFrom | string | send from address of the email | CEmailLogRoute |
subject | string | email subject. | CEmailLogRoute |
utf8 | boolean | set this property to true value in case log data you're going to send through emails contains non-latin or UTF-8 characters. | CEmailLogRoute |
Property Details
public array getEmails()
public void setEmails(mixed $value)
list of destination email addresses
public array getHeaders()
public void setHeaders(mixed $value)
additional headers to use when sending an email.
public string getSentFrom()
public void setSentFrom(string $value)
send from address of the email
public string getSubject()
public void setSubject(string $value)
email subject. Defaults to CEmailLogRoute::DEFAULT_SUBJECT
public boolean $utf8;
set this property to true value in case log data you're going to send through emails contains non-latin or UTF-8 characters. Emails would be UTF-8 encoded.
Method Details
public array getEmails() |
{return} | array | list of destination email addresses |
public array getHeaders() |
{return} | array | additional headers to use when sending an email. |
public string getSentFrom() |
{return} | string | send from address of the email |
public string getSubject() |
{return} | string | email subject. Defaults to CEmailLogRoute::DEFAULT_SUBJECT |
protected void processLogs(array $logs) |
$logs | array | list of log messages |
Source Code: framework/logging/CEmailLogRoute.php#56 (
show)
protected function processLogs($logs)
{
$message='';
foreach($logs as $log)
$message.=$this->formatLogMessage($log[0],$log[1],$log[2],$log[3]);
$message=wordwrap($message,70);
$subject=$this->getSubject();
if($subject===null)
$subject=Yii::t('yii','Application Log');
foreach($this->getEmails() as $email)
$this->sendEmail($email,$subject,$message);
}
Sends log messages to specified email addresses.
protected void sendEmail(string $email, string $subject, string $message) |
$email | string | single email address |
$subject | string | email subject |
$message | string | email content |
Source Code: framework/logging/CEmailLogRoute.php#75 (
show)
protected function sendEmail($email,$subject,$message)
{
$headers=$this->getHeaders();
if($this->utf8)
{
$headers[]="MIME-Version: 1.0";
$headers[]="Content-Type: text/plain; charset=UTF-8";
$subject='=?UTF-8?B?'.base64_encode($subject).'?=';
}
if(($from=$this->getSentFrom())!==null)
{
$matches=array();
preg_match_all('/([^<]*)<([^>]*)>/iu',$from,$matches);
if(isset($matches[1][0],$matches[2][0]))
{
$name=$this->utf8 ? '=?UTF-8?B?'.base64_encode(trim($matches[1][0])).'?=' : trim($matches[1][0]);
$from=trim($matches[2][0]);
$headers[]="From: {$name} <{$from}>";
}
else
$headers[]="From: {$from}";
$headers[]="Reply-To: {$from}";
}
mail($email,$subject,$message,implode("\r\n",$headers));
}
Sends an email.
public void setEmails(mixed $value) |
$value | mixed | list of destination email addresses. If the value is a string, it is assumed to be comma-separated email addresses. |
public void setHeaders(mixed $value) |
$value | mixed | list of additional headers to use when sending an email. If the value is a string, it is assumed to be line break separated headers. |
public void setSentFrom(string $value) |
$value | string | send from address of the email |
public void setSubject(string $value) |
$value | string | email subject. |