Skip to content

Instantly share code, notes, and snippets.

@komagata
Created October 10, 2012 07:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save komagata/3863627 to your computer and use it in GitHub Desktop.
Save komagata/3863627 to your computer and use it in GitHub Desktop.
Sending log by mail for CakePHP1.3
<?php
/**
* メールを送るロガー
*
* 使い方:
* // app/config/bootstrup.php:
* CakeLog::config('mailLog', array(
* 'engine' => 'MailLog',
* 'to' => 'to@example.com',
* 'from' => 'from@example.com'
* ));
*/
class MailLog
{
private $to;
private $from;
/**
* オプションを設定する
*
* @param array $options メールのto、fromの設定
* @return void
*/
public function __construct($options = array())
{
if (isset($options['to'])) {
$this->to = $options['to'];
}
if (isset($options['from'])) {
$this->from = $options['from'];
}
}
/**
* ログをメールで送る(ログを書く)
*
* @param string $type エラーの種類
* @param string $message エラーの内容
* @return void
*/
public function write($type, $message)
{
$subject = "[{$type}] ".mb_substr($message, 0, 32);
mb_send_mail($this->to, $subject, $message, "From: {$this->from}");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment